Skip to content

Commit

Permalink
chore: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Jan 21, 2025
1 parent 001571c commit 0f5a47e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,21 @@ export function useContentAssignments() {
expiredAssignments,
} = allEnrollmentsByStatus.assigned;

const upgradeableAuditEnrollmentCourseKeys = [...allEnrollmentsByStatus.inProgress]
const potentiallyUpgradeableAuditEnrollmentCourses = [...allEnrollmentsByStatus.inProgress]
.filter(enrollment => isEnrollmentUpgradeable(enrollment))
.map((enrollment) => enrollment.courseRunId);
.map((enrollment) => ({
courseKey: enrollment.courseKey,
courseRunId: enrollment.courseRunId,
}));

// Filter out any assignments that have a corresponding potentially upgradeable
// audit enrollment. Note: all enrollment cards currently assume content key is
// a course run id despite the current assignment's content key referring to a
// top-level course key.
// top-level course key or a specific course run identifier as assignment.courseRunId.
const filteredAssignmentsForDisplay = assignmentsForDisplay.filter((assignment) => (
!upgradeableAuditEnrollmentCourseKeys.includes(assignment.courseRunId)
!potentiallyUpgradeableAuditEnrollmentCourses.some(({ courseKey, courseRunId }) => (
[courseKey, courseRunId].includes(assignment.courseRunId)
))
));

