import { vi } from 'vitest' // The canonical fetch stub for store specs. // // `handler(url, init)` returns `{ status, body }`; body is JSON-encoded, and // `ok` is derived from the status so a store's error path can be exercised by // returning 4xx/5xx. Returns the vi.fn so a caller can assert on calls. // // Extracted 2026-09-21 from six specs carrying byte-identical copies // (adminStore, credentials, dbMaintenance, gallery, suggestions, // galleryRelatedStrip). Those still hold their own; migrate each the next // time it is touched rather than in one sweep. export function stubFetch (handler) { globalThis.fetch = vi.fn(async (url, init) => { const { status, body } = handler(url, init) return { ok: status >= 200 && status < 300, status, statusText: String(status), text: async () => (body == null ? '' : JSON.stringify(body)), } }) return globalThis.fetch }