From a78230e23b1c894115509ec1669c3e1c3c285ce5 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 9 Nov 2021 11:16:12 +0000 Subject: [PATCH] Reworking MS-SQL test case to be able to get the sql now with a request being made for each internal query, rather than just at connection. --- packages/server/__mocks__/mssql.ts | 2 +- .../tests/microsoftSqlServer.spec.js | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/server/__mocks__/mssql.ts b/packages/server/__mocks__/mssql.ts index 8a63f3f944..90185f4eef 100644 --- a/packages/server/__mocks__/mssql.ts +++ b/packages/server/__mocks__/mssql.ts @@ -15,7 +15,7 @@ module MsSqlMock { mssql.ConnectionPool = jest.fn(() => ({ connect: jest.fn(() => ({ request: jest.fn(() => ({ - query: jest.fn(() => ({})), + query: jest.fn(sql => ({ recordset: [ sql ] })), })), })), })) diff --git a/packages/server/src/integrations/tests/microsoftSqlServer.spec.js b/packages/server/src/integrations/tests/microsoftSqlServer.spec.js index 7784982ca1..19a99ad54b 100644 --- a/packages/server/src/integrations/tests/microsoftSqlServer.spec.js +++ b/packages/server/src/integrations/tests/microsoftSqlServer.spec.js @@ -9,32 +9,39 @@ class TestConfiguration { } describe("MS SQL Server Integration", () => { - let config + let config - beforeEach(() => { + beforeEach(async () => { 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 + describe("check sql used", () => { + beforeEach(async () => { + await config.integration.connect() }) - 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 + 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.request).toHaveBeenCalledWith() + expect(response[0]).toEqual(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.request).toHaveBeenCalledWith() + expect(response[0]).toEqual(sql) }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql, {}) }) describe("no rows returned", () => { beforeEach(async () => { await config.integration.connect() - config.integration.client.query.mockImplementation(() => ({ rows: [] })) }) it("returns the correct response when the create response has no rows", async () => { @@ -42,7 +49,7 @@ describe("MS SQL Server Integration", () => { const response = await config.integration.create({ sql }) - expect(response).toEqual([{ created: true }]) + expect(response[0]).toEqual(sql) }) }) }) \ No newline at end of file