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.

41 lines (40 loc) 1.24 kB
/** * Creates a mock Axios response. * @returns An AxiosResponse with the provided parameters. */ export const createMockAxiosResponse = ({ data, status = 200, statusText = 'OK', headers = {}, config = {}, }) => { return { data, status, statusText, headers, config: Object.assign(Object.assign({}, config), { headers }), }; }; /** * 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. */ export const createMockAxiosSuccessResponse = (data, status = 200) => { return createMockAxiosResponse({ data, status, statusText: 'OK', }); }; /** * 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. */ export const createMockAxiosErrorResponse = (status = 500, statusText = 'Error') => { return createMockAxiosResponse({ data: {}, status, statusText, }); };