2021-04-12 13:32:25 +00:00
|
|
|
import nock from "nock";
|
2017-03-02 22:07:01 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
const createRequestMock = ({
|
|
|
|
bearerToken,
|
|
|
|
endpoint,
|
|
|
|
method,
|
|
|
|
params,
|
|
|
|
responseStatus = 200,
|
|
|
|
response,
|
|
|
|
}) => {
|
2017-03-02 22:07:01 +00:00
|
|
|
const reqHeaders = { Authorization: `Bearer ${bearerToken}` };
|
2021-04-12 13:32:25 +00:00
|
|
|
const host = "http://localhost:8080";
|
2017-03-02 22:07:01 +00:00
|
|
|
const req = bearerToken ? nock(host) : nock(host, { reqHeaders });
|
|
|
|
|
|
|
|
if (params) {
|
2021-04-12 13:32:25 +00:00
|
|
|
return req[method](endpoint, JSON.stringify(params)).reply(
|
|
|
|
responseStatus,
|
|
|
|
response
|
|
|
|
);
|
2017-03-02 22:07:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
return req[method](endpoint).reply(responseStatus, response);
|
2017-03-02 22:07:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default createRequestMock;
|