Skip to content

Commit 7d1c6a1

Browse files
committed
test: minor refactor of promotions tests
1 parent f90f9a4 commit 7d1c6a1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/services/promotions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ define(function (require, exports, module) {
474474
}
475475
},
476476
// Test-only functions for manipulating credentials directly (bypassing validation)
477-
_testSetRawCredential: async function(data) {
477+
_testSetPromoJSON: async function(data) {
478478
if (Phoenix.isNativeApp) {
479479
await KernalModeTrust.setCredential(KernalModeTrust.CRED_KEY_PROMO, JSON.stringify(data));
480480
} else {

test/spec/promotions-integ-test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ define(function (require, exports, module) {
482482
const tamperedTrial = { ...storedResult.data, signature: "fake_signature" };
483483

484484
// Manually store the tampered data (bypassing _setTrialData validation)
485-
await LoginService._testSetRawCredential(tamperedTrial);
485+
await LoginService._testSetPromoJSON(tamperedTrial);
486486

487487
// Verify: _getTrialData should detect corruption
488488
const corruptedResult = await LoginService._getTrialData();
@@ -559,7 +559,7 @@ define(function (require, exports, module) {
559559
expect(finalTrial.data.endDate).toBe(futureTrial.endDate); // Should preserve end date
560560
});
561561

562-
it("should handle missing signature fields gracefully", async function () {
562+
it("should handle missing signature fields as tampered", async function () {
563563
// Setup: Create trial data with missing signature field
564564
const trialWithoutSignature = {
565565
proVersion: "3.1.0",
@@ -568,7 +568,7 @@ define(function (require, exports, module) {
568568
};
569569

570570
// Manually store data without signature (bypassing _setTrialData)
571-
await LoginService._testSetRawCredential(trialWithoutSignature);
571+
await LoginService._testSetPromoJSON(trialWithoutSignature);
572572

573573
// Should detect corruption due to missing signature
574574
const result = await LoginService._getTrialData();
@@ -596,7 +596,7 @@ define(function (require, exports, module) {
596596
await testWindow.__PR.waitForModalDialogClosed(".modal");
597597
});
598598

599-
it("should persist salt across app restarts", async function () {
599+
it("should persist salt correctly", async function () {
600600
// Clean existing salt
601601
await LoginService._cleanSaltData();
602602

@@ -622,7 +622,6 @@ define(function (require, exports, module) {
622622
expect(storedResult.data).toBeDefined();
623623
expect(storedResult.error).toBeUndefined();
624624

625-
// Simulate "app restart" - get salt again
626625
const salt3 = await LoginService._getSalt();
627626
expect(salt3).toBe(salt1); // Should be persistent
628627

@@ -646,7 +645,7 @@ define(function (require, exports, module) {
646645
const tamperedTrial = { ...storedResult.data, signature: "fake_signature" };
647646

648647
// Manually store the tampered data (bypassing validation)
649-
await LoginService._testSetRawCredential(tamperedTrial);
648+
await LoginService._testSetPromoJSON(tamperedTrial);
650649

651650
// First activation should create expired marker
652651
await LoginService.activateProTrial();
@@ -703,7 +702,6 @@ define(function (require, exports, module) {
703702
const rolledBackTime = mockNow - (10 * LoginService.TRIAL_CONSTANTS.MS_PER_DAY); // 10 days ago
704703
LoginService.setDateNowFn(() => rolledBackTime);
705704

706-
// Despite rollback, _calculateRemainingTrialDays would show positive days
707705
const remainingDaysAfterRollback = await LoginService.getProTrialDaysRemaining();
708706
// But getProTrialDaysRemaining should still return 0 due to closure detection
709707
expect(remainingDaysAfterRollback).toBe(0);

0 commit comments

Comments
 (0)