migrate createrow step to use test builder
This commit is contained in:
parent
b99d411cec
commit
685657b8eb
|
@ -1,6 +1,7 @@
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { basicTableWithAttachmentField } from "../../tests/utilities/structures"
|
import { basicTableWithAttachmentField } from "../../tests/utilities/structures"
|
||||||
import { objectStore } from "@budibase/backend-core"
|
import { objectStore } from "@budibase/backend-core"
|
||||||
|
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
|
||||||
|
|
||||||
async function uploadTestFile(filename: string) {
|
async function uploadTestFile(filename: string) {
|
||||||
let bucket = "testbucket"
|
let bucket = "testbucket"
|
||||||
|
@ -13,6 +14,7 @@ async function uploadTestFile(filename: string) {
|
||||||
|
|
||||||
return presignedUrl
|
return presignedUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("test the create row action", () => {
|
describe("test the create row action", () => {
|
||||||
let table: any
|
let table: any
|
||||||
let row: any
|
let row: any
|
||||||
|
@ -31,30 +33,78 @@ describe("test the create row action", () => {
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
const result = await createAutomationBuilder({
|
||||||
row,
|
name: "Test Create Row Flow",
|
||||||
|
appId: config.getAppId(),
|
||||||
|
config,
|
||||||
})
|
})
|
||||||
expect(res.id).toBeDefined()
|
.appAction({ fields: { status: "new" } })
|
||||||
expect(res.revision).toBeDefined()
|
.serverLog({ text: "Starting create row flow" }, { stepName: "StartLog" })
|
||||||
expect(res.success).toEqual(true)
|
.createRow({ row }, { stepName: "CreateRow" })
|
||||||
const gottenRow = await config.api.row.get(table._id, res.id)
|
.serverLog(
|
||||||
|
{ text: "Row created with ID: {{ stepsByName.CreateRow.row._id }}" },
|
||||||
|
{ stepName: "CreationLog" }
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
|
||||||
|
expect(result.steps[1].outputs.success).toBeDefined()
|
||||||
|
expect(result.steps[1].outputs.id).toBeDefined()
|
||||||
|
expect(result.steps[1].outputs.revision).toBeDefined()
|
||||||
|
const gottenRow = await config.api.row.get(
|
||||||
|
table._id,
|
||||||
|
result.steps[1].outputs.id
|
||||||
|
)
|
||||||
expect(gottenRow.name).toEqual("test")
|
expect(gottenRow.name).toEqual("test")
|
||||||
expect(gottenRow.description).toEqual("test")
|
expect(gottenRow.description).toEqual("test")
|
||||||
|
expect(result.steps[2].outputs.message).toContain(
|
||||||
|
"Row created with ID: " + result.steps[1].outputs.id
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return an error (not throw) when bad info provided", async () => {
|
it("should return an error (not throw) when bad info provided", async () => {
|
||||||
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
const result = await createAutomationBuilder({
|
||||||
row: {
|
name: "Test Create Row Error Flow",
|
||||||
tableId: "invalid",
|
appId: config.getAppId(),
|
||||||
invalid: "invalid",
|
config,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
expect(res.success).toEqual(false)
|
.appAction({ fields: { status: "error" } })
|
||||||
|
.serverLog({ text: "Starting error test flow" }, { stepName: "StartLog" })
|
||||||
|
.createRow(
|
||||||
|
{
|
||||||
|
row: {
|
||||||
|
tableId: "invalid",
|
||||||
|
invalid: "invalid",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ stepName: "CreateRow" }
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
|
||||||
|
expect(result.steps[1].outputs.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
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.CREATE_ROW.stepId, {})
|
const result = await createAutomationBuilder({
|
||||||
expect(res.success).toEqual(false)
|
name: "Test Create Row Invalid Flow",
|
||||||
|
appId: config.getAppId(),
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
.appAction({ fields: { status: "invalid" } })
|
||||||
|
.serverLog({ text: "Testing invalid input" }, { stepName: "StartLog" })
|
||||||
|
.createRow({ row: {} }, { stepName: "CreateRow" })
|
||||||
|
.filter({
|
||||||
|
field: "{{ stepsByName.CreateRow.success }}",
|
||||||
|
condition: "equal",
|
||||||
|
value: true,
|
||||||
|
})
|
||||||
|
.serverLog(
|
||||||
|
{ text: "This log should not appear" },
|
||||||
|
{ stepName: "SkippedLog" }
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
|
||||||
|
expect(result.steps[1].outputs.success).toEqual(false)
|
||||||
|
expect(result.steps.length).toBeLessThan(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should check that an attachment field is sent to storage and parsed", async () => {
|
it("should check that an attachment field is sent to storage and parsed", async () => {
|
||||||
|
@ -76,13 +126,33 @@ describe("test the create row action", () => {
|
||||||
]
|
]
|
||||||
|
|
||||||
attachmentRow.file_attachment = attachmentObject
|
attachmentRow.file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
const result = await createAutomationBuilder({
|
||||||
row: attachmentRow,
|
name: "Test Create Row Attachment Flow",
|
||||||
|
appId: config.getAppId(),
|
||||||
|
config,
|
||||||
})
|
})
|
||||||
|
.appAction({ fields: { type: "attachment" } })
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Processing attachment upload" },
|
||||||
|
{ stepName: "StartLog" }
|
||||||
|
)
|
||||||
|
.createRow({ row: attachmentRow }, { stepName: "CreateRow" })
|
||||||
|
.filter({
|
||||||
|
field: "{{ stepsByName.CreateRow.success }}",
|
||||||
|
condition: "equal",
|
||||||
|
value: true,
|
||||||
|
})
|
||||||
|
.serverLog(
|
||||||
|
{
|
||||||
|
text: "Attachment uploaded with key: {{ stepsByName.CreateRow.row.file_attachment.0.key }}",
|
||||||
|
},
|
||||||
|
{ stepName: "UploadLog" }
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
|
||||||
expect(res.success).toEqual(true)
|
expect(result.steps[1].outputs.success).toEqual(true)
|
||||||
expect(res.row.file_attachment[0]).toHaveProperty("key")
|
expect(result.steps[1].outputs.row.file_attachment[0]).toHaveProperty("key")
|
||||||
let s3Key = res.row.file_attachment[0].key
|
let s3Key = result.steps[1].outputs.row.file_attachment[0].key
|
||||||
|
|
||||||
const client = objectStore.ObjectStore(objectStore.ObjectStoreBuckets.APPS)
|
const client = objectStore.ObjectStore(objectStore.ObjectStoreBuckets.APPS)
|
||||||
|
|
||||||
|
@ -111,13 +181,53 @@ describe("test the create row action", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentRow.single_file_attachment = attachmentObject
|
attachmentRow.single_file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
const result = await createAutomationBuilder({
|
||||||
row: attachmentRow,
|
name: "Test Create Row Single Attachment Flow",
|
||||||
|
appId: config.getAppId(),
|
||||||
|
config,
|
||||||
})
|
})
|
||||||
|
.appAction({ fields: { type: "single-attachment" } })
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Processing single attachment" },
|
||||||
|
{ stepName: "StartLog" }
|
||||||
|
)
|
||||||
|
.createRow({ row: attachmentRow }, { stepName: "CreateRow" })
|
||||||
|
.branch({
|
||||||
|
success: {
|
||||||
|
steps: stepBuilder =>
|
||||||
|
stepBuilder
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Single attachment processed" },
|
||||||
|
{ stepName: "ProcessLog" }
|
||||||
|
)
|
||||||
|
.serverLog(
|
||||||
|
{
|
||||||
|
text: "File key: {{ stepsByName.CreateRow.row.single_file_attachment.key }}",
|
||||||
|
},
|
||||||
|
{ stepName: "KeyLog" }
|
||||||
|
),
|
||||||
|
condition: {
|
||||||
|
equal: { "{{ stepsByName.CreateRow.success }}": true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
steps: stepBuilder =>
|
||||||
|
stepBuilder.serverLog(
|
||||||
|
{ text: "Failed to process attachment" },
|
||||||
|
{ stepName: "ErrorLog" }
|
||||||
|
),
|
||||||
|
condition: {
|
||||||
|
equal: { "{{ stepsByName.CreateRow.success }}": false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.run()
|
||||||
|
|
||||||
expect(res.success).toEqual(true)
|
expect(result.steps[1].outputs.success).toEqual(true)
|
||||||
expect(res.row.single_file_attachment).toHaveProperty("key")
|
expect(result.steps[1].outputs.row.single_file_attachment).toHaveProperty(
|
||||||
let s3Key = res.row.single_file_attachment.key
|
"key"
|
||||||
|
)
|
||||||
|
let s3Key = result.steps[1].outputs.row.single_file_attachment.key
|
||||||
|
|
||||||
const client = objectStore.ObjectStore(objectStore.ObjectStoreBuckets.APPS)
|
const client = objectStore.ObjectStore(objectStore.ObjectStoreBuckets.APPS)
|
||||||
|
|
||||||
|
@ -146,13 +256,50 @@ describe("test the create row action", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentRow.single_file_attachment = attachmentObject
|
attachmentRow.single_file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
const result = await createAutomationBuilder({
|
||||||
row: attachmentRow,
|
name: "Test Create Row Invalid Attachment Flow",
|
||||||
|
appId: config.getAppId(),
|
||||||
|
config,
|
||||||
})
|
})
|
||||||
|
.appAction({ fields: { type: "invalid-attachment" } })
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Testing invalid attachment keys" },
|
||||||
|
{ stepName: "StartLog" }
|
||||||
|
)
|
||||||
|
.createRow({ row: attachmentRow }, { stepName: "CreateRow" })
|
||||||
|
.branch({
|
||||||
|
success: {
|
||||||
|
steps: stepBuilder =>
|
||||||
|
stepBuilder.serverLog(
|
||||||
|
{ text: "Unexpected success" },
|
||||||
|
{ stepName: "UnexpectedLog" }
|
||||||
|
),
|
||||||
|
condition: {
|
||||||
|
equal: { "{{ stepsByName.CreateRow.success }}": true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
steps: stepBuilder =>
|
||||||
|
stepBuilder
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Expected error occurred" },
|
||||||
|
{ stepName: "ErrorLog" }
|
||||||
|
)
|
||||||
|
.serverLog(
|
||||||
|
{ text: "Error: {{ stepsByName.CreateRow.response }}" },
|
||||||
|
{ stepName: "ErrorDetailsLog" }
|
||||||
|
),
|
||||||
|
condition: {
|
||||||
|
equal: { "{{ stepsByName.CreateRow.success }}": false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.run()
|
||||||
|
|
||||||
expect(res.success).toEqual(false)
|
expect(result.steps[1].outputs.success).toEqual(false)
|
||||||
expect(res.response).toEqual(
|
expect(result.steps[1].outputs.response).toEqual(
|
||||||
'Error: Attachments must have both "url" and "filename" keys. You have provided: wrongKey, anotherWrongKey'
|
'Error: Attachments must have both "url" and "filename" keys. You have provided: wrongKey, anotherWrongKey'
|
||||||
)
|
)
|
||||||
|
expect(result.steps[2].outputs.status).toEqual("No branch condition met")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue