From 6183e0220cbde9d020a9ebac412732a5ed41583a Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 17 Jan 2020 20:38:22 -0300 Subject: [PATCH] 15672: Adds unit test to API's list request with method=POST. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- package.json | 2 +- .../common-resource-service.test.ts | 16 ++++++++++++++++ yarn.lock | 8 ++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 93b6bb0f..26ab0800 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "@types/redux-devtools": "3.0.44", "@types/sinon": "7.5", "@types/uuid": "3.4.4", - "axios-mock-adapter": "1.15.0", + "axios-mock-adapter": "1.17.0", "enzyme": "3.6.0", "enzyme-adapter-react-16": "1.5.0", "jest-localstorage-mock": "2.2.0", diff --git a/src/services/common-service/common-resource-service.test.ts b/src/services/common-service/common-resource-service.test.ts index 41a584fd..a53ec400 100644 --- a/src/services/common-service/common-resource-service.test.ts +++ b/src/services/common-service/common-resource-service.test.ts @@ -41,10 +41,13 @@ describe("CommonResourceService", () => { }); 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 () => { @@ -110,4 +113,17 @@ describe("CommonResourceService", () => { itemsAvailable: 20 }); }); + + it("#list using POST when query string is too big", async () => { + axiosMock + .onPost("/resource") + .reply(200); + const tooBig = 'x'.repeat(1500); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); + const resource = 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].params._method).toBe('GET'); + }); }); diff --git a/yarn.lock b/yarn.lock index fd0fa519..e6e1989f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -996,10 +996,10 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== -axios-mock-adapter@1.15.0: - version "1.15.0" - resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.15.0.tgz#fbc06825d8302c95c3334d21023bba996255d45d" - integrity sha1-+8BoJdgwLJXDM00hAju6mWJV1F0= +axios-mock-adapter@1.17.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.17.0.tgz#0dbee43c606d4aaba5a43d88d96d6661a7cc3c04" + integrity sha512-q3efmwJUOO4g+wsLNSk9Ps1UlJoF3fQ3FSEe4uEEhkRtu7SoiAVPj8R3Hc/WP55MBTVFzaDP9QkdJhdVhP8A1Q== dependencies: deep-equal "^1.0.1" -- 2.30.2