-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaning up loop.spec.ts, moved tests from automation.spec.ts to more appropriate places. #15536
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import * as automation from "../../index" | ||
import * as triggers from "../../triggers" | ||
import { basicTable, loopAutomation } from "../../../tests/utilities/structures" | ||
import { context } from "@budibase/backend-core" | ||
import { basicTable } from "../../../tests/utilities/structures" | ||
import { | ||
Table, | ||
LoopStepType, | ||
AutomationResults, | ||
ServerLogStepOutputs, | ||
CreateRowStepOutputs, | ||
FieldType, | ||
} from "@budibase/types" | ||
import * as loopUtils from "../../loopUtils" | ||
import { LoopInput } from "../../../definitions/automations" | ||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder" | ||
import TestConfiguration from "../../../tests/utilities/TestConfiguration" | ||
|
||
|
@@ -34,41 +30,46 @@ describe("Attempt to run a basic loop automation", () => { | |
config.end() | ||
}) | ||
|
||
async function runLoop(loopOpts?: LoopInput): Promise<AutomationResults> { | ||
const appId = config.getAppId() | ||
return await context.doInAppContext(appId, async () => { | ||
const params = { fields: { appId } } | ||
const result = await triggers.externalTrigger( | ||
loopAutomation(table._id!, loopOpts), | ||
params, | ||
{ getResponses: true } | ||
) | ||
if ("outputs" in result && !result.outputs.success) { | ||
throw new Error("Unable to proceed - failed to return anything.") | ||
} | ||
return result as AutomationResults | ||
}) | ||
} | ||
|
||
it("attempt to run a basic loop", async () => { | ||
const resp = await runLoop() | ||
expect(resp.steps[2].outputs.iterations).toBe(1) | ||
const result = await createAutomationBuilder(config) | ||
.onAppAction() | ||
.queryRows({ | ||
tableId: table._id!, | ||
}) | ||
.loop({ | ||
option: LoopStepType.ARRAY, | ||
binding: "{{ steps.1.rows }}", | ||
}) | ||
.serverLog({ text: "log statement" }) | ||
.test({ fields: {} }) | ||
|
||
expect(result.steps[1].outputs.iterations).toBe(1) | ||
}) | ||
|
||
it("test a loop with a string", async () => { | ||
const resp = await runLoop({ | ||
option: LoopStepType.STRING, | ||
binding: "a,b,c", | ||
}) | ||
expect(resp.steps[2].outputs.iterations).toBe(3) | ||
const result = await createAutomationBuilder(config) | ||
.onAppAction() | ||
.loop({ | ||
option: LoopStepType.STRING, | ||
binding: "a,b,c", | ||
}) | ||
.serverLog({ text: "log statement" }) | ||
.test({ fields: {} }) | ||
|
||
expect(result.steps[0].outputs.iterations).toBe(3) | ||
}) | ||
|
||
it("test a loop with a binding that returns an integer", async () => { | ||
const resp = await runLoop({ | ||
option: LoopStepType.ARRAY, | ||
binding: "{{ 1 }}", | ||
}) | ||
expect(resp.steps[2].outputs.iterations).toBe(1) | ||
const result = await createAutomationBuilder(config) | ||
.onAppAction() | ||
.loop({ | ||
option: LoopStepType.ARRAY, | ||
binding: "{{ 1 }}", | ||
}) | ||
.serverLog({ text: "log statement" }) | ||
.test({ fields: {} }) | ||
|
||
expect(result.steps[0].outputs.iterations).toBe(1) | ||
Comment on lines
+34
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be identical to their |
||
}) | ||
|
||
it("should run an automation with a trigger, loop, and create row step", async () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,33 @@ describe("app action trigger", () => { | |
}) | ||
) | ||
}) | ||
|
||
it("should correct coerce values based on the schema", async () => { | ||
const { automation } = await createAutomationBuilder(config) | ||
.onAppAction({ | ||
fields: { text: "string", number: "number", boolean: "boolean" }, | ||
}) | ||
.serverLog({ | ||
text: "{{ fields.text }} {{ fields.number }} {{ fields.boolean }}", | ||
}) | ||
.save() | ||
|
||
await config.api.application.publish() | ||
|
||
const jobs = await captureAutomationResults(automation, async () => { | ||
await config.withProdApp(async () => { | ||
await config.api.automation.trigger(automation._id!, { | ||
fields: { text: "1", number: "2", boolean: "true" }, | ||
timeout: 1000, | ||
}) | ||
}) | ||
}) | ||
|
||
expect(jobs).toHaveLength(1) | ||
expect(jobs[0].data.event.fields).toEqual({ | ||
text: "1", | ||
number: 2, | ||
boolean: true, | ||
}) | ||
}) | ||
Comment on lines
+46
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new to cover a test that was happening in |
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been moved from
automation.spec.ts
to here.