Skip to content

Commit cec0371

Browse files
committed
fix: desktop device license tests without logging in
1 parent 3967064 commit cec0371

File tree

3 files changed

+107
-5
lines changed

3 files changed

+107
-5
lines changed

src/services/login-service.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,18 @@ define(function (require, exports, module) {
657657
return NodeUtils.isLicensedDeviceSystemWide();
658658
}
659659

660+
let _isLicensedDeviceFlagForTest = false;
661+
660662
/**
661663
* Checks if app is configured to check for device licenses at app start at system or user level.
662664
*
663665
* @returns {Promise<boolean>} - Resolves with `true` if the device is licensed, `false` otherwise.
664666
*/
665667
async function isLicensedDevice() {
666-
if(Phoenix.isTestWindow || !Phoenix.isNativeApp) {
668+
if(Phoenix.isTestWindow) {
669+
return _isLicensedDeviceFlagForTest;
670+
}
671+
if(!Phoenix.isNativeApp) {
667672
// browser app doesn't support device licence keys, obviously.
668673
return false;
669674
}
@@ -696,10 +701,13 @@ define(function (require, exports, module) {
696701
if (Phoenix.isTestWindow) {
697702
window._test_login_service_exports = {
698703
LoginService,
699-
setFetchFn: function _setFetchFn(fn) {
704+
setIsLicensedDevice: function (isLicensedDevice) {
705+
_isLicensedDeviceFlagForTest = isLicensedDevice;
706+
},
707+
setFetchFn: function (fn) {
700708
fetchFn = fn;
701709
},
702-
setDateNowFn: function _setDdateNowFn(fn) {
710+
setDateNowFn: function (fn) {
703711
dateNowFn = fn;
704712
},
705713
_validateAndFilterEntitlements: _validateAndFilterEntitlements

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ define(function (require, exports, module) {
187187
} else if (url.includes('/getAppEntitlements')) {
188188
// Entitlements endpoint - return user's plan and entitlements
189189
console.log("llgT: Handling getAppEntitlements call");
190-
if (userSignedOut) {
190+
191+
// Check if this is a device ID request (non-logged-in user with device license)
192+
const isDeviceIDRequest = url.includes('deviceID=');
193+
194+
if (userSignedOut && !isDeviceIDRequest) {
191195
return Promise.resolve({
192196
ok: false,
193197
status: 401,
@@ -207,7 +211,7 @@ define(function (require, exports, module) {
207211
entitlementsResponse.plan = {
208212
paidSubscriber: true,
209213
name: "Phoenix Pro",
210-
fullName: "Phoenix Pro",
214+
fullName: isDeviceIDRequest ? "Phoenix Pro Test Edu" : "Phoenix Pro",
211215
validTill: validTill
212216
};
213217
entitlementsResponse.entitlements = {

test/spec/login-shared.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,96 @@ define(function (require, exports, module) {
710710
await cleanupTrialState();
711711
}
712712
});
713+
714+
if (Phoenix.isNativeApp) {
715+
it("should show device-licensed Pro branding and popup when not logged in", async function () {
716+
console.log("llgT: Starting device license Pro branding test");
717+
718+
try {
719+
// Setup: Enable device license flag
720+
LoginServiceExports.setIsLicensedDevice(true);
721+
722+
// Setup mock that handles device ID requests (returns Pro entitlements)
723+
setupProUserMock(true, false);
724+
725+
// Ensure no trial is active
726+
await cleanupTrialState();
727+
728+
// Ensure user is logged out
729+
if (LoginServiceExports.LoginService.isLoggedIn()) {
730+
await performFullLogoutFlow();
731+
}
732+
733+
// Clear and refresh entitlements to trigger device license check
734+
await LoginServiceExports.LoginService.clearEntitlements();
735+
await LoginServiceExports.LoginService.getEffectiveEntitlements(true);
736+
737+
// Wait for branding to update in the navbar
738+
await awaitsFor(
739+
function () {
740+
const $branding = testWindow.$("#phcode-io-main-nav");
741+
return $branding.hasClass("phoenix-pro");
742+
},
743+
"navbar branding to show Phoenix Pro",
744+
3000
745+
);
746+
747+
// Verify navbar shows Pro branding (uses plan.name)
748+
await verifyProBranding(true, "device license shows Phoenix Pro branding in navbar");
749+
750+
// Verify entitlements API shows Pro access
751+
await verifyPlanEntitlements(
752+
{ paidSubscriber: true, name: "Phoenix Pro" },
753+
"device license provides Pro plan"
754+
);
755+
await verifyIsInProTrialEntitlement(false, "device license is not a trial");
756+
await verifyLiveEditEntitlement({ activated: true }, "live edit activated via device license");
757+
758+
// Verify raw entitlements are present (not null)
759+
const rawEntitlements = await EntitlementsExports.getRawEntitlements();
760+
expect(rawEntitlements).toBeDefined();
761+
expect(rawEntitlements).not.toBeNull();
762+
expect(rawEntitlements.plan.paidSubscriber).toBe(true);
763+
764+
// Verify login popup shows Pro branding with fullName
765+
const $profileButton = testWindow.$("#user-profile-button");
766+
$profileButton.trigger('click');
767+
await popupToAppear(SIGNIN_POPUP);
768+
769+
// Wait for Pro branding to appear in popup (async entitlements load)
770+
await awaitsFor(
771+
function () {
772+
const $popup = testWindow.$('.profile-popup');
773+
const $proInfo = $popup.find('.trial-plan-info');
774+
return $proInfo.length > 0;
775+
},
776+
"Pro branding to appear in login popup",
777+
3000
778+
);
779+
780+
// Check for Pro branding in popup (uses plan.fullName)
781+
const $popup = testWindow.$('.profile-popup');
782+
const $proInfo = $popup.find('.trial-plan-info');
783+
expect($proInfo.length).toBe(1);
784+
785+
const proText = $proInfo.text();
786+
expect(proText).toContain("Phoenix Pro Test Edu");
787+
788+
// Verify feather icon is present
789+
const $featherIcon = $proInfo.find('.fa-feather');
790+
expect($featherIcon.length).toBe(1);
791+
792+
// Close popup
793+
$profileButton.trigger('click');
794+
795+
console.log("llgT: Device license Pro branding test completed successfully");
796+
} finally {
797+
// Cleanup: Reset device license flag
798+
LoginServiceExports.setIsLicensedDevice(false);
799+
await LoginServiceExports.LoginService.clearEntitlements();
800+
}
801+
});
802+
}
713803
}
714804

715805
exports.setup = setup;

0 commit comments

Comments
 (0)