fix(test): de-flake authProvider.test.ts OOBE test-connection (GRO-2745) #244

Merged
Flea Flicker merged 1 commits from flea/gro-2745-deflake-authprovider-test-connection into dev 2026-08-22 08:49:44 +00:00
Member

Problem

POST /admin/auth-provider/test > "returns 400 for missing clientSecret" (~line 245 in both src/__tests__/authProvider.test.ts and apps/api/src/__tests__/authProvider.test.ts) was flaky. The route performs a real fetch to https://auth.example.com/.well-known/openid-configuration with a 10 s AbortSignal.timeout. The test had no explicit timeout override, so vitest used its default 5 s — whenever DNS/network took >5 s the test timed out. Confirmed to have red-lined CI on PR #243 (unrelated diff), went green on re-run.

Fix

  • Mock global.fetch via vi.spyOn so the route's connection attempt resolves instantly without real network I/O.
  • Add afterEach(() => vi.restoreAllMocks()) to the POST describe block to clean up the spy between tests.
  • Reconcile misleading test title: was "returns 400 for missing clientSecret (not required for test)" but the assertion was expect(status).toBe(200). Renamed to "returns 200 when clientSecret is omitted (not required by test-connection schema)".

Both copies of the test file (src/__tests__/ and apps/api/src/__tests__/) updated identically.

No changes to route behaviour — authProvider.ts is untouched.

Updated UAT_PLAYBOOK.md

No UAT Playbook update required — test-only change with no user-facing behaviour change.

Verification

All 18 tests in authProvider.test.ts pass locally. The previously flaky test now completes in ~3 ms (was up to 10 s+).

Closes GRO-2745

## Problem `POST /admin/auth-provider/test > "returns 400 for missing clientSecret"` (~line 245 in both `src/__tests__/authProvider.test.ts` and `apps/api/src/__tests__/authProvider.test.ts`) was flaky. The route performs a real `fetch` to `https://auth.example.com/.well-known/openid-configuration` with a 10 s `AbortSignal.timeout`. The test had no explicit timeout override, so vitest used its default 5 s — whenever DNS/network took >5 s the test timed out. Confirmed to have red-lined CI on PR #243 (unrelated diff), went green on re-run. ## Fix - **Mock `global.fetch`** via `vi.spyOn` so the route's connection attempt resolves instantly without real network I/O. - Add `afterEach(() => vi.restoreAllMocks())` to the POST describe block to clean up the spy between tests. - **Reconcile misleading test title**: was `"returns 400 for missing clientSecret (not required for test)"` but the assertion was `expect(status).toBe(200)`. Renamed to `"returns 200 when clientSecret is omitted (not required by test-connection schema)"`. Both copies of the test file (`src/__tests__/` and `apps/api/src/__tests__/`) updated identically. No changes to route behaviour — `authProvider.ts` is untouched. ## Updated UAT_PLAYBOOK.md No UAT Playbook update required — test-only change with no user-facing behaviour change. ## Verification All 18 tests in `authProvider.test.ts` pass locally. The previously flaky test now completes in ~3 ms (was up to 10 s+). Closes [GRO-2745](/GRO/issues/GRO-2745)
Flea Flicker added 1 commit 2026-08-22 08:39:43 +00:00
fix(test): de-flake authProvider.test.ts OOBE test-connection timeout (GRO-2745)
CI / Lint & Typecheck (pull_request) Successful in 19s
CI / Test (pull_request) Successful in 20s
CI / Build & Push Docker Images (pull_request) Successful in 46s
bb55c658a5
Mock global.fetch in the test-connection test so it no longer hits the
real network. The route has a 10s fetch timeout, but the test used the
default 5s vitest timeout, causing intermittent failures when DNS/network
was slow. Add afterEach(vi.restoreAllMocks) to clean up between tests,
and reconcile the misleading "returns 400" test title to match the 200
assertion the route actually produces.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Flea Flicker merged commit 62c80ca8d0 into dev 2026-08-22 08:49:44 +00:00
Flea Flicker deleted branch flea/gro-2745-deflake-authprovider-test-connection 2026-08-22 08:49:45 +00:00
Sign in to join this conversation.