Skip to content

Commit

Permalink
chore: Gate expiration subs modal by license state as well as feature…
Browse files Browse the repository at this point in the history
… toggle. (#1216) (#1217)
  • Loading branch information
macdiesel authored Oct 30, 2024
1 parent 72ff986 commit 0c14daf
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/components/app/data/services/subsidies/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export async function fetchSubscriptions(enterpriseUUID) {
if (customerAgreement) {
subscriptionsData.customerAgreement = customerAgreement;
}
subscriptionsData.showExpirationNotifications = !(customerAgreement?.disableExpirationNotifications);
subscriptionsData.showExpirationNotifications = (
!customerAgreement?.disableExpirationNotifications && !customerAgreement?.hasCustomLicenseExpirationMessaging
);

// Sort licenses within each license status by whether the associated subscription plans
// are current; current plans should be prioritized over non-current plans.
Expand Down
56 changes: 54 additions & 2 deletions src/components/app/data/services/subsidies/subscriptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ describe('fetchSubscriptions', () => {
daysUntilExpiration: 30,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().add(30, 'days').toISOString(),
disableExpirationNotifications: false,
hasCustomLicenseExpirationMessaging: false,
expectedShowExpirationNotifications: true,
},
{
licenseStatus: LICENSE_STATUS.ACTIVATED,
Expand All @@ -74,6 +77,9 @@ describe('fetchSubscriptions', () => {
daysUntilExpiration: 30,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().add(30, 'days').toISOString(),
disableExpirationNotifications: false,
hasCustomLicenseExpirationMessaging: false,
expectedShowExpirationNotifications: true,
},
{
licenseStatus: LICENSE_STATUS.ACTIVATED,
Expand All @@ -82,6 +88,9 @@ describe('fetchSubscriptions', () => {
daysUntilExpiration: 0,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().toISOString(),
disableExpirationNotifications: false,
hasCustomLicenseExpirationMessaging: false,
expectedShowExpirationNotifications: true,
},
{
licenseStatus: LICENSE_STATUS.UNASSIGNED,
Expand All @@ -90,6 +99,45 @@ describe('fetchSubscriptions', () => {
daysUntilExpiration: 30,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().add(30, 'days').toISOString(),
disableExpirationNotifications: false,
hasCustomLicenseExpirationMessaging: false,
expectedShowExpirationNotifications: true,
},
// Custom subs messaging with standard expiration still enabled
{
licenseStatus: LICENSE_STATUS.ACTIVATED,
isSubscriptionPlanActive: true,
isSubscriptionPlanCurrent: false,
daysUntilExpiration: -10,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().subtract(10, 'days').toISOString(),
disableExpirationNotifications: false,
hasCustomLicenseExpirationMessaging: true,
expectedShowExpirationNotifications: false,
},
// Disabled standard expiration, with custom subs expiration enabled
{
licenseStatus: LICENSE_STATUS.ACTIVATED,
isSubscriptionPlanActive: true,
isSubscriptionPlanCurrent: false,
daysUntilExpiration: -10,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().subtract(10, 'days').toISOString(),
disableExpirationNotifications: true,
hasCustomLicenseExpirationMessaging: true,
expectedShowExpirationNotifications: false,
},
// Disabled standard expiration, no custom subs expiration
{
licenseStatus: LICENSE_STATUS.ACTIVATED,
isSubscriptionPlanActive: true,
isSubscriptionPlanCurrent: false,
daysUntilExpiration: -10,
startDate: dayjs().subtract(15, 'days').toISOString(),
expirationDate: dayjs().subtract(10, 'days').toISOString(),
disableExpirationNotifications: true,
hasCustomLicenseExpirationMessaging: false,
expectedShowExpirationNotifications: false,
},
])('returns subscriptions (%s)', async ({
licenseStatus,
Expand All @@ -98,6 +146,9 @@ describe('fetchSubscriptions', () => {
daysUntilExpiration,
startDate,
expirationDate,
disableExpirationNotifications,
hasCustomLicenseExpirationMessaging,
expectedShowExpirationNotifications,
}) => {
const mockSubscriptionLicense = {
uuid: 'test-license-uuid',
Expand All @@ -114,7 +165,8 @@ describe('fetchSubscriptions', () => {
const mockResponse = {
customerAgreement: {
uuid: 'test-customer-agreement-uuid',
disableExpirationNotifications: false,
disableExpirationNotifications,
hasCustomLicenseExpirationMessaging,
},
results: [mockSubscriptionLicense],
};
Expand Down Expand Up @@ -157,7 +209,7 @@ describe('fetchSubscriptions', () => {
subscriptionLicense: isLicenseApplicable ? updatedMockSubscriptionLicense : null,
subscriptionLicenses: [updatedMockSubscriptionLicense],
shouldShowActivationSuccessMessage: false,
showExpirationNotifications: true,
showExpirationNotifications: expectedShowExpirationNotifications,
};
expect(response).toEqual(expectedResult);
});
Expand Down
10 changes: 7 additions & 3 deletions src/components/expired-subscription-modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import DOMPurify from 'dompurify';
import { useSubscriptions } from '../app/data';

const ExpiredSubscriptionModal = () => {
const { data: { customerAgreement, subscriptionLicense } } = useSubscriptions();
const { data: { customerAgreement, subscriptionLicense, subscriptionPlan } } = useSubscriptions();
const [isOpen] = useToggle(true);
const displaySubscriptionExpirationModal = customerAgreement?.hasCustomLicenseExpirationMessaging
&& !subscriptionLicense?.subscriptionPlan.isCurrent;
const displaySubscriptionExpirationModal = (
customerAgreement?.hasCustomLicenseExpirationMessaging
&& subscriptionLicense && !subscriptionPlan.isCurrent
);

if (!displaySubscriptionExpirationModal) {
return null;
}

return (
<AlertModal
title={<h3 className="mb-2">{customerAgreement.modalHeaderText}</h3>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ describe('<ExpiredSubscriptionModal />', () => {
urlForButtonInModal: null,
},
subscriptionLicense: {
subscriptionPlan: {
isCurrent: true,
},
uuid: '123',
},
subscriptionPlan: {
isCurrent: true,
},
},
});
Expand All @@ -46,9 +47,10 @@ describe('<ExpiredSubscriptionModal />', () => {
urlForButtonInModal: '/renew',
},
subscriptionLicense: {
subscriptionPlan: {
isCurrent: true,
},
uuid: '123',
},
subscriptionPlan: {
isCurrent: true,
},
},
});
Expand All @@ -57,6 +59,25 @@ describe('<ExpiredSubscriptionModal />', () => {
expect(container).toBeEmptyDOMElement();
});

test('does not renderwithrouter if learner does not have a license', () => {
useSubscriptions.mockReturnValue({
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: true,
modalHeaderText: 'Expired Subscription',
buttonLabelInModal: 'Continue Learning',
expiredSubscriptionModalMessaging: '<p>Your subscription has expired.</p>',
urlForButtonInModal: '/renew',
},
subscriptionLicense: null,
subscriptionPlan: null,
},
});

const { container } = renderWithRouter(<ExpiredSubscriptionModal />);
expect(container).toBeEmptyDOMElement();
});

test('renderwithrouters modal with messaging when `hasCustomLicenseExpirationMessaging` is true and license is expired', () => {
useSubscriptions.mockReturnValue({
data: {
Expand All @@ -68,9 +89,10 @@ describe('<ExpiredSubscriptionModal />', () => {
urlForButtonInModal: '/renew',
},
subscriptionLicense: {
subscriptionPlan: {
isCurrent: false,
},
uuid: '123',
},
subscriptionPlan: {
isCurrent: false,
},
},
});
Expand All @@ -97,6 +119,12 @@ describe('<ExpiredSubscriptionModal />', () => {
expiredSubscriptionModalMessaging: '<p>Your subscription has expired.</p>',
urlForButtonInModal: '/renew',
},
subscriptionLicense: {
uuid: '123',
},
subscriptionPlan: {
isCurrent: false,
},
},
});

Expand All @@ -114,6 +142,12 @@ describe('<ExpiredSubscriptionModal />', () => {
expiredSubscriptionModalMessaging: '<p>Your subscription has expired.</p>',
urlForButtonInModal: 'https://example.com',
},
subscriptionLicense: {
uuid: '123',
},
subscriptionPlan: {
isCurrent: false,
},
},
});

Expand Down

0 comments on commit 0c14daf

Please sign in to comment.