Fix scenarios.spec.ts
This commit is contained in:
parent
da32fcc779
commit
a3c4dede60
|
@ -9,6 +9,7 @@ import { Knex } from "knex"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { automations } from "@budibase/shared-core"
|
import { automations } from "@budibase/shared-core"
|
||||||
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
||||||
|
import { basicTable } from "../../tests/utilities/structures"
|
||||||
|
|
||||||
const FilterConditions = automations.steps.filter.FilterConditions
|
const FilterConditions = automations.steps.filter.FilterConditions
|
||||||
|
|
||||||
|
@ -26,13 +27,9 @@ describe("Automation Scenarios", () => {
|
||||||
|
|
||||||
describe("Row Automations", () => {
|
describe("Row Automations", () => {
|
||||||
it("should trigger an automation which then creates a row", async () => {
|
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({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Row Save and Create",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.rowUpdated(
|
.rowUpdated(
|
||||||
{ tableId: table._id! },
|
{ tableId: table._id! },
|
||||||
{
|
{
|
||||||
|
@ -61,19 +58,14 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should trigger an automation which queries the database", async () => {
|
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 = {
|
const row = {
|
||||||
name: "Test Row",
|
name: "Test Row",
|
||||||
description: "original description",
|
description: "original description",
|
||||||
tableId: table._id,
|
|
||||||
}
|
}
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Row Save and Create",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.queryRows({
|
.queryRows({
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
|
@ -85,19 +77,14 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should trigger an automation which queries the database then deletes a row", async () => {
|
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 = {
|
const row = {
|
||||||
name: "DFN",
|
name: "DFN",
|
||||||
description: "original description",
|
description: "original description",
|
||||||
tableId: table._id,
|
|
||||||
}
|
}
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Row Save and Create",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.queryRows({
|
.queryRows({
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
|
@ -117,7 +104,8 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should trigger an automation which creates and then updates a row", async () => {
|
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",
|
name: "TestTable",
|
||||||
type: "table",
|
type: "table",
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -138,11 +126,7 @@ describe("Automation Scenarios", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Create and Update Row",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.createRow(
|
.createRow(
|
||||||
{
|
{
|
||||||
|
@ -204,19 +188,14 @@ describe("Automation Scenarios", () => {
|
||||||
|
|
||||||
describe("Name Based Automations", () => {
|
describe("Name Based Automations", () => {
|
||||||
it("should fetch and delete a rpw using automation naming", async () => {
|
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 = {
|
const row = {
|
||||||
name: "DFN",
|
name: "DFN",
|
||||||
description: "original description",
|
description: "original description",
|
||||||
tableId: table._id,
|
|
||||||
}
|
}
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
await config.createRow(row)
|
await config.api.row.save(table._id!, row)
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Query and Delete Row",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.queryRows(
|
.queryRows(
|
||||||
{
|
{
|
||||||
|
@ -242,7 +221,8 @@ describe("Automation Scenarios", () => {
|
||||||
let table: Table
|
let table: Table
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
table = await config.createTable({
|
table = await config.api.table.save({
|
||||||
|
...basicTable(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
type: "table",
|
type: "table",
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -265,11 +245,7 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should stop an automation if the condition is not met", async () => {
|
it("should stop an automation if the condition is not met", async () => {
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Equal",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.createRow({
|
.createRow({
|
||||||
row: {
|
row: {
|
||||||
|
@ -295,11 +271,7 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should continue the automation if the condition is met", async () => {
|
it("should continue the automation if the condition is met", async () => {
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test Not Equal",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.createRow({
|
.createRow({
|
||||||
row: {
|
row: {
|
||||||
|
@ -366,11 +338,7 @@ describe("Automation Scenarios", () => {
|
||||||
it.each(testCases)(
|
it.each(testCases)(
|
||||||
"should pass the filter when condition is $condition",
|
"should pass the filter when condition is $condition",
|
||||||
async ({ condition, value, rowValue, expectPass }) => {
|
async ({ condition, value, rowValue, expectPass }) => {
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: `Test ${condition}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.createRow({
|
.createRow({
|
||||||
row: {
|
row: {
|
||||||
|
@ -403,13 +371,9 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Check user is passed through from row trigger", async () => {
|
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({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test a user is successfully passed from the trigger",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.rowUpdated(
|
.rowUpdated(
|
||||||
{ tableId: table._id! },
|
{ tableId: table._id! },
|
||||||
{
|
{
|
||||||
|
@ -424,11 +388,7 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Check user is passed through from app trigger", async () => {
|
it("Check user is passed through from app trigger", async () => {
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test a user is successfully passed from the trigger",
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({ fields: {} })
|
.appAction({ fields: {} })
|
||||||
.serverLog({ text: "{{ [user].[email] }}" })
|
.serverLog({ text: "{{ [user].[email] }}" })
|
||||||
.run()
|
.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 () => {
|
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",
|
name: "table",
|
||||||
type: "table",
|
type: "table",
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -499,12 +460,7 @@ if (descriptions.length) {
|
||||||
queryVerb: "read",
|
queryVerb: "read",
|
||||||
})
|
})
|
||||||
|
|
||||||
const builder = createAutomationBuilder({
|
const results = await createAutomationBuilder({ config })
|
||||||
name: "Test external query and save",
|
|
||||||
config,
|
|
||||||
})
|
|
||||||
|
|
||||||
const results = await builder
|
|
||||||
.appAction({
|
.appAction({
|
||||||
fields: {},
|
fields: {},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue