Skip to content

Commit 0401530

Browse files
committed
test: integ tests for entitlement validations and deactivation on expired
1 parent 6842e4a commit 0401530

File tree

4 files changed

+99
-7
lines changed

4 files changed

+99
-7
lines changed

src/services/login-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ define(function (require, exports, module) {
502502
async function getEffectiveEntitlements(forceRefresh = false) {
503503
// Get raw server entitlements
504504
const serverEntitlements = await getEntitlements(forceRefresh);
505+
_validateAndFilterEntitlements(serverEntitlements); // will prune invalid entitlements
505506

506507
// Get trial days remaining
507508
const trialDaysRemaining = await LoginService.getProTrialDaysRemaining();
@@ -514,7 +515,6 @@ define(function (require, exports, module) {
514515
// User has active trial
515516
if (serverEntitlements && serverEntitlements.plan) {
516517
// Logged-in user with trial
517-
_validateAndFilterEntitlements(serverEntitlements); // will prune invalid entitlements
518518
if (serverEntitlements.plan.paidSubscriber) {
519519
// Already a paid subscriber, return as-is
520520
return serverEntitlements;

test/spec/login-browser-integ-test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ define(function (require, exports, module) {
126126
// Note: We can't easily reset login state, so tests should handle this
127127
});
128128

129-
function setupProUserMock(hasActiveSubscription = true) {
129+
function setupProUserMock(hasActiveSubscription = true, expiredEntitlements = false) {
130130
let userSignedOut = false;
131131

132132
// Set fetch mock on both browser and service exports
@@ -174,15 +174,19 @@ define(function (require, exports, module) {
174174
};
175175

176176
if (hasActiveSubscription) {
177+
const validTill = expiredEntitlements ?
178+
Date.now() - 86400000 : // expired yesterday
179+
Date.now() + 30 * 24 * 60 * 60 * 1000; // valid for 30 days
180+
177181
entitlementsResponse.plan = {
178182
paidSubscriber: true,
179183
name: "Phoenix Pro",
180-
validTill: Date.now() + 30 * 24 * 60 * 60 * 1000
184+
validTill: validTill
181185
};
182186
entitlementsResponse.entitlements = {
183187
liveEdit: {
184188
activated: true,
185-
validTill: Date.now() + 30 * 24 * 60 * 60 * 1000
189+
validTill: validTill
186190
}
187191
};
188192
} else {

test/spec/login-desktop-integ-test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ define(function (require, exports, module) {
136136
// Note: We can't easily reset login state, so tests should handle this
137137
});
138138

139-
function setupProUserMock(hasActiveSubscription = true) {
139+
function setupProUserMock(hasActiveSubscription = true, expiredEntitlements = false) {
140140
let userSignedOut = false;
141141

142142
// Set fetch mock on desktop exports
@@ -196,15 +196,19 @@ define(function (require, exports, module) {
196196
};
197197

198198
if (hasActiveSubscription) {
199+
const validTill = expiredEntitlements ?
200+
Date.now() - 86400000 : // expired yesterday
201+
Date.now() + 30 * 24 * 60 * 60 * 1000; // valid for 30 days
202+
199203
entitlementsResponse.plan = {
200204
paidSubscriber: true,
201205
name: "Phoenix Pro",
202-
validTill: Date.now() + 30 * 24 * 60 * 60 * 1000
206+
validTill: validTill
203207
};
204208
entitlementsResponse.entitlements = {
205209
liveEdit: {
206210
activated: true,
207-
validTill: Date.now() + 30 * 24 * 60 * 60 * 1000
211+
validTill: validTill
208212
}
209213
};
210214
} else {

test/spec/login-shared.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,90 @@ define(function (require, exports, module) {
432432
// Close popup
433433
$profileButton.trigger('click');
434434
});
435+
436+
it("should show free user popup when entitlements are expired (no trial)", async function () {
437+
console.log("llgT: Starting expired entitlements without trial test");
438+
439+
// Setup: Expired pro subscription + no trial
440+
setupProUserMock(true, true);
441+
await cleanupTrialState(); // Ensure no trial is active
442+
443+
// Verify initial state (no pro branding due to expired entitlements)
444+
await verifyProBranding(false, "no pro branding initially due to expired entitlements");
445+
446+
// Perform login
447+
await performFullLoginFlow();
448+
449+
// Verify pro branding remains false after login (expired entitlements filtered to free)
450+
await verifyProBranding(false, "no pro branding after login with expired entitlements");
451+
452+
// Check profile popup shows free plan status
453+
const $profileButton = testWindow.$("#user-profile-button");
454+
$profileButton.trigger('click');
455+
await popupToAppear(PROFILE_POPUP);
456+
await verifyProfilePopupContent(VIEW_PHOENIX_FREE,
457+
"free plan user profile popup for user with expired entitlements");
458+
459+
// Close popup
460+
$profileButton.trigger('click');
461+
462+
// Perform logout
463+
await performFullLogoutFlow();
464+
465+
// Verify pro branding remains false after logout
466+
await verifyProBranding(false, "no pro branding after logout with expired entitlements");
467+
468+
// Check profile popup (signed out state)
469+
$profileButton.trigger('click');
470+
await popupToAppear(SIGNIN_POPUP);
471+
// Not logged in user with no trial - no special branding expected
472+
expect(testWindow.$(`.profile-popup .trial-plan-info`).length).toBe(0);
473+
474+
// Close popup
475+
$profileButton.trigger('click');
476+
});
477+
478+
it("should show trial user popup when entitlements are expired (active trial)", async function () {
479+
console.log("llgT: Starting expired entitlements with active trial test");
480+
481+
// Setup: Expired pro subscription + active trial (10 days)
482+
setupProUserMock(true, true);
483+
await setupTrialState(10);
484+
485+
// Verify initial state shows pro branding due to trial (overrides expired entitlements)
486+
await verifyProBranding(true, "pro branding initially due to active trial");
487+
488+
// Perform login
489+
await performFullLoginFlow();
490+
491+
// Verify pro branding remains after login (trial overrides expired server entitlements)
492+
await verifyProBranding(true, "pro branding after login - trial overrides expired entitlements");
493+
494+
// Check profile popup shows trial status (not expired server entitlements)
495+
const $profileButton = testWindow.$("#user-profile-button");
496+
$profileButton.trigger('click');
497+
await popupToAppear(PROFILE_POPUP);
498+
await verifyProfilePopupContent(VIEW_TRIAL_DAYS_LEFT,
499+
"trial user profile popup - trial overrides expired server entitlements");
500+
501+
// Close popup
502+
$profileButton.trigger('click');
503+
504+
// Perform logout
505+
await performFullLogoutFlow();
506+
507+
// Verify pro branding remains after logout (trial continues)
508+
await verifyProBranding(true, "pro branding after logout - trial still active");
509+
510+
// Check profile popup still shows trial status
511+
$profileButton.trigger('click');
512+
await popupToAppear(SIGNIN_POPUP);
513+
await verifyProfilePopupContent(VIEW_TRIAL_DAYS_LEFT,
514+
"trial user profile popup for logged out user");
515+
516+
// Close popup
517+
$profileButton.trigger('click');
518+
});
435519
}
436520

437521
exports.setup = setup;

0 commit comments

Comments
 (0)