|
|
|
@ -1,16 +1,15 @@ |
|
|
|
|
|
|
|
const Airtable = require("airtable") |
|
|
|
const { ElectronHttpExecutor } = require("electron-updater/out/electronHttpExecutor") |
|
|
|
const AirtableIntegration = require("../airtable") |
|
|
|
jest.mock("airtable") |
|
|
|
const pg = require("pg") |
|
|
|
const PostgresIntegration = require("../postgres") |
|
|
|
jest.mock("pg") |
|
|
|
|
|
|
|
class TestConfiguration { |
|
|
|
constructor(config = {}) { |
|
|
|
this.integration = new AirtableIntegration.integration(config) |
|
|
|
this.integration = new PostgresIntegration.integration(config) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("Airtable Integration", () => { |
|
|
|
describe("Postgres Integration", () => { |
|
|
|
let config |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
@ -18,22 +17,60 @@ describe("Airtable Integration", () => { |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the create method with the correct params", async () => { |
|
|
|
const response = await config.integration.create({ |
|
|
|
table: "test", |
|
|
|
json: "" |
|
|
|
const sql = "insert into users (name, age) values ('Joe', 123);" |
|
|
|
const response = await config.integration.create({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(config.integration.client.create).toHaveBeenCalledWith({}) |
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the read method with the correct params", () => { |
|
|
|
|
|
|
|
it("calls the read method with the correct params", async () => { |
|
|
|
const sql = "select * from users;" |
|
|
|
const response = await config.integration.read({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the update method with the correct params", () => { |
|
|
|
it("calls the update method with the correct params", async () => { |
|
|
|
const sql = "update table users set name = 'test';" |
|
|
|
const response = await config.integration.update({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the delete method with the correct params", async () => { |
|
|
|
const sql = "delete from users where name = 'todelete';" |
|
|
|
const response = await config.integration.delete({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(config.integration.client.query).toHaveBeenCalledWith(sql) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the delete method with the correct params", () => { |
|
|
|
describe("no rows returned", () => { |
|
|
|
it("returns the correct response when the create response has no rows", async () => { |
|
|
|
const sql = "insert into users (name, age) values ('Joe', 123);" |
|
|
|
const response = await config.integration.create({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(response).toEqual([{ created: true }]) |
|
|
|
}) |
|
|
|
|
|
|
|
it("returns the correct response when the update response has no rows", async () => { |
|
|
|
const sql = "update table users set name = 'test';" |
|
|
|
const response = await config.integration.update({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(response).toEqual([{ updated: true }]) |
|
|
|
}) |
|
|
|
|
|
|
|
it("returns the correct response when the delete response has no rows", async () => { |
|
|
|
const sql = "delete from users where name = 'todelete';" |
|
|
|
const response = await config.integration.delete({ |
|
|
|
sql |
|
|
|
}) |
|
|
|
expect(response).toEqual([{ deleted: true }]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |