Fix scenarios.spec.ts

This commit is contained in:
Sam Rose 2025-02-03 17:41:16 +00:00
parent da32fcc779
commit a3c4dede60
No known key found for this signature in database
1 changed files with 29 additions and 73 deletions

View File

@ -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: {},
})