From dc8823139e81d12ce0c708226166a7e30e491fd1 Mon Sep 17 00:00:00 2001 From: Oladev Date: Wed, 21 Oct 2026 09:57:52 +0100 Subject: [PATCH] fix: Cover `offlineActionQueue` with unit tests (#1950) --- src/components/Streams/__tests__/testUtils.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/components/Streams/__tests__/testUtils.ts b/src/components/Streams/__tests__/testUtils.ts index 8bf2068b..eed4a1c9 100644 --- a/src/components/Streams/__tests__/testUtils.ts +++ b/src/components/Streams/__tests__/testUtils.ts @@ -1,5 +1,41 @@ import { vi } from "vitest"; +/** + * Minimal fake `Response`-like object for apiVersion tests. + * Avoids network access while exercising status/body handling. + */ +export function makeResponse( + body: unknown, + init: { ok?: boolean; status?: number } = {}, +) { + const status = init.status ?? 200; + return { + ok: init.ok ?? (status >= 200 && status < 300), + status, + json: vi.fn().mockResolvedValue(body), + text: vi.fn().mockResolvedValue( + typeof body === "string" ? body : JSON.stringify(body), + ), + } as unknown as Response; +} + +/** + * Install a fetch mock that resolves with the given responses in order. + * Returns the mock so tests can assert call arguments. + */ +export function mockFetch(...responses: Array) { + const fetchMock = vi.fn(); + for (const response of responses) { + if (response instanceof Error) { + fetchMock.mockRejectedOnce(response); + } else { + fetchMock.mockResolvedOnce(response); + } + } + vi.stubGlobal("fetch", fetchMock); + return fetchMock; +} + /** * Default props for StreamCreatedModal tests. */ @@ -7,7 +43,7 @@ export const defaultStreamCreatedModalProps = { isOpen: true, onClose: vi.fn(), streamId: "STR-123", - streamUrl: "https://fluxora.io/stream/STR-123", + streamUrl: "https://fluxoura.io/stream/STR-123", onCreateAnother: vi.fn(), };