Skip to content

feat: tests for OOO acknowledgement feature#2474

Merged
iamitprakash merged 24 commits intofeature/ooo-req-acknowledgementfrom
test/ooo-req-acknowledgement
Sep 6, 2025
Merged

feat: tests for OOO acknowledgement feature#2474
iamitprakash merged 24 commits intofeature/ooo-req-acknowledgementfrom
test/ooo-req-acknowledgement

Conversation

@RishiChaubey31
Copy link
Contributor

@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

@coderabbitai
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
@korbit-ai
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
Contributor

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