Skip to content

Conversation

RishiChaubey31
Copy link
Member

@RishiChaubey31 RishiChaubey31 commented Aug 27, 2025

Date: 27-08-2025

Developer Name: Rishi Chaubey


Description

  • This PR contains the test regarding the OOO ( Out-Of-Office ) acknowledgement feature
  • This is the feature Pull Request

Issue Ticket

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1

Test Coverage

Screenshot 1 image Screenshot 2025-09-03 011250 Screenshot 2025-09-03 011039

Additional Notes

Description by Korbit AI

What change is being made?

Add comprehensive tests for the OOO (Out-Of-Office) acknowledgement feature, including unit tests, integration tests, and refactored test fixtures, while updating references throughout the test files.

Why are these changes being made?

The changes improve the test coverage for the OOO feature, ensuring that both happy and edge cases, including invalid request types and unauthorized actions, are thoroughly tested. The refactoring also maintains the consistency and readability of the codebase by updating function names and comments.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link

coderabbitai bot commented Aug 27, 2025

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
    • Superusers can now acknowledge (approve/reject) Out‑of‑Office requests via the update endpoint, with validation and conditional dev-flag checks.
    • Requests list supports status filtering (APPROVED, PENDING, REJECTED) to quickly find relevant items.
  • Bug Fixes
    • Clearer, more specific error responses when acknowledging requests (e.g., already approved/rejected) and when a request ID is missing.
  • Security
    • Role-based authorization added to the OOO acknowledgment path to ensure only permitted users can perform this action.

Walkthrough

Adds OOO request acknowledgment flow: constants expanded; new controller, middleware, validator, and service methods; route updated to include conditional dev/role checks; models gain get-by-id; existing controllers/validators updated to route OOO acknowledgments; types added; tests adjusted to new names, signatures, and behaviors.

Changes

Cohort / File(s) Summary
Constants
constants/requests.ts
Added REQUEST_LOG_TYPE entries for already-approved/rejected; removed standalone REQUEST_ALREADY_REJECTED export; added ERROR_WHILE_ACKNOWLEDGING_REQUEST and REQUEST_ID_REQUIRED.
Controllers
controllers/oooRequests.ts, controllers/requests.ts
New acknowledgeOooRequest controller (dev flag gate, superuser check, service delegation, error handling). Updated create flow signature usage. updateRequestBeforeAcknowledgedController now accepts next and routes OOO to acknowledge flow.
Middleware — Conditional Checks
middlewares/conditionalOooChecks.ts
New middleware that, for OOO type, runs devFlagMiddleware then authorizeRoles([SUPERUSER]); otherwise passes through.
Middleware — Validators
middlewares/validators/oooRequests.ts, middlewares/validators/requests.ts
New Joi validator for OOO acknowledgment; updateRequestValidator extended to handle OOO by delegating to the new validator; getRequestsMiddleware now allows optional status filter.
Models
models/requests.ts
Added getRequestById(id): fetches a request, throws NotFound if missing; logs on errors.
Routes
routes/requests.ts
PATCH /:id chain updated: authenticate → conditionalOooChecks → updateRequestValidator → updateRequestBeforeAcknowledgedController.
Services (OOO)
services/oooRequest.ts
Added validateOooAcknowledgeRequest and acknowledgeOooRequest (fetch, validate, update, log; create future status on approval). Refactored createOooRequest signature to (body, requestedBy).
Types
types/oooRequest.d.ts
Added AcknowledgeOooRequestQuery, AcknowledgeOooRequestBody, and AcknowledgeOooRequest types.
Tests — Fixtures
test/fixtures/oooRequest/oooRequest.ts
Renamed fixture export to TestacknowledgeOooRequest.
Tests — Integration
test/integration/requests.test.ts
Updated imports/usages to TestacknowledgeOooRequest; adjusted unauthorized constant usage.
Tests — Unit
test/unit/middlewares/oooRequests.test.ts, test/unit/services/oooRequest.test.ts
Switched to new validator name; updated service API usages and assertions; adopted TestacknowledgeOooRequest fixture.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant R as Router
  participant MW1 as authenticate
  participant MW2 as conditionalOooChecks
  participant MW3 as updateRequestValidator
  participant CTRL as updateRequestBeforeAcknowledgedController
  participant OOOCTRL as acknowledgeOooRequest (controller)
  participant SRV as oooRequest Service
  participant M as Models
  participant L as Log Service

  C->>R: PATCH /requests/:id (body: {type: OOO, status, comment})
  R->>MW1: authenticate
  MW1-->>R: next()
  R->>MW2: conditionalOooChecks
  alt type == OOO
    MW2->>MW2: devFlagMiddleware
    MW2->>MW2: authorizeRoles([SUPERUSER])
  else
    MW2-->>R: next()
  end
  R->>MW3: updateRequestValidator
  MW3-->>R: next()
  R->>CTRL: updateRequestBeforeAcknowledgedController(req,res,next)
  alt REQUEST_TYPE == OOO
    CTRL->>OOOCTRL: delegate(req,res,next)
    OOOCTRL->>SRV: acknowledgeOooRequest(requestId, body, superUserId)
    SRV->>M: getRequestById
    M-->>SRV: request or NotFound
    SRV->>SRV: validateOooAcknowledgeRequest(type,status)
    SRV->>M: update request status
    SRV->>L: addLog(REQUEST_APPROVED/REJECTED)
    opt on approval
      SRV->>M: createFutureStatus + createUserFutureStatus
    end
    SRV-->>OOOCTRL: {data, message}
    OOOCTRL-->>C: 200 {data, message}
  else
    CTRL-->>C: existing non-OOO flow
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

tests, backend

