1
0
Fork 0
mirror of synced 2024-10-01 01:28:51 +13:00

fix tests

This commit is contained in:
Maurits Lourens 2021-10-05 13:38:03 +02:00
parent 42d5140c7f
commit 53cfb8dc9c

View file

@ -1,98 +1,100 @@
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 RestIntegration = require("../rest")
class TestConfiguration {
constructor(config = {}) {
this.integration = new RestIntegration.integration(config)
this.integration = new RestIntegration.integration(config)
}
}
describe("REST Integration", () => {
const BASE_URL = "https://myapi.com"
let config
let config
beforeEach(() => {
config = new TestConfiguration({
url: BASE_URL
url: BASE_URL,
})
})
it("calls the create method with the correct params", async () => {
const query = {
path: "/api",
queryString: "?test=1",
path: "api",
queryString: "test=1",
headers: {
Accept: "application/json"
Accept: "application/json",
},
json: {
name: "test"
}
name: "test",
},
}
const response = await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "POST",
body: "{\"name\":\"test\"}",
body: '{"name":"test"}',
headers: {
Accept: "application/json"
}
Accept: "application/json",
},
})
})
it("calls the read method with the correct params", async () => {
const query = {
path: "/api",
queryString: "?test=1",
path: "api",
queryString: "test=1",
headers: {
Accept: "text/html"
}
Accept: "text/html",
},
}
const response = await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
headers: {
Accept: "text/html"
}
Accept: "text/html",
},
})
})
it("calls the update method with the correct params", async () => {
const query = {
path: "/api",
queryString: "?test=1",
path: "api",
queryString: "test=1",
headers: {
Accept: "application/json"
Accept: "application/json",
},
json: {
name: "test"
}
name: "test",
},
}
const response = await config.integration.update(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "POST",
body: "{\"name\":\"test\"}",
body: '{"name":"test"}',
headers: {
Accept: "application/json"
}
Accept: "application/json",
},
})
})
it("calls the delete method with the correct params", async () => {
const query = {
path: "/api",
queryString: "?test=1",
path: "api",
queryString: "test=1",
headers: {
Accept: "application/json"
Accept: "application/json",
},
json: {
name: "test"
}
name: "test",
},
}
const response = await config.integration.delete(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "DELETE",
headers: {
Accept: "application/json"
}
Accept: "application/json",
},
})
})
})
})