feat(codes): mark a code dead once the owner confirms it in game
Game8 still lists Y1INABQB6DEX, 2BJ64QRZ7RT8 and PLDXIB886Y1S as active Genshin codes after the game refused them. CODE_CHECKS records the owner's in-game check; build-codes stamps the matching code confirmedDead, and the Codes tab shows it expired: "Confirmed expired in game, 2026-10-20." Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7569aa6395
commit
b8e8d44816
12 files changed
+178
-12
No files matched your search
@@ -100,3 +100,32 @@ test("with one server, a code's checkbox does not name it", () => {
|
||||
expect(html).toContain("Redeemed");
|
||||
expect(html).not.toContain("Redeemed · ");
|
||||
});
|
||||
|
||||
test("a code confirmed dead in game says so, in the redeemed-or-expired section", () => {
|
||||
const at = "2026-10-20T12:00:00.000Z";
|
||||
const html = render(
|
||||
<CodesPage
|
||||
game="genshin"
|
||||
state={migrateLegacy({}, ["genshin"], at, () => "account:t")}
|
||||
onAction={async () => ({ ok: true })}
|
||||
feed={{
|
||||
schemaVersion: 1,
|
||||
sources: [],
|
||||
codes: [
|
||||
{
|
||||
id: "dead",
|
||||
game: "genshin",
|
||||
code: "DEAD",
|
||||
reward: null,
|
||||
expiresAt: null,
|
||||
confirmedDead: "2026-10-20",
|
||||
firstObservedAt: at,
|
||||
sourceUrl: "https://example.com",
|
||||
},
|
||||
],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("Redeemed or expired");
|
||||
expect(html).toContain("Confirmed expired in game, 2026-10-20.");
|
||||
});
|
||||
+30
-1
@@ -1,6 +1,7 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { buildCodesFeed } from "../src/ingest/codes/build.ts";
|
||||
import { applyCodeChecks, buildCodesFeed } from "../src/ingest/codes/build.ts";
|
||||
import { parseGame8Codes } from "../src/ingest/codes/game8.ts";
|
||||
import { CODE_CHECKS } from "../src/shared/codeChecks.ts";
|
||||
const at = "2026-10-16T12:00:00.000Z",
|
||||
ctx = {
|
||||
game: "genshin" as const,
|
||||
@@ -54,3 +55,31 @@ test("special-program codes are included while their stated expiry date is still
|
||||
expect(codes).toHaveLength(13);
|
||||
expect(codes.some((c) => c.code === "Rekviem")).toBe(true);
|
||||
});
|
||||
test("a code the owner confirmed dead is stamped, and a check matching nothing is reported", () => {
|
||||
const live = (code: string) => ({
|
||||
id: JSON.stringify(["genshin", code]),
|
||||
game: "genshin" as const,
|
||||
code,
|
||||
reward: null,
|
||||
expiresAt: null,
|
||||
firstObservedAt: at,
|
||||
sourceUrl: ctx.sourceUrl,
|
||||
});
|
||||
const { codes, unmatched } = applyCodeChecks(
|
||||
[live("DEAD"), live("ALIVE")],
|
||||
[
|
||||
{ game: "genshin", code: "DEAD", checked: "2026-10-20" },
|
||||
{ game: "genshin", code: "GONE", checked: "2026-10-20" },
|
||||
],
|
||||
);
|
||||
expect(codes.map((c) => c.confirmedDead ?? null)).toEqual([
|
||||
"2026-10-20",
|
||||
null,
|
||||
]);
|
||||
expect(unmatched.map((c) => c.code)).toEqual(["GONE"]);
|
||||
});
|
||||
test("every code check names one code once, with a date", () => {
|
||||
const ids = CODE_CHECKS.map((c) => JSON.stringify([c.game, c.code]));
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
for (const c of CODE_CHECKS) expect(c.checked).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||
});
|
||||
@@ -69,3 +69,18 @@ test("the Settings marker counts unseen codes that can still be used", () => {
|
||||
).map((c) => c.id);
|
||||
expect(ids).toEqual(["fresh"]);
|
||||
});
|
||||
|
||||
test("a code the owner confirmed dead is expired whatever its stated expiry", () => {
|
||||
expect(codeExpired(code("a", { confirmedDead: "2026-10-20" }), now)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
codeExpired(
|
||||
code("a", {
|
||||
confirmedDead: "2026-10-20",
|
||||
expiresAt: "2026-12-01T00:00:00.000Z",
|
||||
}),
|
||||
now,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
Reference in new issue
Block a user