|
|
@ -1,4 +1,6 @@ |
|
|
jest.mock("node-fetch", () => jest.fn(() => ({ json: jest.fn(), text: jest.fn() }))) |
|
|
jest.mock("node-fetch", () => |
|
|
|
|
|
jest.fn(() => ({ json: jest.fn(), text: jest.fn() })) |
|
|
|
|
|
) |
|
|
const fetch = require("node-fetch") |
|
|
const fetch = require("node-fetch") |
|
|
const RestIntegration = require("../rest") |
|
|
const RestIntegration = require("../rest") |
|
|
|
|
|
|
|
|
@ -14,85 +16,85 @@ describe("REST Integration", () => { |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
config = new TestConfiguration({ |
|
|
config = new TestConfiguration({ |
|
|
url: BASE_URL |
|
|
url: BASE_URL, |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it("calls the create method with the correct params", async () => { |
|
|
it("calls the create method with the correct params", async () => { |
|
|
const query = { |
|
|
const query = { |
|
|
path: "/api", |
|
|
path: "api", |
|
|
queryString: "?test=1", |
|
|
queryString: "test=1", |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
}, |
|
|
}, |
|
|
json: { |
|
|
json: { |
|
|
name: "test" |
|
|
name: "test", |
|
|
} |
|
|
}, |
|
|
} |
|
|
} |
|
|
const response = await config.integration.create(query) |
|
|
const response = await config.integration.create(query) |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
method: "POST", |
|
|
method: "POST", |
|
|
body: "{\"name\":\"test\"}", |
|
|
body: '{"name":"test"}', |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
} |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it("calls the read method with the correct params", async () => { |
|
|
it("calls the read method with the correct params", async () => { |
|
|
const query = { |
|
|
const query = { |
|
|
path: "/api", |
|
|
path: "api", |
|
|
queryString: "?test=1", |
|
|
queryString: "test=1", |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "text/html" |
|
|
Accept: "text/html", |
|
|
} |
|
|
}, |
|
|
} |
|
|
} |
|
|
const response = await config.integration.read(query) |
|
|
const response = await config.integration.read(query) |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "text/html" |
|
|
Accept: "text/html", |
|
|
} |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it("calls the update method with the correct params", async () => { |
|
|
it("calls the update method with the correct params", async () => { |
|
|
const query = { |
|
|
const query = { |
|
|
path: "/api", |
|
|
path: "api", |
|
|
queryString: "?test=1", |
|
|
queryString: "test=1", |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
}, |
|
|
}, |
|
|
json: { |
|
|
json: { |
|
|
name: "test" |
|
|
name: "test", |
|
|
} |
|
|
}, |
|
|
} |
|
|
} |
|
|
const response = await config.integration.update(query) |
|
|
const response = await config.integration.update(query) |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
method: "POST", |
|
|
method: "POST", |
|
|
body: "{\"name\":\"test\"}", |
|
|
body: '{"name":"test"}', |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
} |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it("calls the delete method with the correct params", async () => { |
|
|
it("calls the delete method with the correct params", async () => { |
|
|
const query = { |
|
|
const query = { |
|
|
path: "/api", |
|
|
path: "api", |
|
|
queryString: "?test=1", |
|
|
queryString: "test=1", |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
}, |
|
|
}, |
|
|
json: { |
|
|
json: { |
|
|
name: "test" |
|
|
name: "test", |
|
|
} |
|
|
}, |
|
|
} |
|
|
} |
|
|
const response = await config.integration.delete(query) |
|
|
const response = await config.integration.delete(query) |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { |
|
|
method: "DELETE", |
|
|
method: "DELETE", |
|
|
headers: { |
|
|
headers: { |
|
|
Accept: "application/json" |
|
|
Accept: "application/json", |
|
|
} |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |