diff --git a/apps/fabro-web/app/components/run-summary-panel.test.tsx b/apps/fabro-web/app/components/run-summary-panel.test.tsx index 56e4c3171..3d7175d9d 100644 --- a/apps/fabro-web/app/components/run-summary-panel.test.tsx +++ b/apps/fabro-web/app/components/run-summary-panel.test.tsx @@ -6,6 +6,7 @@ import { RunSummaryPanelView, type RunSummaryPanelViewProps, } from "./run-summary-panel"; +import { testPrincipal } from "../lib/test-fixtures"; function instanceText(instance: TestRenderer.ReactTestInstance): string { const parts: string[] = []; @@ -52,15 +53,10 @@ function cellAfterLabel( function makeRun(overrides: Record = {}) { return { - id: "run_1", - created_by: { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", - }, - diff: null, - billing: null, + id: "run_1", + created_by: testPrincipal(), + diff: null, + billing: null, ...overrides, } as any; } diff --git a/apps/fabro-web/app/data/runs.test.ts b/apps/fabro-web/app/data/runs.test.ts index e8a461cf3..adff4a1a0 100644 --- a/apps/fabro-web/app/data/runs.test.ts +++ b/apps/fabro-web/app/data/runs.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import type { Principal, Run, RunStatus as ApiRunStatus } from "@qltysh/fabro-api-client"; +import type { Run, RunStatus as ApiRunStatus } from "@qltysh/fabro-api-client"; import { columnForStatus, columnStatusDisplay, @@ -8,15 +8,7 @@ import { mapRunToRunItem, runStatusDisplay, } from "./runs"; - -function testPrincipal(): Principal { - return { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", - }; -} +import { testPrincipal } from "../lib/test-fixtures"; function makeRun(overrides: Partial = {}): Run { return { diff --git a/apps/fabro-web/app/lib/run-actions.test.ts b/apps/fabro-web/app/lib/run-actions.test.ts index d8745f19b..a13afd650 100644 --- a/apps/fabro-web/app/lib/run-actions.test.ts +++ b/apps/fabro-web/app/lib/run-actions.test.ts @@ -24,13 +24,7 @@ import { unarchiveRuns, } from "./run-actions"; import { generatedAxios } from "./api-client"; - -const TEST_PRINCIPAL = { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", -}; +import { testPrincipal } from "./test-fixtures"; type StubResponseInit = { status: number; @@ -54,7 +48,7 @@ function makeRun(status: RunStatus, archived = false): Run { workflow: { slug: "fix_build", name: "Fix Build", graph_name: null, node_count: 0, edge_count: 0 }, automation: null, repository: null, - created_by: TEST_PRINCIPAL, + created_by: testPrincipal(), origin: { kind: "api" }, labels: {}, lifecycle: { diff --git a/apps/fabro-web/app/lib/test-fixtures.ts b/apps/fabro-web/app/lib/test-fixtures.ts new file mode 100644 index 000000000..3d669dcad --- /dev/null +++ b/apps/fabro-web/app/lib/test-fixtures.ts @@ -0,0 +1,10 @@ +import type { Principal } from "@qltysh/fabro-api-client"; + +export function testPrincipal(): Principal { + return { + kind: "user", + identity: { issuer: "fabro:test", subject: "test-user" }, + login: "test", + auth_method: "dev_token", + }; +} diff --git a/apps/fabro-web/app/routes/automations-new.test.tsx b/apps/fabro-web/app/routes/automations-new.test.tsx index 9667247b8..69f8ae58f 100644 --- a/apps/fabro-web/app/routes/automations-new.test.tsx +++ b/apps/fabro-web/app/routes/automations-new.test.tsx @@ -4,6 +4,7 @@ import TestRenderer, { act } from "react-test-renderer"; import { createMemoryRouter, RouterProvider } from "react-router"; import { ToastProvider } from "../components/toast"; +import { testPrincipal } from "../lib/test-fixtures"; import { setupReactTestEnv } from "../lib/test-utils"; let currentRun: any = null; @@ -101,13 +102,6 @@ mock.module("swr", () => ({ const { default: AutomationsNew } = await import("./automations-new"); mock.restore(); -const TEST_PRINCIPAL = { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", -}; - function makeRun(overrides: Record = {}) { return { id: "run_1", @@ -127,7 +121,7 @@ function makeRun(overrides: Record = {}) { origin_url: "https://github.com/fallback/repo.git", provider: "github", }, - created_by: TEST_PRINCIPAL, + created_by: testPrincipal(), origin: { kind: "api" }, labels: {}, lifecycle: { diff --git a/apps/fabro-web/app/routes/run-detail.test.ts b/apps/fabro-web/app/routes/run-detail.test.ts index 1fc2a775f..3cc8ad351 100644 --- a/apps/fabro-web/app/routes/run-detail.test.ts +++ b/apps/fabro-web/app/routes/run-detail.test.ts @@ -13,6 +13,7 @@ import { import { ToastProvider } from "../components/toast"; import { DemoModeProvider } from "../lib/demo-mode"; +import { testPrincipal } from "../lib/test-fixtures"; let currentRunSummary: any = null; let currentRunState: any = null; @@ -20,13 +21,6 @@ let currentQuestions: any[] = []; let deleteRunApiResult: Promise | null = null; const mountedRenderers: TestRenderer.ReactTestRenderer[] = []; -const TEST_PRINCIPAL = { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", -}; - const deleteRunApiMock = mock((_id: string) => deleteRunApiResult ?? Promise.resolve({}), ); @@ -228,7 +222,7 @@ function makeRunSummary({ workflow: { slug: "default", name: "Default", graph_name: null, node_count: 0, edge_count: 0 }, automation, repository: { name: "fabro", origin_url: null, provider: "unknown" }, - created_by: TEST_PRINCIPAL, + created_by: testPrincipal(), origin: { kind: "api" }, labels: {}, lifecycle: { diff --git a/apps/fabro-web/app/routes/run-files.render.test.tsx b/apps/fabro-web/app/routes/run-files.render.test.tsx index 9b4cb1a08..1b434d76b 100644 --- a/apps/fabro-web/app/routes/run-files.render.test.tsx +++ b/apps/fabro-web/app/routes/run-files.render.test.tsx @@ -5,13 +5,7 @@ import { MemoryRouter, Route, Routes } from "react-router"; import { toast as sonnerToast } from "sonner"; import { ToastProvider } from "../components/toast"; - -const TEST_PRINCIPAL = { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", -}; +import { testPrincipal } from "../lib/test-fixtures"; let currentFilesPayload: any = null; let currentCommitsPayload: any = null; @@ -58,7 +52,7 @@ mock.module("../lib/queries", () => ({ workflow: { slug: "default", name: "Default", graph_name: null, node_count: 0, edge_count: 0 }, automation: null, repository: { name: "fabro", origin_url: null, provider: "unknown" }, - created_by: TEST_PRINCIPAL, + created_by: testPrincipal(), origin: { kind: "api" }, labels: {}, lifecycle: { diff --git a/apps/fabro-web/app/routes/runs.preferences.test.tsx b/apps/fabro-web/app/routes/runs.preferences.test.tsx index 21af44aef..fd217d152 100644 --- a/apps/fabro-web/app/routes/runs.preferences.test.tsx +++ b/apps/fabro-web/app/routes/runs.preferences.test.tsx @@ -1,10 +1,11 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; import TestRenderer, { act } from "react-test-renderer"; import { createMemoryRouter, RouterProvider } from "react-router"; -import type { PaginatedRunList, Principal, Run } from "@qltysh/fabro-api-client"; +import type { PaginatedRunList, Run } from "@qltysh/fabro-api-client"; import { ToastProvider } from "../components/toast"; import { CHILD_RUNS_LIST_PREFERENCES_STORAGE_KEY } from "../components/runs-list/preferences"; +import { testPrincipal } from "../lib/test-fixtures"; import { setupReactTestEnv } from "../lib/test-utils"; class MemoryStorage { @@ -27,15 +28,6 @@ let previousElement: unknown; let hadElement = false; const mountedRenderers: TestRenderer.ReactTestRenderer[] = []; -function testPrincipal(): Principal { - return { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", - }; -} - function run(id: string, repo = "qlty/fabro", workflow = "release"): Run { return { id, diff --git a/apps/fabro-web/app/routes/runs.test.tsx b/apps/fabro-web/app/routes/runs.test.tsx index 6f71938c9..e20e018ed 100644 --- a/apps/fabro-web/app/routes/runs.test.tsx +++ b/apps/fabro-web/app/routes/runs.test.tsx @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import type { BoardColumn, Principal, Run } from "@qltysh/fabro-api-client"; +import type { BoardColumn, Run } from "@qltysh/fabro-api-client"; import { buildBoardColumns, @@ -11,15 +11,7 @@ import { shouldRefreshBoardForEvent, } from "./runs"; import { summarizeBatchLifecycleAction } from "../components/runs-list/batch-lifecycle"; - -function testPrincipal(): Principal { - return { - kind: "user", - identity: { issuer: "fabro:test", subject: "test-user" }, - login: "test", - auth_method: "dev_token", - }; -} +import { testPrincipal } from "../lib/test-fixtures"; function boardRun(id: string, column: BoardColumn, questionText?: string): Run { const status = diff --git a/lib/crates/fabro-cli/tests/it/cmd/support.rs b/lib/crates/fabro-cli/tests/it/cmd/support.rs index 93ad4d6a9..4625cb81c 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/support.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/support.rs @@ -177,15 +177,7 @@ pub(crate) fn remote_run_summary_json( "origin_url": null, "provider": "unknown" }, - "created_by": { - "kind": "user", - "identity": { - "issuer": "fabro:test", - "subject": "test-user" - }, - "login": "test", - "auth_method": "dev_token" - }, + "created_by": fabro_types::test_support::test_principal(), "origin": { "kind": "api" },