-
-
Notifications
You must be signed in to change notification settings - Fork 88
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(zod): add coercion call when generating schema for DateTime field #1068
Conversation
WalkthroughWalkthroughThe updates focus on enhancing date handling and validation within the REST server tests and Zod plugin, specifically by introducing a Changes
Assessment against linked issues
Related issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (4)
- packages/schema/src/plugins/zod/utils/schema-gen.ts (1 hunks)
- packages/server/tests/api/rest.test.ts (3 hunks)
- packages/server/tests/utils.ts (1 hunks)
- tests/integration/tests/plugins/zod.test.ts (1 hunks)
Additional comments: 8
packages/server/tests/utils.ts (1)
- 23-23: The addition of the
publishedAt
field of typeDateTime
to thePost
model aligns with the PR objectives and enhances the model's capabilities for handling date and time information.packages/schema/src/plugins/zod/utils/schema-gen.ts (1)
- 177-177: Updating the schema generation for 'DateTime' fields to use
z.coerce.date()
is a critical improvement. It enhances the flexibility in handling date inputs, addressing the core issue with DateTime field serialization and validation in model-level validation.tests/integration/tests/plugins/zod.test.ts (1)
- 506-548: The addition of the 'does date coercion' test case is commendable. It effectively validates the handling of different date formats for a model field, ensuring that the changes made to DateTime field handling work as expected across various scenarios.
packages/server/tests/api/rest.test.ts (5)
- 43-47: Adding a new
publishedAt
field of typeDateTime
to thePost
model is a significant change. Ensure that all related CRUD operations, especially those involving date handling, are properly updated to accommodate this new field.- 1297-1317: The test for creating an item with date coercion is crucial for ensuring that the system correctly handles DateTime fields. It's important to verify that the
publishedAt
field accepts and correctly processes ISO 8601 date strings. Additionally, consider adding assertions to check the actual stored value in the database to ensure the coercion happened as expected.- 1319-1338: This test case for creating an item with a Zod violation is essential for validating the robustness of the input validation mechanism. It's good practice to include more detailed assertions about the error message to ensure it provides meaningful feedback to the client. This helps in debugging and improves the API's usability.
- 1633-1653: The test for updating an item with date coercion is important for ensuring consistency in handling DateTime fields across different operations. Similar to the creation test, it would be beneficial to add assertions that verify the new value of the
publishedAt
field in the database, ensuring the update and coercion were successful.- 1655-1675: Testing for Zod validation errors during an update operation is crucial for maintaining data integrity. This test case should also include more detailed assertions regarding the error message to ensure it accurately reflects the nature of the violation, aiding in troubleshooting and enhancing API usability.
Fixes #1067
Summary by CodeRabbit
publishedAt
field of typeDateTime
to thePost
entity to enhance date handling and validation.publishedAt
field.