38 lines
2.3 KiB
JavaScript
38 lines
2.3 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* Unit tests for mobile APK release helpers (rollout, download tokens).
|
|
*/
|
|
const node_test_1 = require("node:test");
|
|
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
const mobileAppReleaseService_1 = require("../services/mobileAppReleaseService");
|
|
(0, node_test_1.describe)('mobileAppReleaseService helpers', () => {
|
|
(0, node_test_1.it)('rolloutBucket is deterministic for the same device id', () => {
|
|
const a = (0, mobileAppReleaseService_1.rolloutBucket)('device-abc');
|
|
const b = (0, mobileAppReleaseService_1.rolloutBucket)('device-abc');
|
|
strict_1.default.equal(a, b);
|
|
strict_1.default.ok(a >= 0 && a < 100);
|
|
});
|
|
(0, node_test_1.it)('isRolloutEligible respects 0 / 100 percent', () => {
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.isRolloutEligible)('any', 0), false);
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.isRolloutEligible)('any', 100), true);
|
|
});
|
|
(0, node_test_1.it)('isRolloutEligible is stable for a given device', () => {
|
|
const device = 'stable-device-42';
|
|
const eligible20 = (0, mobileAppReleaseService_1.isRolloutEligible)(device, 20);
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.isRolloutEligible)(device, 20), eligible20);
|
|
// Raising percent to 100 always includes the device.
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.isRolloutEligible)(device, 100), true);
|
|
});
|
|
(0, node_test_1.it)('download token round-trips and rejects tampering', () => {
|
|
const releaseId = '11111111-1111-1111-1111-111111111111';
|
|
const { token } = (0, mobileAppReleaseService_1.createDownloadToken)(releaseId);
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.verifyDownloadToken)(token, releaseId), true);
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.verifyDownloadToken)(token, '22222222-2222-2222-2222-222222222222'), false);
|
|
strict_1.default.equal((0, mobileAppReleaseService_1.verifyDownloadToken)(token.slice(0, -2) + 'xx', releaseId), false);
|
|
});
|
|
});
|
|
//# sourceMappingURL=mobileAppRelease.test.js.map
|