fleet/frontend/test/mocks/create_request_mock.js
Mike Stone d747a471af Refactor API client (#1335)
* Isolate each API entity
* Improve code structure in API client and request mocks
* Standardize on a request mock structure
* Use helper for creating request mocks
* Adds Request class to handle API requests
2017-03-02 17:07:01 -05:00

18 lines
533 B
JavaScript

import nock from 'nock';
const createRequestMock = ({ bearerToken, endpoint, method, params, responseStatus = 200, response }) => {
const reqHeaders = { Authorization: `Bearer ${bearerToken}` };
const host = 'http://localhost:8080';
const req = bearerToken ? nock(host) : nock(host, { reqHeaders });
if (params) {
return req[method](endpoint, JSON.stringify(params))
.reply(responseStatus, response);
}
return req[method](endpoint)
.reply(responseStatus, response);
};
export default createRequestMock;