Suggested reviewers

  • MayankBansal12
  • AnujChhikara
  • iamitprakash
  • pankajjs

Poem

I nibbled the docs and tapped my paw,
New OOO paths now honor the law.
Dev flags checked, super-buns approve,
Requests hop forward—acknowledge the move.
If status repeats, I thump in objection—
Then bound away with future-direction. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/ooo-req-acknowledgement

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@RishiChaubey31 RishiChaubey31 changed the base branch from develop to feature/ooo-req-acknowledgement August 27, 2025 05:42
Copy link

korbit-ai bot commented Aug 27, 2025

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Error Handling Missing Error Context in Middleware ▹ view
Documentation Inconsistent spacing in code ▹ view
Design Inconsistent Module Import Pattern ▹ view
Security Unsanitized Comment Input in Future Status Creation ▹ view
Security Missing Authorization Check for OOO Request Acknowledgement ▹ view
Security Incomplete Request Type Validation ▹ view
Error Handling Improper Error Type Handling ▹ view
Functionality Missing Request Type Handler ▹ view
Design Monolithic Function with Multiple Responsibilities ▹ view
Error Handling Loss of Error Context in Validation ▹ view
Files scanned
File Path Reviewed
middlewares/conditionalOooChecks.ts
routes/requests.ts
types/oooRequest.d.ts
middlewares/validators/oooRequests.ts
constants/requests.ts
models/requests.ts
controllers/requests.ts
middlewares/validators/requests.ts
controllers/oooRequests.ts
services/oooRequest.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Copy link
Member

@AnujChhikara AnujChhikara left a comment

Choose a reason for hiding this comment

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

@RishiChaubey31 don't find any test for user status changed , if super user approve the request then the user status must changed based on their request, can you please add them

@iamitprakash iamitprakash merged commit c362646 into feature/ooo-req-acknowledgement Sep 6, 2025
3 checks passed
@iamitprakash iamitprakash deleted the test/ooo-req-acknowledgement branch September 6, 2025 18:44
iamitprakash pushed a commit that referenced this pull request Sep 6, 2025
* initial commit

* fix-services-ooorequest-test

* fix-module-imports

* refactor: streamline OOO request handling and enhance validation

- Removed unnecessary checks for development mode and user roles in createOooRequestController.
- Improved documentation for acknowledgeOooRequest function to clarify parameters and return types.
- Added validation for request parameters in acknowledgeOooRequest middleware.
- Updated error handling in getRequestById to use a constant for not found messages.
- Cleaned up imports in requests model to remove unused constants.

* feat: enhance OOO request creation with user role validation

- Added role validation to ensure only users part of Discord can create OOO requests.
- Implemented a check for development mode to restrict access to the feature.
- Updated the controller to handle unauthorized access appropriately.

* fix-getRequestByID-function

* fix-validator-name

* refactor: remove redundant request constants from REQUEST_LOG_TYPE

* fix-ooo-models-condtions

* refactor: enhance OOO request handling and validation

- Updated createOooRequestController to use username instead of roles for user identification.
- Introduced conditionalOooChecks middleware to apply role and dev checks specifically for OOO requests.
- Improved validation error handling in acknowledgeOooRequest and added constants for error messages.
- Refactored request validation schemas for clarity and consistency.
- Cleaned up imports and ensured proper middleware usage in routes.

* refactor: update error handling in OOO request service

- Replaced BadRequest error with NotFound error in acknowledgeOooRequest for improved clarity.
- Removed unused import of NotFound from requests model to streamline code.

* fix/function-name

* fix/spaces

* refactor: simplify variable usage in acknowledgeOooRequest

- Removed redundant variable assignments for 'from', 'until', and 'requestedBy' in acknowledgeOooRequest function.
- Directly used the parameters in subsequent function calls to enhance code clarity and reduce unnecessary lines.

* refactor: rename acknowledgeOooRequest for consistency

- Updated the function name from acknowledgeOooRequest to acknowledgeOooRequestController for clarity and to align with naming conventions in the codebase.
- Adjusted import statements accordingly in the requests controller to reflect the new function name.

* refactor: update acknowledgeOooRequest to improve clarity and maintainability

- Added a TODO comment to indicate the need for future removal of legacy request format handling.
- Simplified the return structure by removing unnecessary data wrapping around requestResult.

* refactor: enhance type handling in acknowledgeOooRequest

- Updated requestData type assertion to include oldOooStatusRequest for better type safety.
- Removed legacy request format normalization logic to streamline the function and improve clarity.

* fix-nested-loop-refactor

* fix/change-conflict-to-badrequest

* refactor: improve oooRoleCheckMiddleware and oooRequests validation

- Enhanced the oooRoleCheckMiddleware for better error handling and code clarity.
- Updated the acknowledgeOooRequestValidator to include specific Joi validation error handling.
- Simplified the validateOooAcknowledgeRequest function by removing unnecessary try-catch nesting and improving logging for invalid request types.

* fix-jsdoc

* refactor: improve error handling and type safety in oooRequests

- Updated acknowledgeOooRequestController to remove unnecessary return statement.
- Enhanced acknowledgeOooRequestValidator to streamline Joi validation error handling.
- Improved type assertions in updateRequestValidator for better clarity and type safety.
- Refined transformRequestResponse logic to simplify request transformation based on environment conditions.

* feat: tests for OOO acknowledgement feature (#2474)

* initial commit

* added-more-test

* fix-test-title

* removed-try/catch-block

* fix-try-catch-cases

* added-try-catch

* removed-functon

* test: update assertions in oooRequest tests to use include for response validation

---------

Co-authored-by: Mayank Bansal <[email protected]>

---------

Co-authored-by: Mayank Bansal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants