Skip to content

Commit

Permalink
Merge pull request #1844 from codecrafters-io/allow-challenge-depreca…
Browse files Browse the repository at this point in the history
…tion-profile

CC-1285 Allow challenge deprecation in the user profile page
  • Loading branch information
libmartinito committed Jun 12, 2024
2 parents 66c75f1 + 4999a66 commit f28f094
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/components/user-page/course-progress-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ type Signature = {

export default class CourseProgressListComponent extends Component<Signature> {
get courseParticipationGroups() {
const participationsGroupedByCourse: CourseParticipationModel[][] = Object.values(groupBy(this.args.user.courseParticipations, 'course'));
const participationsGroupedByCourse: CourseParticipationModel[][] = Object.values(
groupBy(
this.args.user.courseParticipations.filter((participation) => !participation.course.releaseStatusIsDeprecated),
'course',
),
);

const sortedParticipationsGroupedByCourse = participationsGroupedByCourse.map((group) =>
group.sort((a, b) => new Date(a.lastSubmissionAt).getTime() - new Date(b.lastSubmissionAt).getTime()),
Expand Down
30 changes: 30 additions & 0 deletions tests/acceptance/view-user-profile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,34 @@ module('Acceptance | view-user-profile', function (hooks) {
await userPage.visit({ username: user.username });
assert.ok(userPage.profileCustomizationNotice.isVisible);
});

test('it does not show a challenge if it is deprecated', async function (assert) {
testScenario(this.server);

let currentUser = this.server.schema.users.first();
let go = this.server.schema.languages.findBy({ slug: 'go' });
let docker = this.server.schema.courses.findBy({ slug: 'docker' });
let grep = this.server.schema.courses.findBy({ slug: 'grep' });
docker.update({ releaseStatus: 'deprecated' });

this.server.create('course-participation', {
course: grep,
language: go,
user: currentUser,
completedStageSlugs: grep.stages.models.sortBy('position').slice(0, 5).mapBy('slug'),
lastSubmissionAt: new Date('2020-10-10'),
});

this.server.create('course-participation', {
course: docker,
language: go,
user: currentUser,
completedAt: new Date('2020-01-01'),
});

await userPage.visit({ username: 'rohitpaulk' });

assert.strictEqual(userPage.courseProgressListItems.length, 1, 'only one course progress list item should be shown');
assert.strictEqual(userPage.courseProgressListItems[0].name, 'Build your own grep', 'the course progress list item should be for grep');
});
});

0 comments on commit f28f094

Please sign in to comment.