-
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
Add API validation and some tests for automation branching #14508
Conversation
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.
I know I know, I hate this ugly structures file as well, but had to add some as the Automation Test Builder doesn't really work for this case as it doesn't allow you (because of typing) to generate an incorrect structure, say a step after a branch etc. So this is really simulating some bad request coming from the frontend.
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.
In a lot of other parts of the test code that we write, when we're creating invalid structures that TypeScript does not like, we typically just annotate them with a @ts-ignore
comment. If that allows you to not add this structure here, then I think that's probably the way
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.
I actually misunderstood my own code, it's because on a branch step in the test builder we literally only allow a run function:
branch(branchConfig: BranchConfig): {
run: () => Promise<AutomationResults>
} {
this.addBranchStep(branchConfig)
return {
run: () => this.run(),
}
}
I can try and this if you want to try and make it more flexible, what do you think?
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.
I actually just updated the builder and the tests to support this @samwho
…validation' into feat/branching-api-validation
const res = await request | ||
.post(`/api/automations`) | ||
.set(config.defaultHeaders()) | ||
.send(automation) | ||
.expect("Content-Type", /json/) | ||
.expect(400) |
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.
I'd add this post call to packages/server/src/tests/utilities/api/automation.ts
and use the Expectations
type you'll find reference to in there to assert the shape of the body (e.g. { message: "Branch steps are only allowed as the last step" }
. This should make these tests shorter and easier to parse, also more in line with the bulk of our other integration tests.
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.
In a lot of other parts of the test code that we write, when we're creating invalid structures that TypeScript does not like, we typically just annotate them with a @ts-ignore
comment. If that allows you to not add this structure here, then I think that's probably the way
Co-authored-by: Sam Rose <hello@samwho.dev>
Co-authored-by: Sam Rose <hello@samwho.dev>
Description
This PR adds validation for automation branching to our API layer and also some tests to verify it is working correctly.
Also fixed an issue where the branch step wasn't appearing the execution output that I noticed as part of this work, and updated some tests to cover this.
Addresses
https://linear.app/budibase/issue/BUDI-8533/validate-automation-structure-at-api