UNPKG

@rocketmakers/api-swr

Version:

Rocketmakers front-end library for parsing a generated Typescript API client into a set of configurable React hooks for fetching and mutating data.

47 lines (46 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMockAxiosErrorResponse = exports.createMockAxiosSuccessResponse = exports.createMockAxiosResponse = void 0; /** * Creates a mock Axios response. * @returns An AxiosResponse with the provided parameters. */ const createMockAxiosResponse = ({ data, status = 200, statusText = 'OK', headers = {}, config = {}, }) => { return { data, status, statusText, headers, config: Object.assign(Object.assign({}, config), { headers }), }; }; exports.createMockAxiosResponse = createMockAxiosResponse; /** * Creates a successful mock Axios response. * * @param data - The data to include in the response. * @param status - The status code for the response. Defaults to 200. * * @returns An AxiosResponse with a status of 200 (or the provided status) and the provided data. */ const createMockAxiosSuccessResponse = (data, status = 200) => { return (0, exports.createMockAxiosResponse)({ data, status, statusText: 'OK', }); }; exports.createMockAxiosSuccessResponse = createMockAxiosSuccessResponse; /** * Creates an error mock Axios response. * @param status - The status code for the response. Defaults to 500. * @returns An AxiosResponse with a status of 500 (or the provided status) and an empty data object. */ const createMockAxiosErrorResponse = (status = 500, statusText = 'Error') => { return (0, exports.createMockAxiosResponse)({ data: {}, status, statusText, }); }; exports.createMockAxiosErrorResponse = createMockAxiosErrorResponse;