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

fix: page router validations and add test cases #720

Merged
merged 47 commits into from
Oct 11, 2024
Merged

Conversation

karrui
Copy link
Contributor

@karrui karrui commented Oct 2, 2024

This PR starts the chain of PRs for adding test cases for all our procedures in the Studio application so we can be more confident when shipping code.

Solution

Breaking Changes

  • No - this PR is backwards compatible

Features:

  • Details ...

Improvements:

  • Add Tagged types to jsonb columns so we remember to call jsonb() function before insertion into the database. This prevents runtime errors.
  • Update updatePageBlobSchema to validate the type of content in the schema itself.
  • Update all *select constants to use satisfies keyword for better type inference when used.
  • Throw 404 errors when resource is not found in all page.router procedures
  • Validate whether folderId is a folder when calling createPage procedure and passing the folderId arg.
  • use transaction when updating page in updatePage procedure
  • add foreign key violation error handling

Bug Fixes:

  • use correct fullPage.publishedVersionId check in readPageAndBlob procedure

Tests

Tests are added for all procedures in the page router.

A few tests regarding permissions are skipped until permissions are in cc @seaerchin

Copy link

vercel bot commented Oct 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
isomer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 11, 2024 9:52am

Copy link
Contributor Author

karrui commented Oct 2, 2024

@karrui karrui changed the title refactor: use vite-tsconfig-paths for vitest config wip: update test pipelines Oct 2, 2024
@karrui karrui force-pushed the page_router_tests branch from c3b1c28 to b8363e8 Compare October 2, 2024 10:18
@karrui karrui changed the base branch from main to migrate_to_testcontainers October 2, 2024 10:18
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Oct 2, 2024

Datadog Report

Branch report: page_router_tests
Commit report: 19ee86d
Test service: isomer-studio

✅ 0 Failed, 35 Passed, 1 Skipped, 22.48s Total Time

}
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Invalid page content",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are trying to abort early right, do we need the FATAL: true flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok, this will still cause the validation to fail. FATAL just means zod stops validating immediately. No big deal for it to gather all validation errors before returning to the user

@@ -38,7 +38,7 @@ export const setSiteConfig = async (
) => {
return db
.updateTable("Site")
.set({ config })
.set({ config: jsonb(config) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously when we didn't cast it as jsonb it still worked right? how does the cast help now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still worked because of luck. we did not trigger any ambiguity on the pg engine. In more complex shapes, postgres may throw. So this is insurance.

Copy link
Contributor Author

karrui commented Oct 11, 2024

Merge activity

  • Oct 11, 5:55 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Oct 11, 6:00 AM EDT: Graphite couldn't merge this PR because it failed for an unknown reason.
  • Oct 11, 6:07 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Oct 11, 6:07 AM EDT: A user merged this pull request with Graphite.

Base automatically changed from migrate_to_testcontainers to main October 11, 2024 09:55
@karrui karrui enabled auto-merge (squash) October 11, 2024 10:05
@karrui karrui disabled auto-merge October 11, 2024 10:07
@karrui karrui merged commit 5569c85 into main Oct 11, 2024
15 checks passed
@karrui karrui deleted the page_router_tests branch October 11, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants