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

Add API validation and some tests for automation branching #14508

Merged
merged 11 commits into from
Sep 4, 2024

Conversation

PClmnt
Copy link
Collaborator

@PClmnt PClmnt commented Sep 3, 2024

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

@PClmnt PClmnt marked this pull request as ready for review September 3, 2024 15:18
@PClmnt PClmnt requested a review from a team as a code owner September 3, 2024 15:18
@PClmnt PClmnt requested review from adrinr and removed request for a team September 3, 2024 15:18
@github-actions github-actions bot added firestorm Data/Infra/Revenue Team size/m labels Sep 3, 2024
Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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

Comment on lines 145 to 150
const res = await request
.post(`/api/automations`)
.set(config.defaultHeaders())
.send(automation)
.expect("Content-Type", /json/)
.expect(400)
Copy link
Collaborator

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.

packages/server/src/api/routes/utils/validators.ts Outdated Show resolved Hide resolved
packages/server/src/api/routes/utils/validators.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

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

@PClmnt PClmnt merged commit 2c9de04 into master Sep 4, 2024
12 checks passed
@PClmnt PClmnt deleted the feat/branching-api-validation branch September 4, 2024 16:53
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2024
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.

3 participants