summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Forsyth <jf2512@att.com>2019-04-10 13:36:42 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-10 13:36:42 +0000
commit6a47c2493c21c09df35df1f9f03474f8c2f8874a (patch)
tree60e2c4c7f3bfb53c3cd3ff7a4f3d251f85e34281
parent2ac895038dff9d8f4970f9963e49acc64f94810f (diff)
parent12af2f20c2313a3fc1fe5761eaf2e885d3c8b751 (diff)
Merge "Fixing failing test + covarage improvement"
-rw-r--r--test/app/networking/NetworkCalls.test.js51
1 files changed, 35 insertions, 16 deletions
diff --git a/test/app/networking/NetworkCalls.test.js b/test/app/networking/NetworkCalls.test.js
index 373fbac..a3b6176 100644
--- a/test/app/networking/NetworkCalls.test.js
+++ b/test/app/networking/NetworkCalls.test.js
@@ -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);
});
});