1
0
Fork 0
mirror of synced 2024-09-13 07:53:31 +12:00
budibase/packages/server/src/integrations/tests/airtable.spec.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-03-16 05:07:04 +13:00
const Airtable = require("airtable")
2021-03-17 07:43:56 +13:00
const AirtableIntegration = require("../airtable")
2021-03-12 22:29:27 +13:00
jest.mock("airtable")
class TestConfiguration {
constructor(config = {}) {
2021-03-17 07:43:56 +13:00
this.integration = new AirtableIntegration.integration(config)
this.client = {
create: jest.fn(),
select: jest.fn(),
update: jest.fn(),
destroy: jest.fn(),
}
this.integration.client = () => this.client
2021-03-12 22:29:27 +13:00
}
}
2021-03-17 07:43:56 +13:00
describe("Airtable Integration", () => {
2021-03-12 22:29:27 +13:00
let config
beforeEach(() => {
config = new TestConfiguration()
})
it("calls the create method with the correct params", async () => {
const response = await config.integration.create({
table: "test",
2021-03-16 05:07:04 +13:00
json: {}
2021-03-12 22:29:27 +13:00
})
2021-03-17 07:43:56 +13:00
expect(config.client.create).toHaveBeenCalledWith([
{
fields: {}
}
])
2021-03-12 22:29:27 +13:00
})
2021-03-17 07:43:56 +13:00
it("calls the read method with the correct params", async () => {
const response = await config.integration.read({
table: "test",
view: "Grid view"
})
expect(config.client.select).toHaveBeenCalledWith({
maxRecords: 10, view: "Grid view"
})
2021-03-12 22:29:27 +13:00
})
2021-03-17 07:43:56 +13:00
it("calls the update method with the correct params", async () => {
const response = await config.integration.update({
table: "test",
id: "123",
json: {
name: "test"
}
})
expect(config.client.update).toHaveBeenCalledWith([
{
id: "123",
fields: { name: "test" }
}
])
2021-03-12 22:29:27 +13:00
})
2021-03-17 07:43:56 +13:00
it("calls the delete method with the correct params", async () => {
const ids = [1,2,3,4]
const response = await config.integration.delete({
ids
})
expect(config.client.destroy).toHaveBeenCalledWith(ids)
2021-03-12 22:29:27 +13:00
})
})