Merge "Increase code coverage" 1.3.0
authorJames Forsyth <jf2512@att.com>
Thu, 11 Oct 2018 13:16:50 +0000 (13:16 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 11 Oct 2018 13:16:50 +0000 (13:16 +0000)
package.json
test/networking/NetworkCalls.test.js [new file with mode: 0644]
test/networking/NetworkUtil.test.js [new file with mode: 0644]

index c35db74..2c33b10 100644 (file)
     "react-hot-loader": "^3.0.0-beta.6",
     "redux-mock-store": "^1.4.0",
     "sass-loader": "^3.1.2",
+    "sinon": "^6.3.4",
     "source-map-loader": "^0.1.5",
     "style-loader": "^0.13.1",
     "url-loader": "^0.5.7",
diff --git a/test/networking/NetworkCalls.test.js b/test/networking/NetworkCalls.test.js
new file mode 100644 (file)
index 0000000..373fbac
--- /dev/null
@@ -0,0 +1,124 @@
+import NetworkCalls from 'app/networking/NetworkCalls';
+import * as sinon from "sinon";
+
+describe("Network Utils", () => {
+
+  let suite;
+
+  beforeEach(() => {
+    suite = {};
+    suite.sandbox = sinon.createSandbox();
+  });
+
+  afterEach(() => {
+    suite.sandbox.reset();
+  });
+
+  describe('#fetchRequest', () => {
+    it('should fetch request', () => {
+      global.fetch = suite.sandbox.stub();
+
+      const then = suite.sandbox.stub();
+
+      fetch.returns({then});
+
+      NetworkCalls.fetchRequest("URL", "POST", "POST", "HEADER", "BODY");
+      sinon.assert.calledOnce(then);
+
+      expect(then.firstCall.args[0]({json: () => "json"})).toEqual("json");
+      sinon.assert.calledOnce(fetch);
+    });
+  });
+
+  describe('#fetchConfigurableViewRequest', () => {
+    it('fetch configurable request', () => {
+      const queryData = {
+        api: "api",
+        method: "method",
+        headers: "headers",
+        componentDataDescriptor: {object: "object"}
+      };
+
+      const fetchPromise = Promise.resolve();
+      global.fetch = suite.sandbox.stub();
+
+      global.fetch
+      .withArgs(queryData.api, {
+        method: queryData.method,
+        headers: queryData.headers,
+        body: queryData.body
+      })
+      .returns(fetchPromise);
+
+      NetworkCalls.fetchConfigurableViewRequest(queryData);
+
+      sinon.assert.calledWith(fetch, "http://localhost:api", {
+        method: queryData.method,
+        headers: queryData.headers,
+        credentials: "same-origin",
+        body: '{"object":"object"}'
+      });
+    });
+  });
+
+  describe('#fetchRequestObj', () => {
+    it('fetch request object', () => {
+
+      const fetchPromise = Promise.resolve();
+      global.fetch = suite.sandbox.stub();
+      const url = 'url';
+
+      global.fetch
+      .withArgs(url, {
+        method: 'GET',
+        headers: 'POST_HEADER',
+        body: 'BODY'
+
+      })
+      .returns(fetchPromise);
+
+      NetworkCalls.fetchRequestObj(url, "GET", "POST_HEADER", "BODY");
+
+      sinon.assert.calledWith(fetch, url, {
+        credentials: 'same-origin',
+        method: "GET",
+        headers: "POST_HEADER",
+        body: "BODY"
+      });
+    });
+  });
+
+  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);
+      });
+    });
+  });
+
+  describe('#genericRequest', () => {
+    it('should fetch any generic request', () => {
+      global.fetch = suite.sandbox.stub();
+      const then = suite.sandbox.stub();
+      fetch.returns({then});
+      NetworkCalls.genericRequest("localhost", "/relativeUrl", "GET");
+
+      expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d");
+
+      sinon.assert.calledOnce(fetch);
+    });
+  });
+});
diff --git a/test/networking/NetworkUtil.test.js b/test/networking/NetworkUtil.test.js
new file mode 100644 (file)
index 0000000..1743813
--- /dev/null
@@ -0,0 +1,22 @@
+import {getTSUIElasticSearchQueryString} from 'app/networking/NetworkUtil';
+
+describe("Network Utils", () => {
+  describe('#getTSUIElasticSearchQueryString', () => {
+    it('should return query body', () => {
+      const query = "query";
+      const response = getTSUIElasticSearchQueryString(query);
+      expect(response).toEqual({"maxResults": "10", "queryStr": "query"});
+    });
+
+    it('should return partial request query', () => {
+      const query = "";
+      const response = getTSUIElasticSearchQueryString(query);
+      expect(response).toEqual({"maxResults": "10", "queryStr": ""});
+    });
+
+    it('should be truthy', () => {
+      const query = "";
+      expect(getTSUIElasticSearchQueryString(query)).toBeTruthy();
+    })
+  });
+});

© 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