-
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
Conversation
… appropriate places.
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
it("should be able to clean inputs with the utilities", () => { | ||
// can't clean without a schema | ||
let output = cleanInputValues({ a: "1" }) | ||
expect(output.a).toBe("1") | ||
output = cleanInputValues( | ||
{ a: "1", b: "true", c: "false", d: 1, e: "help" }, | ||
{ | ||
properties: { | ||
a: { | ||
type: "number", | ||
}, | ||
b: { | ||
type: "boolean", | ||
}, | ||
c: { | ||
type: "boolean", | ||
}, | ||
}, | ||
} | ||
) | ||
expect(output.a).toBe(1) | ||
expect(output.b).toBe(true) | ||
expect(output.c).toBe(false) | ||
expect(output.d).toBe(1) | ||
}) |
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.
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) |
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.
These should be identical to their runLoop
counterparts, but using the new builder instead of runLoop
.
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, | ||
}) | ||
}) |
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 is new to cover a test that was happening in automation.spec.ts
Description
loop.spec.ts
had some tests that weren't usingcreateAutomationBuilder
so I converted them.automation.spec.ts
was doing some mocking that we don't need anymore now that we havecreateAutomationBuilder
, so I wrote a new test inappAction.spec.ts
that covered what it was doing, moved another test from it intoautomationUtils.spec.ts
, and deleted the file.