fix(test): de-flake authProvider.test.ts OOBE test-connection (GRO-2745) [uat → main] #246

Merged
Flea Flicker merged 3 commits from promote/uat-to-main-gro-2745 into main 2026-08-23 08:23:48 +00:00
2 changed files with 18 additions and 6 deletions
Showing only changes of commit 40899d135a - Show all commits
+9 -3
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { Hono } from "hono";
import { authProviderRouter } from "../routes/authProvider.js";
@@ -227,6 +227,7 @@ describe("PUT /admin/auth-provider", () => {
describe("POST /admin/auth-provider/test", () => {
beforeEach(resetMock);
afterEach(() => vi.restoreAllMocks());
it("returns ok=false for unreachable issuer", async () => {
const app = makeApp(mockSuperUser);
@@ -242,7 +243,12 @@ describe("POST /admin/auth-provider/test", () => {
expect(body.error).toBeTruthy();
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
it("returns 400 for missing clientSecret (not required for test)", async () => {
it("returns 200 when clientSecret is omitted (not required by test-connection schema)", async () => {
// Mock fetch so the route does not make a real network request.
vi.spyOn(global, "fetch").mockResolvedValueOnce({
ok: true,
json: async () => ({ issuer: "https://auth.example.com" }),
} as Response);
const app = makeApp(mockSuperUser);
const { status } = await post(app, "/admin/auth-provider/test", {
providerId: "authentik",
@@ -250,7 +256,7 @@ describe("POST /admin/auth-provider/test", () => {
issuerUrl: "https://auth.example.com",
clientId: "client",
}, mockSuperUser);
expect(status).toBe(200); // clientSecret omitted intentionally for test
expect(status).toBe(200);
});
});
+9 -3
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { Hono } from "hono";
import { authProviderRouter } from "../routes/authProvider.js";
@@ -227,6 +227,7 @@ describe("PUT /admin/auth-provider", () => {
describe("POST /admin/auth-provider/test", () => {
beforeEach(resetMock);
afterEach(() => vi.restoreAllMocks());
it("returns ok=false for unreachable issuer", async () => {
const app = makeApp(mockSuperUser);
@@ -242,7 +243,12 @@ describe("POST /admin/auth-provider/test", () => {
expect(body.error).toBeTruthy();
}, 15000); // timeout must exceed the 10s fetch timeout in the route handler
it("returns 400 for missing clientSecret (not required for test)", async () => {
it("returns 200 when clientSecret is omitted (not required by test-connection schema)", async () => {
// Mock fetch so the route does not make a real network request.
vi.spyOn(global, "fetch").mockResolvedValueOnce({
ok: true,
json: async () => ({ issuer: "https://auth.example.com" }),
} as Response);
const app = makeApp(mockSuperUser);
const { status } = await post(app, "/admin/auth-provider/test", {
providerId: "authentik",
@@ -250,7 +256,7 @@ describe("POST /admin/auth-provider/test", () => {
issuerUrl: "https://auth.example.com",
clientId: "client",
}, mockSuperUser);
expect(status).toBe(200); // clientSecret omitted intentionally for test
expect(status).toBe(200);
});
});