// Sort and transform the list of assignments for display.
Expand All @@ -463,14 +468,14 @@ export function useContentAssignments() {

// Determine whether there are unacknowledged canceled assignments. If so, display alert.
const filteredCanceledAssignments = canceledAssignments.filter((assignment) => (
!upgradeableAuditEnrollmentCourseKeys.includes(assignment.courseRunId)
!potentiallyUpgradeableAuditEnrollmentCourses.includes(assignment.courseRunId)
));
const hasUnacknowledgedCanceledAssignments = getHasUnacknowledgedAssignments(filteredCanceledAssignments);
setShowCanceledAssignmentsAlert(hasUnacknowledgedCanceledAssignments);

// Determine whether there are unacknowledged expired assignments. If so, display alert.
const filteredExpiredAssignments = expiredAssignments.filter((assignment) => (
!upgradeableAuditEnrollmentCourseKeys.includes(assignment.courseRunId)
!potentiallyUpgradeableAuditEnrollmentCourses.includes(assignment.courseRunId)
));
const hasUnacknowledgedExpiredAssignments = getHasUnacknowledgedAssignments(filteredExpiredAssignments);
setShowExpiredAssignmentsAlert(hasUnacknowledgedExpiredAssignments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ describe('useContentAssignments', () => {
const mockSubsidyExpirationDateStr = dayjs().add(ENROLL_BY_DATE_WARNING_THRESHOLD_DAYS + 1, 'days').toISOString();
const mockAssignmentConfigurationId = 'test-assignment-configuration-id';
const mockAssignment = {
courseKey: 'edX+DemoX',
courseRunId: 'course-v1:Best+course+2T2025',
contentKey: 'edX+DemoX',
parentContentKey: null,
contentTitle: 'edX Demo Course',
subsidyExpirationDate: mockSubsidyExpirationDateStr,
assignmentConfiguration: mockAssignmentConfigurationId,
Expand Down Expand Up @@ -888,58 +888,117 @@ describe('useContentAssignments', () => {
});

it.each([
// isCourseRunAssignment false
// Audit, no enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: undefined,
isCourseRunAssignment: false,
isAssignmentExcluded: true,
},
// Audit, with elapsed enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: dayjs().subtract(1, 'd').toISOString(), // yesterday
isCourseRunAssignment: false,
isAssignmentExcluded: false,
},
// Audit, with not-yet-elapsed enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: dayjs().add(1, 'd').toISOString(), // tomorrow
isCourseRunAssignment: false,
isAssignmentExcluded: true,
},
// Verified, no enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: undefined,
isCourseRunAssignment: false,
isAssignmentExcluded: false,
},
// Verified, with elapsed enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: dayjs().subtract(1, 'd').toISOString(), // yesterday
isCourseRunAssignment: false,
isAssignmentExcluded: false,
},
// Verified, with not-yet-elapsed enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: dayjs().add(1, 'd').toISOString(), // tomorrow
isCourseRunAssignment: false,
isAssignmentExcluded: false,
},
// isCourseRunAssignment true
// Audit, no enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: undefined,
isCourseRunAssignment: true,
isAssignmentExcluded: true,
},
// Audit, with elapsed enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: dayjs().subtract(1, 'd').toISOString(), // yesterday
isCourseRunAssignment: true,
isAssignmentExcluded: false,
},
// Audit, with not-yet-elapsed enrollBy date
{
mode: COURSE_MODES_MAP.AUDIT,
enrollBy: dayjs().add(1, 'd').toISOString(), // tomorrow
isCourseRunAssignment: true,
isAssignmentExcluded: true,
},
// Verified, no enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: undefined,
isCourseRunAssignment: true,
isAssignmentExcluded: false,
},
// Verified, with elapsed enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: dayjs().subtract(1, 'd').toISOString(), // yesterday
isCourseRunAssignment: true,
isAssignmentExcluded: false,
},
// Verified, with not-yet-elapsed enrollBy date
{
mode: COURSE_MODES_MAP.VERIFIED,
enrollBy: dayjs().add(1, 'd').toISOString(), // tomorrow
isCourseRunAssignment: true,
isAssignmentExcluded: false,
},
])('should exclude assignments that have an upgradeable in-progress course enrollment (%s)', ({
mode,
enrollBy,
isAssignmentExcluded,
isCourseRunAssignment,
}) => {
const mockEnrollment = {
...mockTransformedMockCourseEnrollment,
mode,
enrollBy,
isAssignedCourseRun: true,
};

const assignmentKeys = isCourseRunAssignment
? {
contentKey: mockEnrollment.courseRunId,
parentContentKey: mockEnrollment.courseKey,
}
: {
contentKey: mockEnrollment.courseKey,
parentContentKey: null,
};
const mockAssignmentForExistingEnrollment = {
...mockAllocatedAssignment,
contentKey: mockEnrollment.courseRunId,
isAssignedCourseRun: true,
contentKey: assignmentKeys.contentKey,
parentContentKey: assignmentKeys.parentContentKey,
isAssignedCourseRun: isCourseRunAssignment,
};
const mockPoliciesWithInProgressEnrollment = {
...mockPoliciesWithAssignments,
Expand All @@ -956,7 +1015,6 @@ describe('useContentAssignments', () => {
},
});
const { result } = renderHook(() => useContentAssignments(), { wrapper });

if (isAssignmentExcluded) {
expect(result.current.assignments).toHaveLength(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('transformCourseEnrollment', () => {
const originalCourseEnrollment = createRawCourseEnrollment();

const transformedCourseEnrollment = {
courseKey: originalCourseEnrollment.courseKey,
completed: originalCourseEnrollment.completed,
courseRunId: originalCourseEnrollment.courseRunId,
courseRunStatus: originalCourseEnrollment.courseRunStatus,
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('transformCourseEnrollment', () => {
certificateDownloadUrl: certificateUrl,
});
const transformedCourseEnrollment = {
courseKey: originalCourseEnrollment.courseKey,
completed: originalCourseEnrollment.completed,
courseRunId: originalCourseEnrollment.courseRunId,
courseRunStatus: originalCourseEnrollment.courseRunStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const createCourseEnrollmentWithStatus = (
) => {
const randomNumber = Math.random();
return ({
courseKey: 'edX+DemoX',
courseRunId: `$course-v1:edX+DemoX+Demo_Course-${randomNumber}`,
courseRunStatus: status,
linkToCourse: 'https://edx.org/',
Expand All @@ -31,6 +32,7 @@ const createCourseEnrollmentWithStatus = (
};

const createRawCourseEnrollment = (options) => ({
courseKey: 'edX+DemoX',
courseRunId: 'course-v1:Best+course+2T2025',
displayName: 'Best course',
micromastersTitle: 'Greatest Micromasters',
Expand Down

0 comments on commit 0f5a47e

Please sign in to comment.