1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

postgres integration tests

This commit is contained in:
Martin McKeaveney 2021-03-15 16:07:04 +00:00
parent a974da6b0d
commit 53278c2648
5 changed files with 73 additions and 39 deletions

View file

@ -1,13 +1,11 @@
class Airtable {
constructor() {}
constructor() {
this.create = jest.fn()
}
base() {
return () => ({
query: jest.fn(),
create: jest.fn(),
select: jest.fn(),
update: jest.fn(),
destroy: jest.fn(),
create: this.create,
})
}
}

View file

@ -1,20 +1,20 @@
const pg = {}
// constructor
function Client() {}
Client.prototype.query = async function() {
return {
rows: [
{
a: "string",
b: 1,
},
],
}
function Client() {
this.query = jest.fn(() => ({ rows: [] }))
}
Client.prototype.connect = async function() {}
Client.prototype.query = jest.fn(() => ({
rows: [
{
a: "string",
b: 1,
},
],
}))
Client.prototype.connect = jest.fn()
pg.Client = Client

View file

@ -66,7 +66,6 @@ class AirtableIntegration {
constructor(config) {
this.config = config
this.client = new Airtable(config).base(config.base)
console.log(new Airtable().base())
}
async create(query) {

View file

@ -1,7 +1,6 @@
const Airtable = require("airtable")
const { ElectronHttpExecutor } = require("electron-updater/out/electronHttpExecutor")
const { integration } = require("../airtable")
const Airtable = require("airtable")
jest.mock("airtable")
class TestConfiguration {
@ -10,7 +9,7 @@ class TestConfiguration {
}
}
describe("Airtable Integration", () => {
xdescribe("Airtable Integration", () => {
let config
beforeEach(() => {
@ -20,9 +19,10 @@ describe("Airtable Integration", () => {
it("calls the create method with the correct params", async () => {
const response = await config.integration.create({
table: "test",
json: ""
json: {}
})
expect(Airtable.create).toHaveBeenCalledWith({})
console.log(config.integration.client)
expect(config.integration.client.create).toHaveBeenCalledWith({})
})
it("calls the read method with the correct params", () => {

View file

@ -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 sql = "insert into users (name, age) values ('Joe', 123);"
const response = await config.integration.create({
table: "test",
json: ""
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", () => {
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)
})
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 }])
})
})
})