Skip to content

Commit

Permalink
fix: checks for non-assignable policy types to allow course search (#896
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brobro10000 authored Dec 12, 2023
1 parent 4eec3cc commit ff50628
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/components/course/routes/CourseAbout.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext } from 'react';
import {
Container, MediaQuery, Row, breakpoints,
breakpoints, Container, MediaQuery, Row,
} from '@edx/paragon';

import { AppContext } from '@edx/frontend-platform/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ export const ASSIGNMENT_TYPES = {
CANCELLED: 'cancelled',
ERRORED: 'errored',
};

export const POLICY_TYPES = {
ASSIGNED_CREDIT: 'AssignedLearnerCreditAccessPolicy',
PER_LEARNER_CREDIT: 'PerLearnerSpendCreditAccessPolicy',
PER_ENROLLMENT_CREDIT: 'PerLearnerEnrollmentCreditAccessPolicy',
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASSIGNMENT_TYPES, ENTERPRISE_OFFER_TYPE } from '../constants';
import { ASSIGNMENT_TYPES, ENTERPRISE_OFFER_TYPE, POLICY_TYPES } from '../constants';
import {
getOfferType,
isDisableCourseSearch,
Expand Down Expand Up @@ -336,9 +336,11 @@ describe('transformEnterpriseOffer', () => {
});

describe('isDisableCourseSearch', () => {
it('returns false if hasActiveSubPlan', () => {
const inputs = {
it.each([
{
isCourseSearchDisabled: false,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
Expand All @@ -352,18 +354,54 @@ describe('isDisableCourseSearch', () => {
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 = {
},
{
isCourseSearchDisabled: false,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
},
{
policyType: POLICY_TYPES.PER_LEARNER_CREDIT,
},
{
policyType: POLICY_TYPES.PER_ENROLLMENT_CREDIT,
}],
enterpriseOffers: [{
isCurrent: true,
}],
subscriptionPlan: {
isActive: false,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
},
{
isCourseSearchDisabled: false,
redeemableLearnerCreditPolicies: [
{
policyType: POLICY_TYPES.PER_LEARNER_CREDIT,
},
{
policyType: POLICY_TYPES.PER_ENROLLMENT_CREDIT,
}],
enterpriseOffers: [{
isCurrent: true,
}],
subscriptionPlan: {
isActive: false,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
},
{
isCourseSearchDisabled: true,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
Expand All @@ -377,13 +415,44 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
};
},
{
isCourseSearchDisabled: true,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ACCEPTED,
},
},
{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: {
state: ASSIGNMENT_TYPES.ALLOCATED,
},
}],
enterpriseOffers: [{
isCurrent: false,
}],
subscriptionPlan: {
isActive: false,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
},
])('isCourseSearchDisabled - (%p), (%s)', ({
isCourseSearchDisabled,
redeemableLearnerCreditPolicies,
enterpriseOffers,
subscriptionPlan,
subscriptionLicenses,
}) => {
const isDisableSearch = isDisableCourseSearch(
inputs.redeemableLearnerCreditPolicies,
inputs.enterpriseOffers,
inputs.subscriptionPlan,
inputs.subscriptionLicenses,
redeemableLearnerCreditPolicies,
enterpriseOffers,
subscriptionPlan,
subscriptionLicenses,
);
expect(isDisableSearch).toEqual(true);
expect(isDisableSearch).toEqual(isCourseSearchDisabled);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ENTERPRISE_OFFER_NO_BALANCE_THRESHOLD_DOLLARS,
ENTERPRISE_OFFER_NO_BALANCE_USER_THRESHOLD_DOLLARS,
ENTERPRISE_OFFER_TYPE,
POLICY_TYPES,
} from './constants';

import { LICENSE_STATUS } from '../../data/constants';
Expand Down Expand Up @@ -122,20 +123,27 @@ export const isDisableCourseSearch = (
subscriptionPlan,
subscriptionLicense,
) => {
const nonAssignablePolicyTypes = redeemableLearnerCreditPolicies.filter(
item => item.policyType !== POLICY_TYPES.ASSIGNED_CREDIT,
);
if (nonAssignablePolicyTypes.length > 0) {
return false;
}

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
const allocatedOrAcceptedAssignments = assignments?.filter(item => item?.state === ASSIGNMENT_TYPES.ALLOCATED
|| item?.state === ASSIGNMENT_TYPES.ACCEPTED);

if (allocatedAndAcceptedAssignments?.length === 0) {
if (allocatedOrAcceptedAssignments?.length === 0) {
return false;
}

if (hasActiveSubPlan) {
return false;
}

return activeOffers?.length > 0 || allocatedAndAcceptedAssignments?.length > 0;
return activeOffers?.length > 0 || allocatedOrAcceptedAssignments?.length > 0;
};
4 changes: 4 additions & 0 deletions src/components/my-career/tests/CategoryCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SubsidyRequestsContext } from '../../enterprise-subsidy-requests';
import { SUBSIDY_TYPE } from '../../enterprise-subsidy-requests/constants';
import { renderWithRouter } from '../../../utils/tests';
import CategoryCard from '../CategoryCard';
import { POLICY_TYPES } from '../../enterprise-user-subsidy/enterprise-offers/data/constants';

jest.mock('@edx/frontend-platform/i18n', () => ({
...jest.requireActual('@edx/frontend-platform/i18n'),
Expand Down Expand Up @@ -90,6 +91,9 @@ const expiringSubscriptionUserSubsidyState = {
},
couponCodes: [],
showExpirationNotifications: false,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.PER_LEARNER_CREDIT,
}],
};

const CategoryCardWithContext = () => (
Expand Down
4 changes: 4 additions & 0 deletions src/components/my-career/tests/MyCareerTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as hooks from '../data/hooks';

import { renderWithRouter } from '../../../utils/tests';
import MyCareerTab from '../MyCareerTab';
import { POLICY_TYPES } from '../../enterprise-user-subsidy/enterprise-offers/data/constants';

jest.mock('@edx/frontend-platform/i18n', () => ({
...jest.requireActual('@edx/frontend-platform/i18n'),
Expand Down Expand Up @@ -206,6 +207,9 @@ const expiringSubscriptionUserSubsidyState = {
},
showExpirationNotifications: false,
couponCodes: defaultCouponCodesState,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.PER_LEARNER_CREDIT,
}],
};

const MyCareerTabWithContext = ({
Expand Down
4 changes: 4 additions & 0 deletions src/components/my-career/tests/VisualizeCareer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { renderWithRouter } from '../../../utils/tests';
import VisualizeCareer from '../VisualizeCareer';
import { SUBSIDY_TYPE, SubsidyRequestsContext } from '../../enterprise-subsidy-requests';
import { UserSubsidyContext } from '../../enterprise-user-subsidy';
import { POLICY_TYPES } from '../../enterprise-user-subsidy/enterprise-offers/data/constants';

jest.mock('@edx/frontend-platform/i18n', () => ({
...jest.requireActual('@edx/frontend-platform/i18n'),
Expand Down Expand Up @@ -176,6 +177,9 @@ const expiringSubscriptionUserSubsidyState = {
},
showExpirationNotifications: false,
couponCodes: defaultCouponCodesState,
redeemableLearnerCreditPolicies: [{
policyType: POLICY_TYPES.PER_LEARNER_CREDIT,
}],
};

const defaultSearchContext = {
Expand Down

0 comments on commit ff50628

Please sign in to comment.