website-backend icon indicating copy to clipboard operation
website-backend copied to clipboard

feat: add test cases for POST /requests creating OOO request

Open surajmaity1 opened this issue 8 months ago • 5 comments

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

1 2 3

unit validator unit service image

4

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.

surajmaity1 avatar Mar 08 '25 14:03 surajmaity1

[!IMPORTANT]

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in 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.

❤️ Share
🪧 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 @coderabbitai in 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 @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

coderabbitai[bot] avatar Mar 08 '25 14:03 coderabbitai[bot]

@surajmaity1 Failing test case?

prakashchoudhary07 avatar Apr 11 '25 19:04 prakashchoudhary07

@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 avatar Apr 12 '25 06:04 surajmaity1

@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

prakashchoudhary07 avatar Apr 12 '25 06:04 prakashchoudhary07

@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.

surajmaity1 avatar Apr 12 '25 07:04 surajmaity1

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

prakashchoudhary07 avatar Apr 29 '25 20:04 prakashchoudhary07