migrate deleteRow from runStep to test builder

This commit is contained in:
Peter Clement 2024-11-26 15:48:40 +00:00
parent e8ade0caee
commit b99d411cec
2 changed files with 45 additions and 32 deletions

View File

@ -1,52 +1,65 @@
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
import * as setup from "./utilities" import * as setup from "./utilities"
describe("test the delete row action", () => { describe("test the delete row action", () => {
let table: any let table: any,
let row: any row: any,
let inputs: any config = setup.getConfig()
let config = setup.getConfig()
beforeEach(async () => { beforeAll(async () => {
await config.init() await config.init()
table = await config.createTable() table = await config.createTable()
row = await config.createRow() row = await config.createRow()
inputs = {
tableId: table._id,
id: row._id,
revision: row._rev,
}
}) })
afterAll(setup.afterAll) afterAll(setup.afterAll)
it("should be able to run the action", async () => { it("should be able to run the delete row action", async () => {
const res = await setup.runStep( const builder = createAutomationBuilder({
config, name: "Delete Row Automation",
setup.actions.DELETE_ROW.stepId,
inputs
)
expect(res.success).toEqual(true)
expect(res.response).toBeDefined()
expect(res.row._id).toEqual(row._id)
}) })
it("check usage quota attempts", async () => { await builder
await setup.runInProd(async () => { .appAction({ fields: {} })
await setup.runStep(config, setup.actions.DELETE_ROW.stepId, inputs) .deleteRow({
tableId: table._id,
id: row._id,
revision: row._rev,
})
.run()
await config.api.row.get(table._id, row._id, {
status: 404,
}) })
}) })
it("should check invalid inputs return an error", async () => { it("should check invalid inputs return an error", async () => {
const res = await setup.runStep(config, setup.actions.DELETE_ROW.stepId, {}) const builder = createAutomationBuilder({
expect(res.success).toEqual(false) name: "Invalid Inputs Automation",
})
const results = await builder
.appAction({ fields: {} })
.deleteRow({ tableId: "", id: "", revision: "" })
.run()
expect(results.steps[0].outputs.success).toEqual(false)
}) })
it("should return an error when table doesn't exist", async () => { it("should return an error when table doesn't exist", async () => {
const res = await setup.runStep(config, setup.actions.DELETE_ROW.stepId, { const builder = createAutomationBuilder({
name: "Nonexistent Table Automation",
})
const results = await builder
.appAction({ fields: {} })
.deleteRow({
tableId: "invalid", tableId: "invalid",
id: "invalid", id: "invalid",
revision: "invalid", revision: "invalid",
}) })
expect(res.success).toEqual(false) .run()
expect(results.steps[0].outputs.success).toEqual(false)
}) })
}) })

View File

@ -15,7 +15,7 @@ import * as uuid from "uuid"
describe("test the update row action", () => { describe("test the update row action", () => {
let table: Table, let table: Table,
row: any, row: Row,
config = setup.getConfig() config = setup.getConfig()
beforeAll(async () => { beforeAll(async () => {
@ -34,7 +34,7 @@ describe("test the update row action", () => {
const results = await builder const results = await builder
.appAction({ fields: {} }) .appAction({ fields: {} })
.updateRow({ .updateRow({
rowId: row._id, rowId: row._id!,
row: { row: {
...row, ...row,
name: "Updated name", name: "Updated name",