test(api): finalize route coverage and document REST contracts
This commit is contained in:
@@ -17,12 +17,13 @@ let app: ReturnType<typeof createApi>;
|
||||
let timestamp: number;
|
||||
let calls: { url: string; init: RequestInit }[];
|
||||
let profile: DiscordProfile;
|
||||
let failure: "token" | "profile" | "malformed" | "throw" | undefined;
|
||||
let failure: "token" | "invalid_token" | "profile" | "malformed" | "throw" | undefined;
|
||||
const request: FetchDiscord = async (url, init) => {
|
||||
calls.push({ url, init });
|
||||
if (failure === "throw") throw new Error("provider secret response");
|
||||
if (url.endsWith("/token")) {
|
||||
if (failure === "token") return new Response("provider secret response", { status: 400 });
|
||||
if (failure === "invalid_token") return Response.json({ access_token: "secret-access", token_type: "Bearer", scope: "email" });
|
||||
return Response.json({ access_token: "secret-access", refresh_token: "secret-refresh", token_type: "Bearer", scope: "identify" });
|
||||
}
|
||||
if (failure === "profile") return new Response("provider secret response", { status: 503 });
|
||||
@@ -149,7 +150,7 @@ describe("Discord sign-in and sessions", () => {
|
||||
expect(calls).toHaveLength(0); expect(db.select().from(schema.sessions).all()).toHaveLength(0);
|
||||
});
|
||||
|
||||
test.each(["token", "profile", "malformed", "throw"] as const)("provider failure (%s) leaves no account or session", async value => {
|
||||
test.each(["token", "invalid_token", "profile", "malformed", "throw"] as const)("provider failure (%s) leaves no account or session", async value => {
|
||||
failure = value;
|
||||
const result = await login();
|
||||
expect(result.response.headers.get("Location")).toBe("/?auth_error=discord_unavailable");
|
||||
|
||||
Reference in New Issue
Block a user