Fixing failing test 45/84645/3
authorMariusz Sygnowski <mariusz.sygnowski@nokia.com>
Tue, 9 Apr 2019 09:32:23 +0000 (11:32 +0200)
committerMariusz Sygnowski <mariusz.sygnowski@nokia.com>
Wed, 10 Apr 2019 11:01:08 +0000 (13:01 +0200)
+ covarage improvement

Change-Id: Id13e334cc1493274081758079a1f896f35af6b80
Issue-ID: AAI-2341
Signed-off-by: Mariusz Sygnowski<mariusz.sygnowski@nokia.com>
test/app/networking/NetworkCalls.test.js

index 373fbac..a3b6176 100644 (file)
@@ -90,34 +90,53 @@ describe("Network Utils", () => {
 
   describe('#getRequest', () => {
     it("should fetch any request", () => {
-      const json = suite.sandbox.stub();
-      const fetchPromise = Promise.resolve({json});
-      global.fetch = suite.sandbox.stub();
-
-      global.fetch
-      .withArgs('URL', {
-        credentials: 'same-origin',
-        method: 'GET'
-      })
-      .returns(fetchPromise);
-
-      NetworkCalls.getRequest("URL", "GET");
-
-      return fetchPromise.then(() => {
-        sinon.assert.calledOnce(json);
-      });
+        // given
+        global.fetch = suite.sandbox.stub();
+        const json = suite.sandbox.stub();
+        const url = "localhost";
+
+        global.fetch
+            .withArgs(url, {
+                credentials: 'same-origin',
+                method: 'GET'
+            })
+            .returns(json);
+
+        // when
+        const request = NetworkCalls.getRequest(url, "GET");
+
+        //then
+        expect(request).toBe(json)
+        sinon.assert.calledOnce(global.fetch);
     });
   });
 
   describe('#genericRequest', () => {
     it('should fetch any generic request', () => {
+      // given
       global.fetch = suite.sandbox.stub();
       const then = suite.sandbox.stub();
       fetch.returns({then});
+
+      // when
       NetworkCalls.genericRequest("localhost", "/relativeUrl", "GET");
 
+      // then
       expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d");
+      sinon.assert.calledOnce(fetch);
+    });
 
+    it('should fetch any generic request - non relative', () => {
+      // given
+      global.fetch = suite.sandbox.stub();
+      const then = suite.sandbox.stub();
+      fetch.returns({then});
+
+      // when
+      NetworkCalls.genericRequest("localhost", false, "GET");
+
+      // then
+      expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d");
       sinon.assert.calledOnce(fetch);
     });
   });

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use