Cotton code
24 lines · 1.3 KB · TypeScriptRaw
/** * ALARM KICK (coordinator, 28 Nov 2026): POST /v1/admin/alarm/kick sets the object's alarm 5 s out whatever stands (an * alarm in the past the platform stopped retrying, or none), answering getAlarm() before and after; the admin token only. */import { env, runInDurableObject } from "cloudflare:test";import { describe, expect, it } from "vitest";import { ADMIN, http, personalObject } from "./personal.ts";describe("the alarm kick", { timeout: 180_000 }, () => {  it("sets an alarm stuck in the past 5 s out, and answers before and after; the admin token only", async () => {    const slug = "alarm-kick";    const { owner } = await personalObject(slug);    const stub = env.BUSINESS.get(env.BUSINESS.idFromName(slug));    const past = Date.now() - 6 * 3_600_000;    await runInDurableObject(stub, async (_i, s) => s.storage.setAlarm(past));    expect((await http(slug, "POST", "/v1/admin/alarm/kick", {}, { authorization: `Bearer ${owner}` })).status).toBe(403);    const kick = await http<{ before: string | null; after: string; now: string }>(slug, "POST", "/v1/admin/alarm/kick", {}, ADMIN);    expect(kick.status, JSON.stringify(kick.body)).toBe(200);    const after = Date.parse(kick.body.after) - Date.parse(kick.body.now);    expect(after).toBeGreaterThan(3_000);    expect(after).toBeLessThanOrEqual(5_000);  });});