-
Notifications
You must be signed in to change notification settings - Fork 273
feat: tests for OOO acknowledgement feature #2474
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
feat: tests for OOO acknowledgement feature #2474
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Summary by CodeRabbit
WalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Review by Korbit AIKorbit automatically attempts to detect when you fix issues in new commits.
Files scanned
|
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.
@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
…l-Dev-Squad/website-backend into test/ooo-req-acknowledgement
* 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]>
Date: 27-08-2025
Developer Name: Rishi Chaubey
Description
Issue Ticket
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Test Coverage
Screenshot 1
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.