From 5005d75a8489d36bec9de3309d939e8b41a9665f Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Mon, 13 May 2024 16:10:36 -0400 Subject: [PATCH] fix: handle multi-use codes in 2 more spots (#1078) --- .../data/hooks/useHasAvailableSubsidiesOrRequests.js | 6 +++--- .../useHasAvailableSubsidiesOrRequests.test.jsx | 12 +++++++++++- .../dashboard/sidebar/SubsidiesSummary.jsx | 2 +- .../sidebar/tests/DashboardSidebar.test.jsx | 7 +++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.js b/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.js index 2472e3fca8..1f7798b522 100644 --- a/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.js +++ b/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.js @@ -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; diff --git a/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.test.jsx b/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.test.jsx index a1821b0169..eb180fd489 100644 --- a/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.test.jsx +++ b/src/components/app/data/hooks/useHasAvailableSubsidiesOrRequests.test.jsx @@ -64,6 +64,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { useCouponCodes.mockReturnValue({ data: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, }); useEnterpriseOffers.mockReturnValue({ data: { enterpriseOffers: [] } }); @@ -102,6 +103,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, mockCouponCodes: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, expectedResult: { hasActiveLicenseOrLicenseRequest: true, @@ -134,6 +136,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, mockCouponCodes: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, expectedResult: { hasActiveLicenseOrLicenseRequest: true, @@ -163,7 +166,11 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, }, mockCouponCodes: { - couponCodeAssignments: [uuidv4()], + couponCodeAssignments: [{ + code: '23EHKQE2PDOTTHGT', + redemptions_remaining: 3, + }], + couponCodeRedemptionCount: 3, }, expectedResult: { hasActiveLicenseOrLicenseRequest: false, @@ -194,6 +201,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, mockCouponCodes: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, expectedResult: { hasActiveLicenseOrLicenseRequest: false, @@ -235,6 +243,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, mockCouponCodes: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, expectedResult: { hasActiveLicenseOrLicenseRequest: false, @@ -298,6 +307,7 @@ describe('useHasAvailableSubsidiesOrRequests', () => { }, mockCouponCodes: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, expectedResult: { hasActiveLicenseOrLicenseRequest: false, diff --git a/src/components/dashboard/sidebar/SubsidiesSummary.jsx b/src/components/dashboard/sidebar/SubsidiesSummary.jsx index f60e8f4bc1..04c214cef8 100644 --- a/src/components/dashboard/sidebar/SubsidiesSummary.jsx +++ b/src/components/dashboard/sidebar/SubsidiesSummary.jsx @@ -106,7 +106,7 @@ const SubsidiesSummary = ({ )} {hasAssignedCodesOrCodeRequests && ( ', () => { useCouponCodes.mockReturnValue({ data: { couponCodeAssignments: [], + couponCodeRedemptionCount: 0, }, }); useEnterpriseOffers.mockReturnValue({ @@ -136,7 +137,8 @@ describe('', () => { 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({ @@ -242,7 +244,8 @@ describe('', () => { 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({