import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { GOOGLE_ACCESS, googleConnectUrl } from "./googleConnect"; // The frontend builds the Google connect URL by hand, so nothing but this test notices when the // backend route moves or its `access` values change: the click would land on a 404 or a 422 page. const AUTH = readFileSync(new URL("../../../backend/app/routes/auth.py", import.meta.url), "utf-8"); describe("the Google connect URL", () => { it("names the backend route", () => { const prefix = /APIRouter\(prefix="([^"]+)"/.exec(AUTH)?.[1]; const path = /@router\.get\("([^"]+)"\)\nasync def google_connect\(/.exec(AUTH)?.[1]; expect(googleConnectUrl("read").split("?")[0]).toBe(`${prefix}${path}`); }); it("offers exactly the access values the backend accepts", () => { const literal = /access: Literal\[([^\]]+)\]/.exec(AUTH)?.[1] ?? ""; const accepted = [...literal.matchAll(/"([^"]+)"/g)].map((m) => m[1]); expect(accepted).toEqual([...GOOGLE_ACCESS]); }); });