From 010c3dd7bac15ce69305e8eff8913d38f4ebcdcb Mon Sep 17 00:00:00 2001 From: huyplb Date: Sun, 1 Nov 2026 15:25:41 -0600 Subject: [PATCH] test(e2e): the last four specs use the shared apiCall instead of their own fetch helper admin-policy, auth-recovery, git-migrations and workspaces each defined the same `api()` fetch wrapper. Each is now a one-line call into helpers/accounts.ts's apiCall, so the 57 call sites stay as they are and there is one place that builds a request. Co-Authored-By: Claude Opus 5.5 --- apps/e2e/src/tests/admin-policy.test.ts | 11 ++--------- apps/e2e/src/tests/auth-recovery.test.ts | 11 ++--------- apps/e2e/src/tests/git-migrations.test.ts | 11 ++--------- apps/e2e/src/tests/workspaces.test.ts | 10 ++-------- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/apps/e2e/src/tests/admin-policy.test.ts b/apps/e2e/src/tests/admin-policy.test.ts index 6c4ac7b1c..706f8a19c 100644 --- a/apps/e2e/src/tests/admin-policy.test.ts +++ b/apps/e2e/src/tests/admin-policy.test.ts @@ -13,8 +13,8 @@ import { buildDriver, quitDriver, clickWhen, waitFor, BASE_URL } from '../helper import { sessionCookie } from '../helpers/app-session.js'; import { saveScreenshot } from '../helpers/screenshot.js'; import { byTestId } from '../helpers/test-ids.js'; +import { apiCall } from '../helpers/accounts.js'; -const API_URL = process.env.E2E_API_URL ?? 'http://127.0.0.1:3210'; const EMAIL = `e2e-policy-${Date.now().toString(36)}@foxschema.test`; let admin = ''; @@ -22,14 +22,7 @@ let driver: Page; let userId = ''; let policy: { adminPolicy: 'one' | 'several'; source: string | null; activeAdmins: string[] }; -async function api(method: string, path: string, body?: unknown) { - const res = await fetch(`${API_URL}/api${path}`, { - method, - headers: { ...(body ? { 'content-type': 'application/json' } : {}), cookie: admin }, - ...(body ? { body: JSON.stringify(body) } : {}), - }); - return { status: res.status, json: (await res.json().catch(() => null)) as any }; -} +const api = (method: string, path: string, body?: unknown) => apiCall(method, path, body, admin); async function openAppUsers(): Promise { // A fresh load each time, so every test reads what the server holds now. diff --git a/apps/e2e/src/tests/auth-recovery.test.ts b/apps/e2e/src/tests/auth-recovery.test.ts index 05e89959e..81ce634cd 100644 --- a/apps/e2e/src/tests/auth-recovery.test.ts +++ b/apps/e2e/src/tests/auth-recovery.test.ts @@ -12,8 +12,8 @@ import { randomBytes } from 'node:crypto'; import type { Page } from 'playwright'; import { buildDriver, quitDriver, BASE_URL } from '../helpers/driver.js'; import { sessionCookie } from '../helpers/app-session.js'; +import { apiCall } from '../helpers/accounts.js'; -const API_URL = process.env.E2E_API_URL ?? 'http://127.0.0.1:3210'; const EMAIL = `e2e-invite-${Date.now()}@foxschema.test`; const FIRST_PASSWORD = `first-${randomBytes(6).toString('hex')}`; const SECOND_PASSWORD = `second-${randomBytes(6).toString('hex')}`; @@ -22,14 +22,7 @@ let admin = ''; let userId = ''; const pages: Page[] = []; -async function api(method: string, path: string, body?: unknown, cookie = admin) { - const res = await fetch(`${API_URL}/api${path}`, { - method, - headers: { ...(body ? { 'content-type': 'application/json' } : {}), ...(cookie ? { cookie } : {}) }, - ...(body ? { body: JSON.stringify(body) } : {}), - }); - return { status: res.status, json: (await res.json().catch(() => null)) as any }; -} +const api = (method: string, path: string, body?: unknown, cookie = admin) => apiCall(method, path, body, cookie); async function signedOutPage(): Promise { const page = await buildDriver({ signedIn: false }); diff --git a/apps/e2e/src/tests/git-migrations.test.ts b/apps/e2e/src/tests/git-migrations.test.ts index 4310be6f0..779b5a18a 100644 --- a/apps/e2e/src/tests/git-migrations.test.ts +++ b/apps/e2e/src/tests/git-migrations.test.ts @@ -21,6 +21,7 @@ import { tryCleanup } from '../helpers/sql-exec.js'; import { AppPage } from '../pages/AppPage.js'; import { ConnectionModal } from '../pages/ConnectionModal.js'; import { MigrationPage } from '../pages/MigrationPage.js'; +import { apiCall } from '../helpers/accounts.js'; /** * The real Git server the server's own tests use (packages/server), loaded at @@ -40,7 +41,6 @@ async function startTestGitServer(): Promise { return mod.startTestGitServer(); } -const API_URL = process.env.E2E_API_URL ?? 'http://127.0.0.1:3210'; /** * The whole flow for one engine. The seed gives every engine a `demo_a` and a @@ -60,14 +60,7 @@ let app: AppPage; let modal: ConnectionModal; let migration: MigrationPage; -async function api(method: string, path: string, body?: unknown) { - const res = await fetch(`${API_URL}/api${path}`, { - method, - headers: { ...(body ? { 'content-type': 'application/json' } : {}), cookie: admin }, - ...(body ? { body: JSON.stringify(body) } : {}), - }); - return { status: res.status, json: (await res.json().catch(() => null)) as any }; -} +const api = (method: string, path: string, body?: unknown) => apiCall(method, path, body, admin); describe.skipIf(!hasConfig(dialect))(`Migrations in Git (${label})`, () => { beforeAll(async () => { diff --git a/apps/e2e/src/tests/workspaces.test.ts b/apps/e2e/src/tests/workspaces.test.ts index d550360c1..c4832f16d 100644 --- a/apps/e2e/src/tests/workspaces.test.ts +++ b/apps/e2e/src/tests/workspaces.test.ts @@ -12,6 +12,7 @@ import { buildDriver, quitDriver, clickWhen, waitFor, BASE_URL } from '../helper import { sessionCookie } from '../helpers/app-session.js'; import { saveScreenshot } from '../helpers/screenshot.js'; import { byTestId } from '../helpers/test-ids.js'; +import { apiCall } from '../helpers/accounts.js'; const API_URL = process.env.E2E_API_URL ?? 'http://127.0.0.1:3210'; const RUN = Date.now().toString(36); @@ -30,14 +31,7 @@ let guestCookie = ''; const WALKER_EMAIL = `e2e-wswalker-${RUN}@foxschema.test`; let walkerId = ''; -async function api(method: string, path: string, body?: unknown, cookie = admin) { - const res = await fetch(`${API_URL}/api${path}`, { - method, - headers: { ...(body !== undefined ? { 'content-type': 'application/json' } : {}), cookie }, - ...(body !== undefined ? { body: JSON.stringify(body) } : {}), - }); - return { status: res.status, json: (await res.json().catch(() => null)) as any }; -} +const api = (method: string, path: string, body?: unknown, cookie = admin) => apiCall(method, path, body, cookie); async function openMenu(page: Page = driver): Promise { if (page === driver) await page.goto(BASE_URL);