Fix test for update

This commit is contained in:
Mel O'Hagan 2022-05-13 15:56:02 +01:00 committed by mike12345567
parent c2fc1598fa
commit 0d3ab9ae33
1 changed files with 28 additions and 16 deletions

View File

@ -9,10 +9,10 @@ class TestConfiguration {
} }
function disableConsole() { function disableConsole() {
jest.spyOn(console, 'error'); jest.spyOn(console, "error")
console.error.mockImplementation(() => {}); console.error.mockImplementation(() => {})
return console.error.mockRestore; return console.error.mockRestore
} }
describe("MongoDB Integration", () => { describe("MongoDB Integration", () => {
@ -25,12 +25,12 @@ describe("MongoDB Integration", () => {
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const body = { const body = {
name: "Hello" name: "Hello",
} }
await config.integration.create({ await config.integration.create({
index: indexName, index: indexName,
json: body, json: body,
extra: { collection: 'testCollection', actionTypes: 'insertOne'} extra: { collection: "testCollection", actionTypes: "insertOne" },
}) })
expect(config.integration.client.insertOne).toHaveBeenCalledWith(body) expect(config.integration.client.insertOne).toHaveBeenCalledWith(body)
}) })
@ -38,9 +38,9 @@ describe("MongoDB Integration", () => {
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const query = { const query = {
json: { json: {
address: "test" address: "test",
}, },
extra: { collection: 'testCollection', actionTypes: 'find'} extra: { collection: "testCollection", actionTypes: "find" },
} }
const response = await config.integration.read(query) const response = await config.integration.read(query)
expect(config.integration.client.find).toHaveBeenCalledWith(query.json) expect(config.integration.client.find).toHaveBeenCalledWith(query.json)
@ -50,9 +50,9 @@ describe("MongoDB Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const query = { const query = {
json: { json: {
id: "test" id: "test",
}, },
extra: { collection: 'testCollection', actionTypes: 'deleteOne'} extra: { collection: "testCollection", actionTypes: "deleteOne" },
} }
await config.integration.delete(query) await config.integration.delete(query)
expect(config.integration.client.deleteOne).toHaveBeenCalledWith(query.json) expect(config.integration.client.deleteOne).toHaveBeenCalledWith(query.json)
@ -61,19 +61,31 @@ describe("MongoDB Integration", () => {
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const query = { const query = {
json: { json: {
id: "test" filter: {
id: "test",
}, },
extra: { collection: 'testCollection', actionTypes: 'updateOne'} update: {
name: "TestName",
},
options: {
upsert: false,
},
},
extra: { collection: "testCollection", actionTypes: "updateOne" },
} }
await config.integration.update(query) await config.integration.update(query)
expect(config.integration.client.updateOne).toHaveBeenCalledWith(query.json) expect(config.integration.client.updateOne).toHaveBeenCalledWith(
query.json.filter,
query.json.update,
query.json.options
)
}) })
it("throws an error when an invalid query.extra.actionType is passed for each method", async () => { it("throws an error when an invalid query.extra.actionType is passed for each method", async () => {
const restore = disableConsole() const restore = disableConsole()
const query = { const query = {
extra: { collection: 'testCollection', actionTypes: 'deleteOne'} extra: { collection: "testCollection", actionTypes: "deleteOne" },
} }
let error = null let error = null