From 35942d27b447a5572297553adebbc4d58af397a7 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 17 Jun 2021 15:24:52 +0100 Subject: [PATCH] fix up datasources and server tests --- packages/builder/cypress/support/commands.js | 5 +++-- packages/server/__mocks__/mysql.js | 2 +- packages/server/src/integrations/microsoftSqlServer.js | 8 ++++---- packages/server/src/integrations/mysql.js | 8 ++++---- packages/server/src/integrations/postgres.js | 2 +- .../src/integrations/tests/microsoftSqlServer.spec.js | 4 ++-- packages/server/src/integrations/tests/mysql.spec.js | 8 ++++---- packages/server/src/integrations/tests/postgres.spec.js | 8 ++++---- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 0d87697fdf..670f3fb988 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -37,7 +37,7 @@ Cypress.Commands.add("createApp", name => { cy.contains("Create app").click() }) .then(() => { - cy.get("[data-cy=new-table]", { + cy.contains("Budibase DB", { timeout: 20000, }).should("be.visible") }) @@ -72,7 +72,8 @@ Cypress.Commands.add("createTestTableWithData", () => { Cypress.Commands.add("createTable", tableName => { // Enter table name - cy.get("[data-cy=new-table]").click() + cy.get("Budibase DB") + cy.contains("Create new table").click() cy.get(".spectrum-Modal").within(() => { cy.get("input").first().type(tableName).blur() cy.get(".spectrum-ButtonGroup").contains("Create").click() diff --git a/packages/server/__mocks__/mysql.js b/packages/server/__mocks__/mysql.js index da0126e88b..d382755c50 100644 --- a/packages/server/__mocks__/mysql.js +++ b/packages/server/__mocks__/mysql.js @@ -2,7 +2,7 @@ const mysql = {} const client = { connect: jest.fn(), - query: jest.fn((query, fn) => { + query: jest.fn((query, bindings, fn) => { fn(null, []) }), } diff --git a/packages/server/src/integrations/microsoftSqlServer.js b/packages/server/src/integrations/microsoftSqlServer.js index 488fda94b1..1a916e0424 100644 --- a/packages/server/src/integrations/microsoftSqlServer.js +++ b/packages/server/src/integrations/microsoftSqlServer.js @@ -85,25 +85,25 @@ class SqlServerIntegration extends Sql { async read(query) { await this.connect() - const response = await internalQuery(this.client, query.sql) + const response = await internalQuery(this.client, query) return response.recordset } async create(query) { await this.connect() - const response = await internalQuery(this.client, query.sql) + const response = await internalQuery(this.client, query) return response.recordset || [{ created: true }] } async update(query) { await this.connect() - const response = await internalQuery(this.client, query.sql) + const response = await internalQuery(this.client, query) return response.recordset || [{ updated: true }] } async delete(query) { await this.connect() - const response = await internalQuery(this.client, query.sql) + const response = await internalQuery(this.client, query) return response.recordset || [{ deleted: true }] } diff --git a/packages/server/src/integrations/mysql.js b/packages/server/src/integrations/mysql.js index 0907a83f4c..37971574e2 100644 --- a/packages/server/src/integrations/mysql.js +++ b/packages/server/src/integrations/mysql.js @@ -79,21 +79,21 @@ class MySQLIntegration extends Sql { } async create(query) { - const results = await internalQuery(this.client, query.sql) + const results = await internalQuery(this.client, query) return results.length ? results : [{ created: true }] } read(query) { - return internalQuery(this.client, query.sql) + return internalQuery(this.client, query) } async update(query) { - const results = await internalQuery(this.client, query.sql) + const results = await internalQuery(this.client, query) return results.length ? results : [{ updated: true }] } async delete(query) { - const results = await internalQuery(this.client, query.sql) + const results = await internalQuery(this.client, query) return results.length ? results : [{ deleted: true }] } diff --git a/packages/server/src/integrations/postgres.js b/packages/server/src/integrations/postgres.js index 2458afa333..a7148e335c 100644 --- a/packages/server/src/integrations/postgres.js +++ b/packages/server/src/integrations/postgres.js @@ -168,7 +168,7 @@ class PostgresIntegration extends Sql { return response.rows.length ? response.rows : [{ updated: true }] } - async delete({ sql }) { + async delete(sql) { const response = await internalQuery(this.client, sql) return response.rows.length ? response.rows : [{ deleted: true }] } diff --git a/packages/server/src/integrations/tests/microsoftSqlServer.spec.js b/packages/server/src/integrations/tests/microsoftSqlServer.spec.js index 5d7d59a647..af65fcbec4 100644 --- a/packages/server/src/integrations/tests/microsoftSqlServer.spec.js +++ b/packages/server/src/integrations/tests/microsoftSqlServer.spec.js @@ -20,7 +20,7 @@ describe("MS SQL Server Integration", () => { const response = await config.integration.create({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined) }) it("calls the read method with the correct params", async () => { @@ -28,7 +28,7 @@ describe("MS SQL Server Integration", () => { const response = await config.integration.read({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined) }) describe("no rows returned", () => { diff --git a/packages/server/src/integrations/tests/mysql.spec.js b/packages/server/src/integrations/tests/mysql.spec.js index 71b828a4e6..6d6d00dd67 100644 --- a/packages/server/src/integrations/tests/mysql.spec.js +++ b/packages/server/src/integrations/tests/mysql.spec.js @@ -19,7 +19,7 @@ describe("MySQL Integration", () => { await config.integration.create({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function)) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function)) }) it("calls the read method with the correct params", async () => { @@ -27,7 +27,7 @@ describe("MySQL Integration", () => { await config.integration.read({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function)) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function)) }) it("calls the update method with the correct params", async () => { @@ -35,7 +35,7 @@ describe("MySQL Integration", () => { await config.integration.update({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function)) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function)) }) it("calls the delete method with the correct params", async () => { @@ -43,7 +43,7 @@ describe("MySQL Integration", () => { await config.integration.delete({ sql }) - expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function)) + expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function)) }) describe("no rows returned", () => { diff --git a/packages/server/src/integrations/tests/postgres.spec.js b/packages/server/src/integrations/tests/postgres.spec.js index dc34fcf6bb..d0d579f32d 100644 --- a/packages/server/src/integrations/tests/postgres.spec.js +++ b/packages/server/src/integrations/tests/postgres.spec.js @@ -20,7 +20,7 @@ describe("Postgres Integration", () => { const response = await config.integration.create({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql) + expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined) }) it("calls the read method with the correct params", async () => { @@ -28,7 +28,7 @@ describe("Postgres Integration", () => { const response = await config.integration.read({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql) + expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined) }) it("calls the update method with the correct params", async () => { @@ -36,7 +36,7 @@ describe("Postgres Integration", () => { const response = await config.integration.update({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql) + expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined) }) it("calls the delete method with the correct params", async () => { @@ -44,7 +44,7 @@ describe("Postgres Integration", () => { await config.integration.delete({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql) + expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined) }) describe("no rows returned", () => {