diff options
author | James Forsyth <jf2512@att.com> | 2019-04-09 20:41:31 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-09 20:41:31 +0000 |
commit | cae868635ebe867b85223b056a5243c128192cbe (patch) | |
tree | 13db7f35d15a5463dfe3512e849ab4275a2ba346 /test/app/networking/NetworkCalls.test.js | |
parent | 5b062c1f5005e14b6f18563ee875a06f5c1bc299 (diff) | |
parent | b0f2f345cc2d1cc3812ad8a06fc1898daf5842d0 (diff) |
Merge "Remove unused code"
Diffstat (limited to 'test/app/networking/NetworkCalls.test.js')
-rw-r--r-- | test/app/networking/NetworkCalls.test.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/app/networking/NetworkCalls.test.js b/test/app/networking/NetworkCalls.test.js new file mode 100644 index 0000000..373fbac --- /dev/null +++ b/test/app/networking/NetworkCalls.test.js @@ -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); + }); + }); +}); |