{"version":3,"file":"create-mock-handlers.cjs","names":[],"sources":["../../src/testing/create-mock-handlers.ts"],"sourcesContent":["/**\n * Lightweight, MSW-shaped mock request handler factory. Returns plain\n * objects with `{ method, path, status, body }` that callers feed into\n * `msw`'s `http.<method>` helpers OR a custom test harness — the SDK\n * does **not** declare `msw` as a peer dep, so this helper is purely\n * data-driven.\n *\n * Use cases:\n * - Define request fixtures in a single file, share between tests and\n *   Storybook stories (when used).\n * - Standardise the \"happy path\" + \"error path\" shape across services.\n *\n * @example\n * import { http, HttpResponse } from \"msw\";\n * import { setupServer } from \"msw/node\";\n * import { createMockHandlers } from \"tempest-react-sdk/testing\";\n *\n * const fixtures = createMockHandlers([\n *     { method: \"GET\", path: \"/users/me\", status: 200, body: { id: \"u1\", name: \"Mauricio\" } },\n *     { method: \"POST\", path: \"/orders\", status: 201, body: { id: \"o1\" } },\n *     { method: \"GET\", path: \"/explode\", status: 500, body: { detail: \"kaboom\" } },\n * ]);\n *\n * const handlers = fixtures.map((f) =>\n *     (http as Record<string, Function>)[f.method.toLowerCase()](f.path, () =>\n *         HttpResponse.json(f.body, { status: f.status }),\n *     ),\n * );\n *\n * setupServer(...handlers);\n */\n\nexport type MockHandlerMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport interface MockHandlerInput {\n    method: MockHandlerMethod;\n    path: string;\n    /** HTTP status code. Default `200`. */\n    status?: number;\n    /** Response body — anything JSON-serialisable. Default `null`. */\n    body?: unknown;\n    /** Optional response headers. */\n    headers?: Record<string, string>;\n    /** Optional artificial delay in ms. Useful to test loading states. */\n    delayMs?: number;\n}\n\nexport interface MockHandler {\n    method: MockHandlerMethod;\n    path: string;\n    status: number;\n    body: unknown;\n    headers: Record<string, string>;\n    delayMs: number;\n}\n\n/**\n * Normalise a list of request fixtures into MSW-friendly handler descriptors.\n * Default `status` is `200`, default `body` is `null`, default `delayMs` is `0`,\n * default `headers` is `{ \"Content-Type\": \"application/json\" }`.\n */\nexport function createMockHandlers(handlers: MockHandlerInput[]): MockHandler[] {\n    return handlers.map((handler) => ({\n        method: handler.method,\n        path: handler.path,\n        status: handler.status ?? 200,\n        body: handler.body ?? null,\n        headers: handler.headers ?? { \"Content-Type\": \"application/json\" },\n        delayMs: handler.delayMs ?? 0,\n    }));\n}\n"],"mappings":"AA6DA,SAAgB,EAAmB,EAA6C,CAC5E,OAAO,EAAS,IAAK,IAAa,CAC9B,OAAQ,EAAQ,OAChB,KAAM,EAAQ,KACd,OAAQ,EAAQ,QAAU,IAC1B,KAAM,EAAQ,MAAQ,KACtB,QAAS,EAAQ,SAAW,CAAE,eAAgB,kBAAmB,EACjE,QAAS,EAAQ,SAAW,CAChC,EAAE,CACN"}