};
describe("CommonResourceService", () => {
- const axiosInstance = axios.create();
- const axiosMock = new MockAdapter(axiosInstance);
+ let axiosInstance: AxiosInstance;
+ let axiosMock: MockAdapter;
beforeEach(() => {
- axiosMock.reset();
+ axiosInstance = axios.create();
+ axiosMock = new MockAdapter(axiosInstance);
});
it("#create", async () => {
});
it("#create maps request params to snake case", async () => {
- const realPost = axiosInstance.post;
axiosInstance.post = jest.fn(() => Promise.resolve({data: {}}));
const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions);
await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
expect(axiosInstance.post).toHaveBeenCalledWith("/resource", {owner_uuid: "ownerUuidValue"});
- // Restore post function so that tests below don't break.
- axiosInstance.post = realPost;
});
it("#delete", async () => {
it("#list using POST when query string is too big", async () => {
axiosMock
- .onPost("/resource")
+ .onAny("/resource")
.reply(200);
const tooBig = 'x'.repeat(1500);
const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions);
- const resource = await commonResourceService.list({ filters: tooBig });
+ await commonResourceService.list({ filters: tooBig });
expect(axiosMock.history.get.length).toBe(0);
expect(axiosMock.history.post.length).toBe(1);
- expect(axiosMock.history.post[0].data.get('filters')).toBe('['+tooBig+']');
+ expect(axiosMock.history.post[0].data.get('filters')).toBe(`[${tooBig}]`);
expect(axiosMock.history.post[0].params._method).toBe('GET');
});
});