UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

80 lines (79 loc) 2.53 kB
import { ASYNCHRONOUS_JOB_TOKEN as g } from "../../../utils/APIConstants.js"; import { getEndpoint as f, BackendDestinationEnum as j } from "../../../utils/functions/getEndpoint.js"; import { http as u, HttpResponse as n } from "msw"; import J from "../util/BasicMockedCrudService.js"; const d = new J({ idField: "id", autoGenerateId: !0 }); function h(p, y, b, a = f(j.REPO_ENDPOINT), i = 201) { return [ // Handler for the asynchronous job request endpoint. u.post(`${a}${p}`, async ({ request: t }) => { const s = { token: d.create({ request: await t.json(), response: b }).id }; return n.json(s, { status: 201 }); }), // Generic async job response handler. Since this implementation is the same for all services and references the global map, it's fine if this is overridden. u.get( `${a}${g(":id")}`, ({ params: t }) => { const e = t.id, s = d.getOneById(e); if (!e || !s) return n.json( { message: "The mocked asynchronous job was not found" }, { status: 404 } ); const { request: r, response: o } = s, c = typeof o == "function" ? o(r) : o, m = i < 400 ? "COMPLETE" : "FAILED"; return n.json( { jobState: m, jobCanceling: !1, requestBody: r, etag: "00000000-0000-0000-0000-000000000000", jobId: e, responseBody: c, startedByUserId: 0, startedOn: "", changedOn: "", progressMessage: "", progressCurrent: 100, progressTotal: 100, exception: "", errorMessage: "", errorDetails: "", runtimeMS: 100 }, { // This endpoint returns a successful status code regardless of the job status status: 200 } ); } ), // Service-specific response endpoint u.get( `${a}${y(":asyncJobToken")}`, ({ params: t }) => { const e = t.asyncJobToken, s = d.getOneById(e); if (!e || !s) return n.json( { message: "The mocked asynchronous job was not found" }, { status: 404 } ); const { request: r, response: o } = s, c = typeof o == "function" ? o(r) : o; return n.json(c, { status: i }); } ) ]; } export { h as generateAsyncJobHandlers }; //# sourceMappingURL=asyncJobHandlers.js.map