Skip to content

Commit

Permalink
feat: include addtional tests for useEnterpriseCourseEnrollments
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Apr 22, 2024
1 parent 4b939f5 commit 49a3004
Showing 1 changed file with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ const mockContentAssignment = {
earliestPossibleExpiration: {
date: dayjs().add(25, 'days').toISOString(),
},
contentKey: 'edX+DemoX',
contentTitle: 'Test Content Title 1',
contentMetadata: {
startDate: dayjs().add(25, 'days').toISOString(),
endDate: dayjs().add(65, 'days').toISOString(),
mode: 'test-mode',
partners: [{ name: 'edx' }],
},
assignmentConfiguration: 'test-configuration',
learnerAcknowledged: true,
};
const redeemablePolicies = [
{
Expand Down Expand Up @@ -109,29 +119,50 @@ describe('useEnterpriseCourseEnrollments', () => {
fetchCouponCodeRequests.mockResolvedValue([mockCouponCodeRequests]);
fetchRedeemablePolicies.mockResolvedValue(mockRedeemablePolicies);
});
it('should return transformed requests', async () => {
it('should return transformed return values', async () => {
const { result, waitForNextUpdate } = renderHook(() => useEnterpriseCourseEnrollments(), { wrapper: Wrapper });
await waitForNextUpdate();
const expectedTransformedLearnerContentAssignment = {
linkToCourse: `/${mockEnterpriseCustomer.slug}/course/${mockContentAssignment.contentKey}`,
courseRunId: mockContentAssignment.contentKey,
title: mockContentAssignment.contentTitle,
isRevoked: false,
notifications: [],
courseRunStatus: COURSE_STATUSES.assigned,
endDate: mockContentAssignment.contentMetadata?.endDate,
startDate: mockContentAssignment.contentMetadata?.startDate,
mode: mockContentAssignment.contentMetadata?.courseType,
orgName: mockContentAssignment.contentMetadata?.partners[0]?.name,
enrollBy: mockContentAssignment.earliestPossibleExpiration.date,
isCanceledAssignment: false,
isExpiredAssignment: false,
assignmentConfiguration: mockContentAssignment.assignmentConfiguration,
uuid: mockContentAssignment.uuid,
learnerAcknowledged: mockContentAssignment.learnerAcknowledged,
};
const expectedTransformedRequests = (request) => ({
courseRunId: request.courseId,
title: request.courseTitle,
orgName: request.coursePartners?.map(partner => partner.name).join(', '),
courseRunStatus: COURSE_STATUSES.requested,
linkToCourse: `${mockEnterpriseCustomer.slug}/course/${request.courseId}`,
created: request.created,
notifications: [],
});

expect(result.current.data.enterpriseCourseEnrollments).toEqual(mockCourseEnrollments);
expect(result.current.data.contentAssignments).toEqual({
acceptedAssignments: [],
allocatedAssignments: [expectedTransformedLearnerContentAssignment],
assignmentsForDisplay: [expectedTransformedLearnerContentAssignment],
assignments: [expectedTransformedLearnerContentAssignment],
canceledAssignments: [],
erroredAssignments: [],
expiredAssignments: [],
});
expect(result.current.data.requests).toEqual({
couponCodes: [{
courseRunId: mockCouponCodeRequests.courseId,
title: mockCouponCodeRequests.courseTitle,
orgName: mockCouponCodeRequests.coursePartners?.map(partner => partner.name).join(', '),
courseRunStatus: COURSE_STATUSES.requested,
linkToCourse: `${mockEnterpriseCustomer.slug}/course/${mockCouponCodeRequests.courseId}`,
created: mockCouponCodeRequests.created,
notifications: [],
}],
subscriptionLicenses: [{
courseRunId: mockLicenseRequests.courseId,
title: mockLicenseRequests.courseTitle,
orgName: mockLicenseRequests.coursePartners?.map(partner => partner.name).join(', '),
courseRunStatus: COURSE_STATUSES.requested,
linkToCourse: `${mockEnterpriseCustomer.slug}/course/${mockLicenseRequests.courseId}`,
created: mockLicenseRequests.created,
notifications: [],
}],
couponCodes: [expectedTransformedRequests(mockCouponCodeRequests)],
subscriptionLicenses: [expectedTransformedRequests(mockLicenseRequests)],
});
});
});

0 comments on commit 49a3004

Please sign in to comment.