22 lines
1.1 KiB
TypeScript
22 lines
1.1 KiB
TypeScript
/** 重新安装 Worker 脚本端点测试(v2.10.0):权限/前置校验,不轮换凭据 */
|
|
import { describe, expect, test } from "bun:test";
|
|
import { authedFetch, loginCookie, makeTestEnv } from "./helpers.ts";
|
|
|
|
describe("POST /api/accounts/:id/reinstall-worker", () => {
|
|
test("不存在的账号 -> 404", async () => {
|
|
const t = await makeTestEnv();
|
|
const cookie = await loginCookie(t);
|
|
const resp = await authedFetch(t, cookie, "http://localhost/api/accounts/acct_no_such/reinstall-worker", { method: "POST" });
|
|
expect(resp.status).toBe(404);
|
|
});
|
|
|
|
test("无 Cloudflare 连接凭据 -> 400(不触碰 Cloudflare,不留半截状态)", async () => {
|
|
const t = await makeTestEnv();
|
|
const cookie = await loginCookie(t);
|
|
// 种子账号有 worker_id 但没有 oauth_connections/token -> 应明确报错而非 500
|
|
const resp = await authedFetch(t, cookie, `http://localhost/api/accounts/${t.accountId}/reinstall-worker`, { method: "POST" });
|
|
expect(resp.status).toBe(400);
|
|
expect(((await resp.json()) as { error: string }).error).toContain("no active Cloudflare connection");
|
|
});
|
|
});
|