Skip to content

Commit

Permalink
fix: update redirect logic to take into account available coupon codes (
Browse files Browse the repository at this point in the history
#906)

* fix: update redirect logic to take into account available coupon codes

* chore: refactor

* chore: test

* chore: Pr fixes
  • Loading branch information
brobro10000 authored Dec 14, 2023
1 parent e1d8c5d commit 12b1c2c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/components/course/data/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export const getCouponCodesDisabledEnrollmentReasonType = ({
const applicableCouponsToCatalog = couponsOverview?.data?.results.filter(
coupon => catalogsWithCourse.includes(coupon.enterpriseCatalogUuid),
) || [];

const hasCouponsApplicableToCourse = applicableCouponsToCatalog.length > 0;
if (!hasCouponsApplicableToCourse) {
return undefined;
Expand Down
2 changes: 2 additions & 0 deletions src/components/course/routes/CourseAbout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const CourseAbout = () => {
enterpriseOffers,
subscriptionPlan,
subscriptionLicense,
couponCodes,
} = useContext(UserSubsidyContext);

const isCourseAssigned = useIsCourseAssigned(redeemableLearnerCreditPolicies?.learnerContentAssignments, course?.key);
Expand All @@ -37,6 +38,7 @@ const CourseAbout = () => {
enterpriseOffers,
subscriptionPlan,
subscriptionLicense,
couponCodes.couponCodes,
);

const featuredHideCourseSearch = features.FEATURE_ENABLE_TOP_DOWN_ASSIGNMENT && hideCourseSearch;
Expand Down
3 changes: 3 additions & 0 deletions src/components/course/routes/tests/CourseAbout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const initialUserSubsidyState = {
enterpriseOffers: [],
subscriptionPlan: {},
subscriptionLicense: {},
couponCodes: {
couponCodes: [],
},
};

const CourseAboutWrapper = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [],
},
{
isCourseSearchDisabled: false,
Expand Down Expand Up @@ -400,6 +401,7 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [],
},
{
isCourseSearchDisabled: false,
Expand Down Expand Up @@ -430,6 +432,38 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [],
},
{
isCourseSearchDisabled: false,
redeemableLearnerCreditPolicies: {
redeemablePolicies: [
{
policyType: POLICY_TYPES.ASSIGNED_CREDIT,
learnerContentAssignments: [
{ state: ASSIGNMENT_TYPES.ALLOCATED },
],
},
],
learnerContentAssignments: {
assignments: [],
hasAssignments: false,
activeAssignments: [],
hasActiveAssignments: false,
},
},
enterpriseOffers: [{
isCurrent: true,
}],
subscriptionPlan: {
isActive: false,
},
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [
{ available: true },
],
},
{
isCourseSearchDisabled: true,
Expand Down Expand Up @@ -458,6 +492,7 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [],
},
{
isCourseSearchDisabled: true,
Expand Down Expand Up @@ -492,19 +527,22 @@ describe('isDisableCourseSearch', () => {
subscriptionLicenses: {
status: LICENSE_STATUS.ACTIVATED,
},
couponCodes: [],
},
])('isCourseSearchDisabled - (%p), (%s)', ({
isCourseSearchDisabled,
redeemableLearnerCreditPolicies,
enterpriseOffers,
subscriptionPlan,
subscriptionLicenses,
couponCodes,
}) => {
const isDisableSearch = isDisableCourseSearch(
redeemableLearnerCreditPolicies,
enterpriseOffers,
subscriptionPlan,
subscriptionLicenses,
couponCodes,
);
expect(isDisableSearch).toEqual(isCourseSearchDisabled);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const transformEnterpriseOffer = (offer) => {
* @param {Array} enterpriseOffers - Array of enterprise offers.
* @param {Object} subscriptionPlan - Subscription plan object.
* @param {Object} subscriptionLicense - Subscription license object.
* @param {Array} couponCodes - Array of couponCodes from the UserSubsidyContext, couponCodes.couponCodes
*
* @returns {boolean} Returns true if course search should be disabled, otherwise false.
*/
Expand All @@ -123,12 +124,12 @@ export const isDisableCourseSearch = (
enterpriseOffers,
subscriptionPlan,
subscriptionLicense,
couponCodes,
) => {
const {
redeemablePolicies,
learnerContentAssignments,
} = redeemableLearnerCreditPolicies || {};

const nonAssignablePolicyTypes = redeemablePolicies.filter(
item => item.policyType !== POLICY_TYPES.ASSIGNED_CREDIT,
);
Expand All @@ -137,16 +138,18 @@ export const isDisableCourseSearch = (
}

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

const hasCouponCodes = couponCodes.filter(code => !!code?.available).length > 0;
const allocatedOrAcceptedAssignments = learnerContentAssignments.assignments
.filter(item => [ASSIGNMENT_TYPES.ALLOCATED, ASSIGNMENT_TYPES.ACCEPTED].includes(item.state));
const activeOffers = enterpriseOffers?.filter(item => item?.isCurrent);

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

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

Expand Down
10 changes: 4 additions & 6 deletions src/components/my-career/CategoryCard.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import React, {
useMemo, useState, useEffect, useContext,
useContext, useEffect, useMemo, useState,
} from 'react';

import PropTypes from 'prop-types';
import {
Card,
Button,
useToggle,
} from '@edx/paragon';
import { Button, Card, useToggle } from '@edx/paragon';
import { getConfig } from '@edx/frontend-platform/config';
import algoliasearch from 'algoliasearch/lite';
import { AppContext } from '@edx/frontend-platform/react';
Expand All @@ -31,12 +27,14 @@ const CategoryCard = ({ topCategory }) => {
enterpriseOffers,
subscriptionPlan,
subscriptionLicense,
couponCodes,
} = useContext(UserSubsidyContext);
const hideCourseSearch = isDisableCourseSearch(
redeemableLearnerCreditPolicies,
enterpriseOffers,
subscriptionPlan,
subscriptionLicense,
couponCodes.couponCodes,
);

const featuredHideCourseSearch = features.FEATURE_ENABLE_TOP_DOWN_ASSIGNMENT && hideCourseSearch;
Expand Down

0 comments on commit 12b1c2c

Please sign in to comment.