couchDB tests
This commit is contained in:
parent
53278c2648
commit
813ea1ede8
|
@ -0,0 +1,10 @@
|
|||
const mysql = {}
|
||||
|
||||
const client = {
|
||||
connect: jest.fn(),
|
||||
query: jest.fn((sql, cb) => cb),
|
||||
}
|
||||
|
||||
mysql.createConnection = jest.fn(() => client)
|
||||
|
||||
module.exports = mysql
|
|
@ -1,9 +1,7 @@
|
|||
const pg = {}
|
||||
|
||||
// constructor
|
||||
function Client() {
|
||||
this.query = jest.fn(() => ({ rows: [] }))
|
||||
}
|
||||
function Client() {}
|
||||
|
||||
Client.prototype.query = jest.fn(() => ({
|
||||
rows: [
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
function CouchDB() {
|
||||
this.post = jest.fn()
|
||||
this.allDocs = jest.fn(() => ({ rows: [] }))
|
||||
this.put = jest.fn()
|
||||
this.remove = jest.fn()
|
||||
}
|
||||
|
||||
module.exports = CouchDB
|
|
@ -0,0 +1,61 @@
|
|||
const PouchDB = require("pouchdb")
|
||||
const CouchDBIntegration = require("../couchdb")
|
||||
jest.mock("pouchdb")
|
||||
|
||||
class TestConfiguration {
|
||||
constructor(config = {}) {
|
||||
this.integration = new CouchDBIntegration.integration(config)
|
||||
}
|
||||
}
|
||||
|
||||
describe("CouchDB Integration", () => {
|
||||
let config
|
||||
|
||||
beforeEach(() => {
|
||||
config = new TestConfiguration()
|
||||
})
|
||||
|
||||
it("calls the create method with the correct params", async () => {
|
||||
const doc = {
|
||||
test: 1
|
||||
}
|
||||
const response = await config.integration.create({
|
||||
json: doc
|
||||
})
|
||||
expect(config.integration.client.post).toHaveBeenCalledWith(doc)
|
||||
})
|
||||
|
||||
it("calls the read method with the correct params", async () => {
|
||||
const doc = {
|
||||
name: "search"
|
||||
}
|
||||
|
||||
const response = await config.integration.read({
|
||||
json: doc
|
||||
})
|
||||
|
||||
expect(config.integration.client.allDocs).toHaveBeenCalledWith({
|
||||
include_docs: true,
|
||||
name: "search"
|
||||
})
|
||||
})
|
||||
|
||||
it("calls the update method with the correct params", async () => {
|
||||
const doc = {
|
||||
_id: "1234",
|
||||
name: "search"
|
||||
}
|
||||
|
||||
const response = await config.integration.update({
|
||||
json: doc
|
||||
})
|
||||
|
||||
expect(config.integration.client.put).toHaveBeenCalledWith(doc)
|
||||
})
|
||||
|
||||
it("calls the delete method with the correct params", async () => {
|
||||
const id = "1234"
|
||||
const response = await config.integration.delete({ id })
|
||||
expect(config.integration.client.remove).toHaveBeenCalledWith(id)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,75 @@
|
|||
const pg = require("mysql")
|
||||
const MySQLIntegration = require("../mysql")
|
||||
jest.mock("mysql")
|
||||
|
||||
class TestConfiguration {
|
||||
constructor(config = { ssl: {} }) {
|
||||
this.integration = new MySQLIntegration.integration(config)
|
||||
}
|
||||
}
|
||||
|
||||
describe("MySQL Integration", () => {
|
||||
let config
|
||||
|
||||
beforeEach(() => {
|
||||
config = new TestConfiguration()
|
||||
})
|
||||
|
||||
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({
|
||||
sql
|
||||
})
|
||||
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
|
||||
})
|
||||
|
||||
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", 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)
|
||||
})
|
||||
|
||||
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 }])
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const pg = require("pg")
|
||||
const PostgresIntegration = require("../postgres")
|
||||
jest.mock("pg")
|
||||
|
@ -49,6 +48,10 @@ describe("Postgres Integration", () => {
|
|||
})
|
||||
|
||||
describe("no rows returned", () => {
|
||||
beforeEach(() => {
|
||||
config.integration.client.query.mockImplementation(() => ({ rows: [] }))
|
||||
})
|
||||
|
||||
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({
|
||||
|
|
Loading…
Reference in New Issue