website-backend
website-backend copied to clipboard
feat: add test cases for POST /requests creating OOO request
Date: 08 Mar, 2025
Developer Name: Suraj Maity ( @surajmaity1 )
Issue Ticket Number
- Open #2242
Description
This PR adds test cases for the POST /requests API for OOO requests to ensure its correctness and reliability. The tests cover the following scenarios:
- Valid input for creating OOO request.
- Invalid input handling (e.g., missing or incorrect fields).
- Authentication and authorization checks.
- Error handling for edge cases and unexpected failures.
Documentation Updated?
- [ ] Yes
- [x] No
Under Feature Flag
- [x] Yes
- [ ] No
Database Changes
- [ ] Yes
- [x] No
Breaking Changes
- [ ] Yes
- [x] No
Development Tested?
- [x] Yes
- [ ] No
Test Coverage
Screenshot 1
Additional Notes
- This test PR has to be merged into the Feature PR ( https://github.com/Real-Dev-Squad/website-backend/pull/2383 ), and then the feature PR ( https://github.com/Real-Dev-Squad/website-backend/pull/2383 ) can be merged into develop.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Summary by CodeRabbit
- New Features
- Updated out-of-office request submissions to use clearer, more descriptive fields for user input and request status.
- Bug Fixes
- Enhanced validation and error handling across request endpoints, ensuring more consistent and descriptive feedback when inputs are missing or invalid.
Walkthrough
This pull request revises the structure and validations for Out of Office requests. The fixture objects have been updated to use the properties reason and status instead of message and state. Integration tests for the /requests endpoint are enhanced with new cases, standardized endpoints, and improved error handling. Additionally, unit tests for middleware and service components have been modified to validate these new properties and to incorporate a comprehensive test suite for user status validations and request creation.
Changes
| File(s) | Change Summary |
|---|---|
test/fixtures/oooRequest/oooRequest.ts |
Updated the OOO request object structure by replacing message with reason and state with status in both validOooStatusRequests and createOooRequests. |
test/integration/requests.test.ts |
Enhanced /requests endpoint tests by adding new test cases, standardizing the endpoint variable, importing new helper methods (updateUserStatus, getRequestByKeyValues), and updating validations to use reason instead of message. |
test/unit/middlewares/oooRequests.test.ts |
Adjusted validation tests: removed the unused validOooStatusUpdate import, replaced message checks with reason, and updated expected error messages and validation detail counts accordingly. |
test/unit/services/oooRequest.test.ts |
Introduced a comprehensive test suite for the OOO Request service, covering validateUserStatus and createOOORequest scenarios with tests for error cases, successful creation, and error logging simulations. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant API
participant OOOService
Client->>API: POST /requests (with { reason, ... })
API->>OOOService: validateUserStatus(user)
OOOService-->>API: Return validation result or error
API->>OOOService: createOOORequest(data)
OOOService-->>API: Return request status (e.g., PENDING)
API-->>Client: JSON response with success or error message
Poem
I'm a bunny in a code-filled glen,
Hopping through changes time and again.
No more "message" or stale "state",
With "reason" and "status", our code's first rate.
Carrots and code, let's celebrate!
🥕🐇
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
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 using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@surajmaity1 Failing test case?
@surajmaity1 Failing test case?
Hi @prakashchoudhary07 , test cases are failing becuase this PR only contains tests of feature PR ( https://github.com/Real-Dev-Squad/website-backend/pull/2383 ) .
@surajmaity1 Failing test case?
Hi @prakashchoudhary07 , test cases are failing becuase this PR only contains tests of feature PR ( #2383 ) .
Then shouldn't it be mentioned in the description?
Also, what is the plan? When are we going to merge this PR And special note please mention it in the description
@surajmaity1 Failing test case?
Hi @prakashchoudhary07 , test cases are failing becuase this PR only contains tests of feature PR ( #2383 ) .
Then shouldn't it be mentioned in the description?
Also, what is the plan? When are we going to merge this PR And special note please mention it in the description
Hi @prakashchoudhary07 , can you please check now in the additional notes section? Thank you.
All my comments have been addressed. Since this PR is not stacked on the feature PR, we’ve had to temporarily skip/comment out some tests because the corresponding feature code isn't yet present in the repo. I'll personally ensure that these test cases are uncommented once the feature PR is under review or merged.
Approving this PR
Thank you for this @AnujChhikara