Skip to content

Commit

Permalink
fix: update redirect logic on courseAbout page (#891)
Browse files Browse the repository at this point in the history
* fix: update redirect logic on courseAbout page

* chore: the bestests of tests
  • Loading branch information
brobro10000 authored Dec 8, 2023
1 parent fa163a4 commit 6a53e66
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/course/routes/tests/CourseAbout.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { ResponsiveContext, breakpoints } from '@edx/paragon';
import { breakpoints, ResponsiveContext } from '@edx/paragon';

import { AppContext } from '@edx/frontend-platform/react';
import CourseAbout from '../CourseAbout';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ENTERPRISE_OFFER_TYPE } from '../constants';
import { ASSIGNMENT_TYPES, ENTERPRISE_OFFER_TYPE } from '../constants';
import {
getOfferType,
isDisableCourseSearch,
isOfferLowOnBalance,
isOfferOutOfBalance,
offerHasBookingsLimit,
offerHasEnrollmentsLimit,
transformEnterpriseOffer,
} from '../utils';
import { LICENSE_STATUS } from '../../../data/constants';

describe('offerHasBookingsLimit', () => {
test.each([
Expand Down Expand Up @@ -332,3 +334,56 @@ describe('transformEnterpriseOffer', () => {
expect(transformEnterpriseOffer(offer)).toEqual(expectedResult);
});
});

describe('isDisableCourseSearch', () => {
it('returns false if hasActiveSubPlan', () => {
const inputs = {
redeemableLearnerCreditPolicies: [{
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
}],
enterpriseOffers: [{
isCurrent: true,
}],
subscriptionPlan: {
isActive: true,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
};
const isDisableSearch = isDisableCourseSearch(
inputs.redeemableLearnerCreditPolicies,
inputs.enterpriseOffers,
inputs.subscriptionPlan,
inputs.subscriptionLicenses,
);
expect(isDisableSearch).toEqual(false);
});
it('returns true if does not have active sub plans and assignments', () => {
const inputs = {
redeemableLearnerCreditPolicies: [{
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
}],
enterpriseOffers: [{
isCurrent: true,
}],
subscriptionPlan: {
isActive: false,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
};
const isDisableSearch = isDisableCourseSearch(
inputs.redeemableLearnerCreditPolicies,
inputs.enterpriseOffers,
inputs.subscriptionPlan,
inputs.subscriptionLicenses,
);
expect(isDisableSearch).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export const isDisableCourseSearch = (
subscriptionPlan,
subscriptionLicense,
) => {
const hasActiveSubPlan = subscriptionPlan?.isActive && subscriptionLicense?.status === LICENSE_STATUS.ACTIVATED;
const activeOffers = enterpriseOffers?.filter(item => item?.isCurrent);

const assignments = redeemableLearnerCreditPolicies?.flatMap(item => item?.learnerContentAssignments || []);
const allocatedAndAcceptedAssignments = assignments?.filter(item => item?.state === ASSIGNMENT_TYPES.ALLOCATED
|| item?.state === ASSIGNMENT_TYPES.ACCEPTED);
Expand All @@ -130,8 +133,9 @@ export const isDisableCourseSearch = (
return false;
}

const activeOffers = enterpriseOffers?.filter(item => item?.isCurrent);
const hasActiveSubPlan = subscriptionPlan?.isActive && subscriptionLicense?.status === LICENSE_STATUS.ACTIVATED;
if (hasActiveSubPlan) {
return false;
}

return (activeOffers?.length === 1 && !hasActiveSubPlan) || (activeOffers?.length === 0 && hasActiveSubPlan);
return activeOffers?.length > 0 || allocatedAndAcceptedAssignments?.length > 0;
};

0 comments on commit 6a53e66

Please sign in to comment.