Integrate starter pack timing, reactivation, purchase analytics, payment routing and atomic user IDs. Resolve iOS conflicts by preserving both battle pass delivery and starter pack snapshots. Add coexistence regression checks and record remaining compatibility risks. Validation: 118/125 tests passed; 7 existing failures remain, plus a separately reproduced pre-existing V2 task login failure.
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const moduleUrl = new URL("../functions/wucaiMigration.ts", import.meta.url);
|
|
const {
|
|
addWucaiReward,
|
|
buildWucaiPreview,
|
|
isPristineWucaiTarget,
|
|
normalizeWucaiUser,
|
|
} = await import(moduleUrl);
|
|
|
|
test("normalization preserves valid zero values and derived entitlements", () => {
|
|
const normalized = normalizeWucaiUser({
|
|
levelAmount: 0,
|
|
freezeAmount: 0,
|
|
hammerAmount: 0,
|
|
magicAmount: 0,
|
|
pay_user: true,
|
|
monthCardTime: 123,
|
|
passCheck: [{ activate: true }],
|
|
headArr: [7],
|
|
catArr: [8],
|
|
});
|
|
|
|
assert.equal(normalized.levelAmount, 0);
|
|
assert.equal(normalized.freezeAmount, 0);
|
|
assert.equal(normalized.hammerAmount, 0);
|
|
assert.equal(normalized.magicAmount, 0);
|
|
assert.equal(normalized.pay_user, true);
|
|
assert.equal(normalized.monthCardTime, 123);
|
|
assert.deepEqual(normalized.headArr, [7]);
|
|
assert.deepEqual(normalized.catArr, [8]);
|
|
});
|
|
|
|
test("preview is sanitized and includes paid activation booleans", () => {
|
|
const preview = buildWucaiPreview({
|
|
levelAmount: 12,
|
|
coinAmount: 300,
|
|
healthAmount: 4,
|
|
headArr: [1, 2],
|
|
catArr: [1, 2, 3],
|
|
monthCardTime: 200,
|
|
passCheck: JSON.stringify([{ activate: true }]),
|
|
token: "must-not-leak",
|
|
unionid: "must-not-leak",
|
|
}, 100);
|
|
|
|
assert.equal(preview.monthCardActive, true);
|
|
assert.equal(preview.passCheckActive, true);
|
|
assert.equal(preview.headCount, 2);
|
|
assert.equal(preview.catCount, 3);
|
|
assert.equal("token" in preview, false);
|
|
assert.equal("unionid" in preview, false);
|
|
});
|
|
|
|
test("pristine classification requires explicit unpaid state and no activity", () => {
|
|
const defaults = {
|
|
levelAmount: 0,
|
|
coinAmount: 0,
|
|
healthAmount: 5,
|
|
freezeAmount: 3,
|
|
hammerAmount: 3,
|
|
magicAmount: 3,
|
|
pay_user: false,
|
|
headArr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
|
catArr: [1, 2, 3],
|
|
};
|
|
|
|
assert.equal(isPristineWucaiTarget(defaults, false), true);
|
|
const { pay_user, ...withoutPayUser } = defaults;
|
|
assert.equal(isPristineWucaiTarget(withoutPayUser, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, coinAmount: 1 }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, pay_user: true }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, pay_user: 1 }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, pay_user: "true" }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, task: JSON.stringify({ levelPass: { value: 1, state: 0 } }) }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, task: JSON.stringify({ levelPass: { value: 0, state: 0 } }) }, false), true);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, shareLv: JSON.stringify([{ id: "friend", lv: 1 }]) }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, passCheckLv: 1 }, false), false);
|
|
assert.equal(isPristineWucaiTarget({ ...defaults, levelTJ: 1 }, false), false);
|
|
assert.equal(isPristineWucaiTarget(defaults, true), false);
|
|
});
|
|
|
|
test("reward increments the four configured resources", () => {
|
|
assert.deepEqual(addWucaiReward({
|
|
coinAmount: 10,
|
|
freezeAmount: 1,
|
|
hammerAmount: 2,
|
|
magicAmount: 3,
|
|
}), {
|
|
coinAmount: 2010,
|
|
freezeAmount: 4,
|
|
hammerAmount: 5,
|
|
magicAmount: 6,
|
|
});
|
|
});
|
|
|
|
test("migration preserves the starter pack offer round", () => {
|
|
assert.equal(normalizeWucaiUser({ starter_pack: 100, starterPackRound: 4 }).starterPackRound, 4);
|
|
assert.equal(normalizeWucaiUser({}).starterPackRound, 0);
|
|
});
|