Skip to content

Commit

Permalink
chore: revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Dec 9, 2024
1 parent a3a5a28 commit fa9699e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,30 @@ describe('<UnenrollModal />', () => {
updatedEnrollments = mockQueryClient.getQueryData(
queryEnterpriseLearnerDashboardBFF({ enterpriseSlug: 'test-enterprise-slug' }).queryKey,
);
if (bffEnterpriseCourseEnrollmentsData) {
if (bffEnterpriseCourseEnrollmentsData && !enterpriseCourseEnrollmentsData) {
expect(updatedEnrollments).toEqual(learnerDashboardBFFResponse);
expect(logInfo).toHaveBeenCalledTimes(0);
} else {
} else if (!bffEnterpriseCourseEnrollmentsData) {
expect(updatedEnrollments).toEqual(undefined);
expect(logInfo).toHaveBeenCalledTimes(1);
} else {
expect(updatedEnrollments).toEqual(learnerDashboardBFFResponse);
expect(logInfo).toHaveBeenCalledTimes(0);
}
}
if (!isBFFEnabled) {
updatedEnrollments = mockQueryClient.getQueryData(
queryEnterpriseCourseEnrollments(mockEnterpriseCustomer.uuid).queryKey,
);
if (enterpriseCourseEnrollmentsData) {
if (enterpriseCourseEnrollmentsData && !bffEnterpriseCourseEnrollmentsData) {
expect(updatedEnrollments).toEqual([]);
expect(logInfo).toHaveBeenCalledTimes(0);
} else {
} else if (!enterpriseCourseEnrollmentsData) {
expect(updatedEnrollments).toEqual(undefined);
expect(logInfo).toHaveBeenCalledTimes(1);
} else {
expect(updatedEnrollments).toEqual([]);
expect(logInfo).toHaveBeenCalledTimes(0);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,122 +1069,61 @@ describe('handleQueriesForUpdatedCourseEnrollmentStatus', () => {
jest.resetAllMocks();
});
it.each([
// BFF enabled && courseRunIdMatch == true
// BFF enabled
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: true,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: true,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: true,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: true,
doesCourseRunIdMatch: true,
},
// BFF disabled && courseRunIdMatch == true
// BFF disabled
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: false,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: false,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: false,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: false,
doesCourseRunIdMatch: true,
},
// BFF enabled && courseRunIdMatch == false
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: true,
doesCourseRunIdMatch: false,
},
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: true,
doesCourseRunIdMatch: false,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: true,
doesCourseRunIdMatch: false,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: true,
doesCourseRunIdMatch: false,
},
// BFF disabled && courseRunIdMatch == false
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: false,
doesCourseRunIdMatch: true,
},
{
bffEnterpriseCourseEnrollmentsData: mockBFFEnterpriseCourseEnrollments,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: false,
doesCourseRunIdMatch: false,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: mockEnterpriseCourseEnrollment,
isBFFEnabled: false,
doesCourseRunIdMatch: false,
},
{
bffEnterpriseCourseEnrollmentsData: null,
enterpriseCourseEnrollmentsData: null,
isBFFEnabled: false,
doesCourseRunIdMatch: false,
},
])('updates the status, (%s)', (
{
bffEnterpriseCourseEnrollmentsData,
enterpriseCourseEnrollmentsData,
isBFFEnabled,
doesCourseRunIdMatch,
},
) => {
// Define parameters
let mockQueryClient;
isBFFEnabledForEnterpriseCustomer.mockReturnValue(isBFFEnabled);
const mockParams = { enterpriseSlug: 'test-enterprise-slug' };
const mockCorrectCourseRunId = mockEnterpriseCourseEnrollment.courseRunId;
const mockIncorrectCourseRunId = 'course-v1:edX+DemoY+Demo';
const mockCourseRunId = mockEnterpriseCourseEnrollment.courseRunId;
const newEnrollmentStatus = 'saved_for_later';
const originalEnrollmentStatus = 'in_progress';

// Create a mock hook to utilize queryClient
const useMockHook = () => {
Expand All @@ -1205,13 +1144,13 @@ describe('handleQueriesForUpdatedCourseEnrollmentStatus', () => {
queryClient: mockQueryClient,
enterpriseSlug: mockParams.enterpriseSlug,
enterpriseCustomer: mockEnterpriseCustomer,
courseRunId: doesCourseRunIdMatch ? mockCorrectCourseRunId : mockIncorrectCourseRunId,
courseRunId: mockCourseRunId,
newEnrollmentStatus,
});
};

// Validate initial courseRunStatus as `in_progress`
expect(mockEnterpriseCourseEnrollment.courseRunStatus).toEqual(originalEnrollmentStatus);
expect(mockEnterpriseCourseEnrollment.courseRunStatus).toEqual('in_progress');

// Render hook
renderHook(
Expand All @@ -1222,37 +1161,38 @@ describe('handleQueriesForUpdatedCourseEnrollmentStatus', () => {
// Determine if course run status gets modified based on parameters
let updatedEnrollments;
let updatedMockedEnrollment;
const expectedCourseRunStatus = doesCourseRunIdMatch
? newEnrollmentStatus
: originalEnrollmentStatus;
if (isBFFEnabled) {
updatedEnrollments = mockQueryClient.getQueryData(
queryEnterpriseLearnerDashboardBFF({ enterpriseSlug: 'test-enterprise-slug' }).queryKey,
);
updatedMockedEnrollment = updatedEnrollments?.enterpriseCourseEnrollments.find(
enrollment => enrollment.courseRunId === mockCorrectCourseRunId,
enrollment => enrollment.courseRunId === mockCourseRunId,
);
if (bffEnterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(expectedCourseRunStatus);
if (bffEnterpriseCourseEnrollmentsData && !enterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(newEnrollmentStatus);
expect(logInfo).toHaveBeenCalledTimes(0);
} else {
} else if (!bffEnterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment).toEqual(undefined);
expect(logInfo).toHaveBeenCalledTimes(1);
} else {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(newEnrollmentStatus);
expect(logInfo).toHaveBeenCalledTimes(0);
}
}
if (!isBFFEnabled) {
updatedEnrollments = mockQueryClient.getQueryData(
queryEnterpriseCourseEnrollments(mockEnterpriseCustomer.uuid).queryKey,
);
updatedMockedEnrollment = updatedEnrollments?.find(
enrollment => enrollment.courseRunId === mockCorrectCourseRunId,
);
if (enterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(expectedCourseRunStatus);
updatedMockedEnrollment = updatedEnrollments?.find(enrollment => enrollment.courseRunId === mockCourseRunId);
if (enterpriseCourseEnrollmentsData && !bffEnterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(newEnrollmentStatus);
expect(logInfo).toHaveBeenCalledTimes(0);
} else {
} else if (!enterpriseCourseEnrollmentsData) {
expect(updatedMockedEnrollment).toEqual(undefined);
expect(logInfo).toHaveBeenCalledTimes(1);
} else {
expect(updatedMockedEnrollment.courseRunStatus).toEqual(newEnrollmentStatus);
expect(logInfo).toHaveBeenCalledTimes(0);
}
}
});
Expand Down

0 comments on commit fa9699e

Please sign in to comment.