qoder: test that auth.checkin claims on a PAT account's job token (#262)

#262's check-in tests went through the loader's campaigns fetch; the daily
check-in magpie presses is auth.checkin, whose PAT change nothing covered.
One test claims on qoder and qoder-cn with a PAT account (job token, no
deviceToken refresh); one checks a 403 is "failed", not rotated.

Run on 0a8e5ab + this: bun test packages/qoder 157 pass, 0 fail; bun
scripts/check.mjs passes. With the checkin hook's PAT lines reverted by
hand both new tests fail. Test only, no version bump.
This commit is contained in:
yetone
2026-10-20 16:15:34 +08:00
parent 0a8e5abd00
commit bb688ea81a
+28
View File
@@ -128,3 +128,31 @@ test("a refused device token is rotated and the claim asked again", async () =>
expect(p.out).toEqual({ outcome: "claimed", credit: 100 })
expect(p.auth().deviceToken).toBe("dt-new")
})
test("a PAT account's daily check-in claims on its job token, with no device token to rotate", async () => {
for (const [make, origin] of [[QoderAuthPlugin, "https://openapi.qoder.sh"], [QoderCNAuthPlugin, "https://openapi.qoder.com.cn"]]) {
let auth = { ...account(), patAuth: true, pat: "pt-x", deviceToken: "", deviceRefresh: "" }
const seen = []
globalThis.fetch = async (url, init = {}) => {
const u = new URL(String(url))
seen.push({ origin: u.origin, path: u.pathname, auth: init.headers.Authorization })
if (init.headers.Authorization !== "Bearer jt") return new Response("", { status: 401 })
return u.pathname.endsWith("/claim") ? json({ status: "CLAIMED" }) : json(LIST)
}
const hooks = await make({ client: { auth: { set: async ({ body }) => (auth = body) } } })
const out = await hooks.auth.checkin(async () => auth)
expect(out).toEqual({ outcome: "claimed", credit: 100 })
expect(seen.map((s) => s.origin + s.path)).toEqual([origin + "/sash/api/v1/me/campaigns", origin + "/sash/api/v1/me/campaigns/c1/claim"])
expect(auth.deviceToken).toBe("")
}
})
test("a PAT account's refused check-in is failed, not rotated", async () => {
let auth = { ...account(), patAuth: true, pat: "pt-x", deviceToken: "", deviceRefresh: "" }
const seen = []
globalThis.fetch = async (url) => (seen.push(new URL(String(url)).pathname), json({}, 403))
const hooks = await QoderCNAuthPlugin({ client: { auth: { set: async ({ body }) => (auth = body) } } })
const out = await hooks.auth.checkin(async () => auth)
expect(out).toEqual({ outcome: "failed", message: "campaigns: HTTP 403" })
expect(seen).toEqual(["/sash/api/v1/me/campaigns"])
})