From 0d3ab9ae332f605f02cbfdeddc47a4fa1b31065f Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Fri, 13 May 2022 15:56:02 +0100 Subject: [PATCH] Fix test for update --- .../src/integrations/tests/mongo.spec.js | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/server/src/integrations/tests/mongo.spec.js b/packages/server/src/integrations/tests/mongo.spec.js index 430ccc1c3a..1260491796 100644 --- a/packages/server/src/integrations/tests/mongo.spec.js +++ b/packages/server/src/integrations/tests/mongo.spec.js @@ -4,19 +4,19 @@ jest.mock("mongodb") class TestConfiguration { constructor(config = {}) { - this.integration = new MongoDBIntegration.integration(config) + this.integration = new MongoDBIntegration.integration(config) } } function disableConsole() { - jest.spyOn(console, 'error'); - console.error.mockImplementation(() => {}); + jest.spyOn(console, "error") + console.error.mockImplementation(() => {}) - return console.error.mockRestore; + return console.error.mockRestore } describe("MongoDB Integration", () => { - let config + let config let indexName = "Users" beforeEach(() => { @@ -25,12 +25,12 @@ describe("MongoDB Integration", () => { it("calls the create method with the correct params", async () => { const body = { - name: "Hello" + name: "Hello", } await config.integration.create({ index: indexName, json: body, - extra: { collection: 'testCollection', actionTypes: 'insertOne'} + extra: { collection: "testCollection", actionTypes: "insertOne" }, }) expect(config.integration.client.insertOne).toHaveBeenCalledWith(body) }) @@ -38,9 +38,9 @@ describe("MongoDB Integration", () => { it("calls the read method with the correct params", async () => { const query = { json: { - address: "test" + address: "test", }, - extra: { collection: 'testCollection', actionTypes: 'find'} + extra: { collection: "testCollection", actionTypes: "find" }, } const response = await config.integration.read(query) 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 () => { const query = { json: { - id: "test" + id: "test", }, - extra: { collection: 'testCollection', actionTypes: 'deleteOne'} + extra: { collection: "testCollection", actionTypes: "deleteOne" }, } await config.integration.delete(query) 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 () => { const query = { json: { - id: "test" + filter: { + id: "test", + }, + update: { + name: "TestName", + }, + options: { + upsert: false, + }, }, - extra: { collection: 'testCollection', actionTypes: 'updateOne'} + extra: { collection: "testCollection", actionTypes: "updateOne" }, } 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 () => { const restore = disableConsole() const query = { - extra: { collection: 'testCollection', actionTypes: 'deleteOne'} + extra: { collection: "testCollection", actionTypes: "deleteOne" }, } let error = null @@ -85,4 +97,4 @@ describe("MongoDB Integration", () => { expect(error).toBeDefined() restore() }) -}) \ No newline at end of file +})