import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; // A tab names the account it was built for, and the server refuses a request from a tab showing // another one than the cookie's. Spelled on both sides, so nothing but this test notices a rename: // the server would see no header, and a tab left showing the previous account would act as the new // one without a word. const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf-8"); const AUTH = read("../../../../backend/app/auth.py"); const ROUTES = read("../../../../backend/app/routes/auth.py"); const CORE = read("./core.ts"); const CONNECT = read("../googleConnect.ts"); const ENTRY = read("../entryUrl.ts"); describe("the account a tab was built for", () => { it("is the header the server checks", () => { const backend = /^EXPECTED_ACCOUNT_HEADER = "([^"]+)"$/m.exec(AUTH)?.[1]; const frontend = /^const EXPECTED_ACCOUNT_HEADER = "([^"]+)";$/m.exec(CORE)?.[1]; expect(backend).toBeTruthy(); expect(backend).toBe(frontend?.toLowerCase()); }); it("rides a Google connect as the query parameter the route reads", () => { // A navigation carries no headers; a rename on one side would leave the connect unchecked. expect(CONNECT).toMatch(/params\.set\("expect", account\)/); expect(ROUTES).toMatch(/^ {4}expect: str \| None = None,$/m); }); it("lands a refused navigation where the reloaded tab says why", () => { const landing = /^ACCOUNT_CHANGED_LANDING = "\/\?([^"]+)"$/m.exec(ROUTES)?.[1]; const flag = /^export const ACCOUNT_CHANGED_FLAG = "([^"]+)";$/m.exec(ENTRY)?.[1]; expect(landing).toBeTruthy(); expect(landing).toBe(flag); }); });