Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
1.7 KiB

jest.mock("pouchdb", () => function CouchDBMock() {
this.post = jest.fn()
this.allDocs = jest.fn(() => ({ rows: [] }))
this.put = jest.fn()
this.get = jest.fn()
this.remove = jest.fn()
this.plugin = jest.fn()
this.close = jest.fn()
})
const CouchDBIntegration = require("../couchdb")
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.get).toHaveBeenCalledWith(id)
expect(config.integration.client.remove).toHaveBeenCalled()
})
})