15672: Adds unit test to API's list request with method=POST.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 17 Jan 2020 23:38:22 +0000 (20:38 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 17 Jan 2020 23:38:22 +0000 (20:38 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

package.json
src/services/common-service/common-resource-service.test.ts
yarn.lock

index 93b6bb0fd61db49fff011743c9db38064dc67b4a..26ab080003e3de364fd90d3ab54abdc119edc2b8 100644 (file)
@@ -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",
index 41a584fd78582056a279b2cd977b4731109e9bd8..a53ec40074eabf2dccb1700454569c4dd1a6f5ed 100644 (file)
@@ -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');
+    });
 });
index fd0fa51976795d7b52bb6c46853e61fb5311a03c..e6e1989f05d369129d6f09a12d10d6cb1ed8193d 100644 (file)
--- 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"