Skip to content
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

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

samwho
Copy link
Collaborator

@samwho samwho commented Feb 12, 2025

Description

  • loop.spec.ts had some tests that weren't using createAutomationBuilder so I converted them.
  • automation.spec.ts was doing some mocking that we don't need anymore now that we have createAutomationBuilder, so I wrote a new test in appAction.spec.ts that covered what it was doing, moved another test from it into automationUtils.spec.ts, and deleted the file.

@samwho samwho requested a review from a team as a code owner February 12, 2025 12:52
@samwho samwho requested review from adrinr and removed request for a team February 12, 2025 12:52
Copy link

qa-wolf bot commented Feb 12, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@github-actions github-actions bot added firestorm Data/Infra/Revenue Team size/m labels Feb 12, 2025
Comment on lines +123 to +147
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)
})
Copy link
Collaborator Author

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.

Comment on lines +34 to +72
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)
Copy link
Collaborator Author

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.

Comment on lines +46 to +73
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,
})
})
Copy link
Collaborator Author

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

Base automatically changed from app-action-tests to master February 12, 2025 15:08
@samwho samwho merged commit c49ae39 into master Feb 12, 2025
20 checks passed
@samwho samwho deleted the fix-automation-loop-test-output branch February 12, 2025 15:39
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
firestorm Data/Infra/Revenue Team size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants