Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove duplicative course run card on allocation #1248

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import {
useEnterpriseCourseEnrollments,
useEnterpriseCustomer,
useEnterpriseCustomerContainsContent,
useIsBFFEnabled,
useRedeemablePolicies,
useSubscriptions,
useIsBFFEnabled,
} from '../../../../app/data';
import { sortAssignmentsByAssignmentStatus, sortedEnrollmentsByEnrollmentDate } from './utils';
import { ASSIGNMENTS_EXPIRING_WARNING_LOCALSTORAGE_KEY } from '../../../data/constants';
Expand Down 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.courseKey);
.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 @@ -589,11 +589,15 @@ describe('useCourseUpgradeData', () => {
});

describe('useContentAssignments', () => {
beforeEach(() => {
jest.clearAllMocks();
});
const mockRedeemableLearnerCreditPolicies = emptyRedeemableLearnerCreditPolicies;
const mockSubsidyExpirationDateStr = dayjs().add(ENROLL_BY_DATE_WARNING_THRESHOLD_DAYS + 1, 'days').toISOString();
const mockAssignmentConfigurationId = 'test-assignment-configuration-id';
const mockAssignment = {
contentKey: 'edX+DemoX',
parentContentKey: null,
contentTitle: 'edX Demo Course',
subsidyExpirationDate: mockSubsidyExpirationDateStr,
assignmentConfiguration: mockAssignmentConfigurationId,
Expand Down Expand Up @@ -884,55 +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,
};
const assignmentKeys = isCourseRunAssignment
? {
contentKey: mockEnrollment.courseRunId,
parentContentKey: mockEnrollment.courseKey,
}
: {
contentKey: mockEnrollment.courseKey,
parentContentKey: null,
};
const mockAssignmentForExistingEnrollment = {
...mockAllocatedAssignment,
contentKey: mockEnrollment.courseRunKey,
contentKey: assignmentKeys.contentKey,
parentContentKey: assignmentKeys.parentContentKey,
isAssignedCourseRun: isCourseRunAssignment,
};
const mockPoliciesWithInProgressEnrollment = {
...mockPoliciesWithAssignments,
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: 'Best+course',
courseRunId: `$course-v1:edX+DemoX+Demo_Course-${randomNumber}`,
courseRunStatus: status,
linkToCourse: 'https://edx.org/',
Expand All @@ -31,7 +32,8 @@ const createCourseEnrollmentWithStatus = (
};

const createRawCourseEnrollment = (options) => ({
courseRunId: 'course-v1:Best+course',
courseKey: 'Best+course',
courseRunId: 'course-v1:Best+course+2T2025',
displayName: 'Best course',
micromastersTitle: 'Greatest Micromasters',
resumeCourseRunUrl: 'http://www.resumecourserun.com',
Expand Down
Loading