Skip to content

Commit

Permalink
fix: handle multi-use codes in 2 more spots (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored May 13, 2024
1 parent 1efd730 commit 5005d75
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default function useHasAvailableSubsidiesOrRequests() {

const hasActiveLicenseOrLicenseRequest = (
subscriptions.subscriptionLicense?.status === LICENSE_STATUS.ACTIVATED
|| requests.subscriptionLicenses.length > 0
|| requests.subscriptionLicenses.length > 0
);
const hasAssignedCodesOrCodeRequests = (
couponCodes.couponCodeAssignments.length > 0
|| requests.couponCodes.length > 0
couponCodes.couponCodeRedemptionCount > 0
|| requests.couponCodes.length > 0
);
const hasAvailableLearnerCreditPolicies = redeemablePolicies.length > 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
useCouponCodes.mockReturnValue({
data: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
});
useEnterpriseOffers.mockReturnValue({ data: { enterpriseOffers: [] } });
Expand Down Expand Up @@ -102,6 +103,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
mockCouponCodes: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: true,
Expand Down Expand Up @@ -134,6 +136,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
mockCouponCodes: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: true,
Expand Down Expand Up @@ -163,7 +166,11 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
},
mockCouponCodes: {
couponCodeAssignments: [uuidv4()],
couponCodeAssignments: [{
code: '23EHKQE2PDOTTHGT',
redemptions_remaining: 3,
}],
couponCodeRedemptionCount: 3,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: false,
Expand Down Expand Up @@ -194,6 +201,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
mockCouponCodes: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: false,
Expand Down Expand Up @@ -235,6 +243,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
mockCouponCodes: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: false,
Expand Down Expand Up @@ -298,6 +307,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => {
},
mockCouponCodes: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
expectedResult: {
hasActiveLicenseOrLicenseRequest: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/sidebar/SubsidiesSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const SubsidiesSummary = ({
)}
{hasAssignedCodesOrCodeRequests && (
<CouponCodesSummaryCard
couponCodesCount={couponCodes.couponCodeAssignments.length}
couponCodesCount={couponCodes.couponCodeRedemptionCount}
couponCodeRequestsCount={requests.couponCodes.length}
totalCoursesEligibleForCertificate={totalCoursesEligibleForCertificate}
programProgressPage={programProgressPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('<DashboardSidebar />', () => {
useCouponCodes.mockReturnValue({
data: {
couponCodeAssignments: [],
couponCodeRedemptionCount: 0,
},
});
useEnterpriseOffers.mockReturnValue({
Expand Down Expand Up @@ -136,7 +137,8 @@ describe('<DashboardSidebar />', () => {
test('Coupon codes summary card is displayed when coupon codes are available', () => {
useCouponCodes.mockReturnValue({
data: {
couponCodeAssignments: [{ id: 3 }],
couponCodeAssignments: [{ code: '322DXUX3G2RJXLHF', redemptionsRemaining: 3 }],
couponCodeRedemptionCount: 3,
},
});
useHasAvailableSubsidiesOrRequests.mockReturnValue(useMockHasAvailableSubsidyOrRequests({
Expand Down Expand Up @@ -242,7 +244,8 @@ describe('<DashboardSidebar />', () => {
test('Enterprise offers summary card is displayed when enterprise has active offers and has coupon codes', () => {
useCouponCodes.mockReturnValue({
data: {
couponCodeAssignments: [{ id: 3 }],
couponCodeAssignments: [{ code: '322DXUX3G2RJXLHF', redemptionsRemaining: 3 }],
couponCodeRedemptionCount: 3,
},
});
useEnterpriseOffers.mockReturnValue({
Expand Down

0 comments on commit 5005d75

Please sign in to comment.