Skip to content

Commit

Permalink
fix: fix auto-applied license flow (#1119)
Browse files Browse the repository at this point in the history
Fix the `activateOrAutoApplySubscriptionLicense()` function
so that it doesn't early-return when there is no subscription
license present (which is actually the *expected* case during
the auto-apply flow), but *does* early return if there
is no current subscription plan associated with the present
customer agreement record.
ENT-9221
  • Loading branch information
iloveagent57 authored Jul 17, 2024
1 parent 72c17d9 commit e2a3310
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/app/data/services/subsidies/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ export async function activateOrAutoApplySubscriptionLicense({
const {
customerAgreement,
licensesByStatus,
subscriptionLicense,
} = subscriptionsData;
if (!customerAgreement || !subscriptionLicense?.subscriptionPlan?.isCurrent) {
// If there is no available customer agreement for the current customer,
// or if there is no *current* plan available within such a customer agreement,
// exit early and redirect to the dashboard.
if (!customerAgreement || customerAgreement.netDaysUntilExpiration <= 0) {
return checkLicenseActivationRouteAndRedirectToDashboard();
}

Expand Down
18 changes: 16 additions & 2 deletions src/components/app/data/services/subsidies/subscriptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const mockLicenseActivationKey = 'test-license-activation-key';
const mockSubscriptionPlanUUID = 'test-subscription-plan-uuid';
const mockCustomerAgreement = {
uuid: 'test-customer-agreement-uuid',
netDaysUntilExpiration: 35,
};
const APP_CONFIG = {
LICENSE_MANAGER_URL: 'http://localhost:18170',
Expand Down Expand Up @@ -197,7 +198,13 @@ describe('activateOrAutoApplySubscriptionLicense', () => {

it('returns null with already activated license', async () => {
const mockLicensesByStatus = {
[LICENSE_STATUS.ACTIVATED]: [{ uuid: 'test-license-uuid' }],
[LICENSE_STATUS.ACTIVATED]: [
{
uuid: 'test-license-uuid',
status: LICENSE_STATUS.ACTIVATED,
subscriptionPlan: { isCurrent: true },
},
],
[LICENSE_STATUS.ASSIGNED]: [],
[LICENSE_STATUS.REVOKED]: [],
};
Expand All @@ -222,7 +229,13 @@ describe('activateOrAutoApplySubscriptionLicense', () => {
const mockLicensesByStatus = {
[LICENSE_STATUS.ACTIVATED]: [],
[LICENSE_STATUS.ASSIGNED]: [],
[LICENSE_STATUS.REVOKED]: [{ uuid: 'test-license-uuid' }],
[LICENSE_STATUS.REVOKED]: [
{
uuid: 'test-license-uuid',
status: LICENSE_STATUS.REVOKED,
subscriptionPlan: { isCurrent: true },
},
],
};
const mockSubscriptionsData = {
customerAgreement: mockCustomerAgreement,
Expand Down Expand Up @@ -253,6 +266,7 @@ describe('activateOrAutoApplySubscriptionLicense', () => {
uuid: mockLicenseUUID,
status: LICENSE_STATUS.ASSIGNED,
activationKey: mockLicenseActivationKey,
subscriptionPlan: { isCurrent: true },
};
const mockLicensesByStatus = {
[LICENSE_STATUS.ACTIVATED]: [],
Expand Down

0 comments on commit e2a3310

Please sign in to comment.