From d0f4d573d6bb0b111189f102a7ea09487b235374 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 16 Sep 2021 12:43:08 +0100 Subject: [PATCH] Adding test case for new query rows step. --- packages/server/package.json | 3 +- .../src/automations/tests/queryRows.spec.js | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/automations/tests/queryRows.spec.js diff --git a/packages/server/package.json b/packages/server/package.json index c564e00d6e..f805fea051 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -49,7 +49,8 @@ "!src/automations/tests/**/*", "!src/utilities/fileProcessor.js", "!src/utilities/fileSystem/**/*", - "!src/utilities/redis.js" + "!src/utilities/redis.js", + "!src/api/controllers/row/internalSearch.js" ], "coverageReporters": [ "lcov", diff --git a/packages/server/src/automations/tests/queryRows.spec.js b/packages/server/src/automations/tests/queryRows.spec.js new file mode 100644 index 0000000000..fca03f4e3b --- /dev/null +++ b/packages/server/src/automations/tests/queryRows.spec.js @@ -0,0 +1,51 @@ +// lucene searching not supported in test due to use of PouchDB +let rows = [] +jest.mock("../../api/controllers/row/internalSearch", () => ({ + fullSearch: jest.fn(() => { + return { + rows, + } + }), + paginatedSearch: jest.fn(), +})) +const setup = require("./utilities") + +const NAME = "Test" + +describe("Test a query step automation", () => { + let table + let config = setup.getConfig() + + beforeEach(async () => { + await config.init() + table = await config.createTable() + const row = { + name: NAME, + description: "original description", + tableId: table._id, + } + rows.push(await config.createRow(row)) + rows.push(await config.createRow(row)) + }) + + afterAll(setup.afterAll) + + it("should be able to run the query step", async () => { + const inputs = { + tableId: table._id, + filters: { + equal: { + name: NAME, + }, + }, + sortColumn: "name", + sortOrder: "ascending", + limit: 10, + } + const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs) + expect(res.success).toBe(true) + expect(res.rows).toBeDefined() + expect(res.rows.length).toBe(2) + expect(res.rows[0].name).toBe(NAME) + }) +}) \ No newline at end of file