From a3c4dede60ad0a8ecbbf774ce35e82c908784b0f Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 3 Feb 2025 17:41:16 +0000 Subject: [PATCH] Fix scenarios.spec.ts --- .../src/automations/tests/scenarios.spec.ts | 102 +++++------------- 1 file changed, 29 insertions(+), 73 deletions(-) diff --git a/packages/server/src/automations/tests/scenarios.spec.ts b/packages/server/src/automations/tests/scenarios.spec.ts index 55cfb61337..8d6e051ce2 100644 --- a/packages/server/src/automations/tests/scenarios.spec.ts +++ b/packages/server/src/automations/tests/scenarios.spec.ts @@ -9,6 +9,7 @@ import { Knex } from "knex" import { generator } from "@budibase/backend-core/tests" import { automations } from "@budibase/shared-core" import TestConfiguration from "../../tests/utilities/TestConfiguration" +import { basicTable } from "../../tests/utilities/structures" const FilterConditions = automations.steps.filter.FilterConditions @@ -26,13 +27,9 @@ describe("Automation Scenarios", () => { describe("Row Automations", () => { it("should trigger an automation which then creates a row", async () => { - const table = await config.createTable() + const table = await config.api.table.save(basicTable()) - const builder = createAutomationBuilder({ - name: "Test Row Save and Create", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .rowUpdated( { tableId: table._id! }, { @@ -61,19 +58,14 @@ describe("Automation Scenarios", () => { }) it("should trigger an automation which queries the database", async () => { - const table = await config.createTable() + const table = await config.api.table.save(basicTable()) const row = { name: "Test Row", description: "original description", - tableId: table._id, } - await config.createRow(row) - await config.createRow(row) - const builder = createAutomationBuilder({ - name: "Test Row Save and Create", - }) - - const results = await builder + await config.api.row.save(table._id!, row) + await config.api.row.save(table._id!, row) + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .queryRows({ tableId: table._id!, @@ -85,19 +77,14 @@ describe("Automation Scenarios", () => { }) it("should trigger an automation which queries the database then deletes a row", async () => { - const table = await config.createTable() + const table = await config.api.table.save(basicTable()) const row = { name: "DFN", description: "original description", - tableId: table._id, } - await config.createRow(row) - await config.createRow(row) - const builder = createAutomationBuilder({ - name: "Test Row Save and Create", - }) - - const results = await builder + await config.api.row.save(table._id!, row) + await config.api.row.save(table._id!, row) + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .queryRows({ tableId: table._id!, @@ -117,7 +104,8 @@ describe("Automation Scenarios", () => { }) it("should trigger an automation which creates and then updates a row", async () => { - const table = await config.createTable({ + const table = await config.api.table.save({ + ...basicTable(), name: "TestTable", type: "table", schema: { @@ -138,11 +126,7 @@ describe("Automation Scenarios", () => { }, }) - const builder = createAutomationBuilder({ - name: "Test Create and Update Row", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .createRow( { @@ -204,19 +188,14 @@ describe("Automation Scenarios", () => { describe("Name Based Automations", () => { it("should fetch and delete a rpw using automation naming", async () => { - const table = await config.createTable() + const table = await config.api.table.save(basicTable()) const row = { name: "DFN", description: "original description", - tableId: table._id, } - await config.createRow(row) - await config.createRow(row) - const builder = createAutomationBuilder({ - name: "Test Query and Delete Row", - }) - - const results = await builder + await config.api.row.save(table._id!, row) + await config.api.row.save(table._id!, row) + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .queryRows( { @@ -242,7 +221,8 @@ describe("Automation Scenarios", () => { let table: Table beforeEach(async () => { - table = await config.createTable({ + table = await config.api.table.save({ + ...basicTable(), name: "TestTable", type: "table", schema: { @@ -265,11 +245,7 @@ describe("Automation Scenarios", () => { }) it("should stop an automation if the condition is not met", async () => { - const builder = createAutomationBuilder({ - name: "Test Equal", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .createRow({ row: { @@ -295,11 +271,7 @@ describe("Automation Scenarios", () => { }) it("should continue the automation if the condition is met", async () => { - const builder = createAutomationBuilder({ - name: "Test Not Equal", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .createRow({ row: { @@ -366,11 +338,7 @@ describe("Automation Scenarios", () => { it.each(testCases)( "should pass the filter when condition is $condition", async ({ condition, value, rowValue, expectPass }) => { - const builder = createAutomationBuilder({ - name: `Test ${condition}`, - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .createRow({ row: { @@ -403,13 +371,9 @@ describe("Automation Scenarios", () => { }) it("Check user is passed through from row trigger", async () => { - const table = await config.createTable() + const table = await config.api.table.save(basicTable()) - const builder = createAutomationBuilder({ - name: "Test a user is successfully passed from the trigger", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .rowUpdated( { tableId: table._id! }, { @@ -424,11 +388,7 @@ describe("Automation Scenarios", () => { }) it("Check user is passed through from app trigger", async () => { - const builder = createAutomationBuilder({ - name: "Test a user is successfully passed from the trigger", - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {} }) .serverLog({ text: "{{ [user].[email] }}" }) .run() @@ -451,7 +411,8 @@ if (descriptions.length) { }) it("should query an external database for some data then insert than into an internal table", async () => { - const newTable = await config.createTable({ + const newTable = await config.api.table.save({ + ...basicTable(), name: "table", type: "table", schema: { @@ -499,12 +460,7 @@ if (descriptions.length) { queryVerb: "read", }) - const builder = createAutomationBuilder({ - name: "Test external query and save", - config, - }) - - const results = await builder + const results = await createAutomationBuilder({ config }) .appAction({ fields: {}, })