-
Notifications
You must be signed in to change notification settings - Fork 273
feat: Add test cases for PATCH /requests/:id API for acknowledging OOO requests #2391
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: Add test cases for PATCH /requests/:id API for acknowledging OOO requests #2391
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
WalkthroughThe changes enhance the functionality and test coverage for out-of-office (OOO) requests. New constants for creating and acknowledging OOO requests were added to a fixture file. Integration tests now cover the PATCH /requests/:id endpoint for various error conditions and success scenarios during request acknowledgment. Additionally, unit tests have been expanded to verify the behavior of the OOO request validator and service functions under valid and invalid conditions. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant Validator
participant Service
Client->>API: PATCH /requests/{id} (acknowledge OOO request)
API->>Validator: Run acknowledgeOOORequestsValidator
alt Validation Success
API->>Service: Process OOO request acknowledgment
Service-->>API: Return success response
API-->>Client: 200 OK (acknowledged)
else Validation Failure
API-->>Client: Error response (400/401/404/501)
end
Poem
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. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
e37b3b0
to
80ef6f8
Compare
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.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
test/fixtures/oooRequest/oooRequest.ts
(1 hunks)test/integration/requests.test.ts
(5 hunks)test/unit/middlewares/oooRequests.test.ts
(2 hunks)test/unit/services/oooRequest.test.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
test/fixtures/oooRequest/oooRequest.ts (1)
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/fixtures/oooRequest/oooRequest.ts:59-60
Timestamp: 2025-03-22T14:28:57.808Z
Learning: The `createOooRequests2` object in test/fixtures/oooRequest/oooRequest.ts still uses the old property names `message` and `state` (instead of `reason` and `status`) because it's specifically used in acknowledging OOO request tests. This naming inconsistency will be fixed by surajmaity1 in a dedicated PR for acknowledging OOO requests.
🧬 Code Definitions (4)
test/fixtures/oooRequest/oooRequest.ts (1)
constants/requests.ts (1)
REQUEST_STATE
(1-5)
test/unit/middlewares/oooRequests.test.ts (1)
test/fixtures/oooRequest/oooRequest.ts (1)
acknowledgeOooRequest
(142-145)
test/unit/services/oooRequest.test.ts (1)
test/fixtures/oooRequest/oooRequest.ts (1)
acknowledgeOooRequest
(142-145)
test/integration/requests.test.ts (3)
test/fixtures/oooRequest/oooRequest.ts (2)
createOooRequests3
(133-140)acknowledgeOooRequest
(142-145)models/requests.ts (2)
createRequest
(13-30)updateRequest
(32-70)constants/requests.ts (8)
REQUEST_STATE
(1-5)REQUEST_TYPE
(13-19)REQUEST_DOES_NOT_EXIST
(42-42)REQUEST_ALREADY_APPROVED
(35-35)REQUEST_ALREADY_REJECTED
(36-36)INVALID_REQUEST_TYPE
(63-63)REQUEST_APPROVED_SUCCESSFULLY
(31-31)REQUEST_REJECTED_SUCCESSFULLY
(32-32)
🪛 ESLint
test/fixtures/oooRequest/oooRequest.ts
[error] 139-139: Insert ,
(prettier/prettier)
[error] 144-144: Insert ,
(prettier/prettier)
[error] 145-145: Insert ⏎
(prettier/prettier)
test/unit/services/oooRequest.test.ts
[error] 3-3: Replace ·INVALID_REQUEST_TYPE,·REQUEST_ALREADY_APPROVED,·REQUEST_ALREADY_REJECTED,·REQUEST_APPROVED_SUCCESSFULLY,·REQUEST_DOES_NOT_EXIST,·REQUEST_STATE,·REQUEST_TYPE·
with ⏎··INVALID_REQUEST_TYPE,⏎··REQUEST_ALREADY_APPROVED,⏎··REQUEST_ALREADY_REJECTED,⏎··REQUEST_APPROVED_SUCCESSFULLY,⏎··REQUEST_DOES_NOT_EXIST,⏎··REQUEST_STATE,⏎··REQUEST_TYPE,⏎
(prettier/prettier)
[error] 14-14: Insert ·
(prettier/prettier)
[error] 15-16: Delete ⏎··
(prettier/prettier)
[error] 18-18: Delete ··
(prettier/prettier)
[error] 19-19: Replace ········
with ····
(prettier/prettier)
[error] 20-20: Replace ········
with ····
(prettier/prettier)
[error] 21-21: Delete ··
(prettier/prettier)
[error] 23-23: Replace ····describe("validateOOOAcknowledgeRequest",·function
with ··describe("validateOOOAcknowledgeRequest",·function·
(prettier/prettier)
[error] 24-25: Delete ⏎····
(prettier/prettier)
[error] 26-26: Replace ········
with ····
(prettier/prettier)
[error] 28-28: Delete ····
(prettier/prettier)
[error] 29-29: Delete ······
(prettier/prettier)
[error] 30-30: Delete ········
(prettier/prettier)
[error] 31-31: Replace ················
with ········
(prettier/prettier)
[error] 32-32: Replace ················
with ········
(prettier/prettier)
[error] 33-33: Replace ············}
with ······};
(prettier/prettier)
[error] 34-34: Replace ········
with ····
(prettier/prettier)
[error] 36-36: Replace ········it("should·return·INVALID_REQUEST_TYPE·if·request·type·is·not·OOO",·async·function
with ····it("should·return·INVALID_REQUEST_TYPE·if·request·type·is·not·OOO",·async·function·
(prettier/prettier)
[error] 37-37: Replace ············testRequestData·=·{...testRequestData,·requestType:·"ONBOARDING"
with ······testRequestData·=·{·...testRequestData,·requestType:·"ONBOARDING"·
(prettier/prettier)
[error] 38-38: Delete ······
(prettier/prettier)
[error] 39-39: Replace ················
with ········
(prettier/prettier)
[error] 40-40: Replace ····················
with ··········
(prettier/prettier)
[error] 41-41: Replace ····················
with ··········
(prettier/prettier)
[error] 42-42: Replace ····················
with ··········
(prettier/prettier)
[error] 43-43: Replace ················
with ········
(prettier/prettier)
[error] 44-44: Delete ······
(prettier/prettier)
[error] 45-45: Replace ················
with ········
(prettier/prettier)
[error] 46-46: Delete ········
(prettier/prettier)
[error] 47-47: Delete ········
(prettier/prettier)
[error] 48-48: Delete ······
(prettier/prettier)
[error] 49-49: Replace ········
with ····
(prettier/prettier)
[error] 51-51: Replace ········it("should·return·REQUEST_ALREADY_APPROVED·if·request·is·already·approved",·async·function
with ····it("should·return·REQUEST_ALREADY_APPROVED·if·request·is·already·approved",·async·function·
(prettier/prettier)
[error] 52-52: Replace ············testRequestData·=·{...testRequestData,·requestStatus:·REQUEST_STATE.APPROVED
with ······testRequestData·=·{·...testRequestData,·requestStatus:·REQUEST_STATE.APPROVED·
(prettier/prettier)
[error] 53-53: Replace ············
with ······
(prettier/prettier)
[error] 54-54: Replace ················
with ········
(prettier/prettier)
[error] 55-55: Delete ··········
(prettier/prettier)
[error] 56-56: Replace ····················
with ··········
(prettier/prettier)
[error] 57-57: Replace ····················
with ··········
(prettier/prettier)
[error] 58-58: Replace ················
with ········
(prettier/prettier)
[error] 59-59: Delete ······
(prettier/prettier)
[error] 60-60: Replace ················
with ········
(prettier/prettier)
[error] 61-61: Replace ················
with ········
(prettier/prettier)
[error] 62-62: Replace ················
with ········
(prettier/prettier)
[error] 63-63: Delete ······
(prettier/prettier)
[error] 64-64: Delete ····
(prettier/prettier)
[error] 66-66: Replace ········it("should·return·REQUEST_ALREADY_REJECTED·if·request·is·already·rejected",·async·function
with ····it("should·return·REQUEST_ALREADY_REJECTED·if·request·is·already·rejected",·async·function·
(prettier/prettier)
[error] 67-67: Replace ············testRequestData·=·{...testRequestData,·requestStatus:·REQUEST_STATE.REJECTED
with ······testRequestData·=·{·...testRequestData,·requestStatus:·REQUEST_STATE.REJECTED·
(prettier/prettier)
[error] 68-68: Replace ············
with ······
(prettier/prettier)
[error] 69-69: Delete ········
(prettier/prettier)
[error] 70-70: Replace ····················
with ··········
(prettier/prettier)
[error] 71-71: Replace ····················
with ··········
(prettier/prettier)
[error] 72-72: Replace ····················
with ··········
(prettier/prettier)
[error] 73-73: Delete ········
(prettier/prettier)
[error] 74-74: Replace ············
with ······
(prettier/prettier)
[error] 75-75: Delete ········
(prettier/prettier)
[error] 76-76: Replace ················
with ········
(prettier/prettier)
[error] 77-77: Delete ········
(prettier/prettier)
[error] 78-78: Replace ············
with ······
(prettier/prettier)
[error] 79-79: Delete ····
(prettier/prettier)
[error] 81-81: Replace ········it("should·return·undefined·when·all·validation·checks·passes",·async·function
with ····it("should·return·undefined·when·all·validation·checks·passes",·async·function·
(prettier/prettier)
[error] 82-82: Delete ······
(prettier/prettier)
[error] 83-83: Replace ················
with ········
(prettier/prettier)
[error] 84-84: Replace ················
with ········
(prettier/prettier)
[error] 85-85: Replace ················testRequestData.requestStatus,
with ········testRequestData.requestStatus
(prettier/prettier)
[error] 86-86: Replace ············
with ······
(prettier/prettier)
[error] 87-87: Replace ············
with ······
(prettier/prettier)
[error] 87-87: Expected an assignment or function call and instead saw an expression.
(no-unused-expressions)
[error] 88-88: Delete ····
(prettier/prettier)
[error] 90-90: Replace ········it("should·throw·error",·async·function
with ····it("should·throw·error",·async·function·
(prettier/prettier)
[error] 91-91: Replace ············
with ······
(prettier/prettier)
[error] 92-92: Delete ······
(prettier/prettier)
[error] 94-94: Delete ······
(prettier/prettier)
[error] 95-95: Replace ················
with ········
(prettier/prettier)
[error] 96-96: Delete ··········
(prettier/prettier)
[error] 97-97: Replace ····················
with ··········
(prettier/prettier)
[error] 98-98: Replace ····················
with ··········
(prettier/prettier)
[error] 99-99: Replace ················
with ········
(prettier/prettier)
[error] 100-100: Delete ······
(prettier/prettier)
[error] 101-101: Replace ················
with ········
(prettier/prettier)
[error] 102-102: Replace ················
with ········
(prettier/prettier)
[error] 102-102: Expected an assignment or function call and instead saw an expression.
(no-unused-expressions)
[error] 103-103: Replace ············
with ······
(prettier/prettier)
[error] 104-104: Replace ········
with ····
(prettier/prettier)
[error] 105-105: Replace ····
with ··
(prettier/prettier)
[error] 107-107: Replace ····describe("acknowledgeOOORequest",·function
with ··describe("acknowledgeOOORequest",·function·
(prettier/prettier)
[error] 108-109: Replace ⏎········
with ····
(prettier/prettier)
[error] 110-110: Delete ····
(prettier/prettier)
[error] 111-111: Delete ····
(prettier/prettier)
[error] 113-113: Delete ····
(prettier/prettier)
[error] 114-114: Replace ············
with ······
(prettier/prettier)
[error] 115-115: Delete ······
(prettier/prettier)
[error] 116-116: Delete ······
(prettier/prettier)
[error] 117-117: Replace ············
with ······
(prettier/prettier)
[error] 118-118: Replace ············
with ······
(prettier/prettier)
[error] 120-120: Delete ······
(prettier/prettier)
[error] 121-121: Replace ················
with ········
(prettier/prettier)
[error] 122-122: Delete ········
(prettier/prettier)
[error] 123-123: Replace ················
with ········
(prettier/prettier)
[error] 124-124: Delete ········
(prettier/prettier)
[error] 125-125: Replace ················
with ········
(prettier/prettier)
[error] 126-126: Replace ················
with ········
(prettier/prettier)
[error] 127-127: Replace ················
with ········
(prettier/prettier)
[error] 128-128: Replace ················
with ········
(prettier/prettier)
[error] 129-129: Replace ················lastModifiedBy:·null
with ········lastModifiedBy:·null,
(prettier/prettier)
[error] 130-130: Replace ············
with ······
(prettier/prettier)
[error] 131-131: Replace ········
with ····
(prettier/prettier)
[error] 133-133: Replace ········
with ····
(prettier/prettier)
[error] 134-134: Delete ······
(prettier/prettier)
[error] 135-139: Replace ················await·acknowledgeOOORequest(⏎····················"11111111111111111111",⏎····················acknowledgeOooRequest,⏎····················testSuperUserId⏎················
with ········await·acknowledgeOOORequest("11111111111111111111",·acknowledgeOooRequest,·testSuperUserId
(prettier/prettier)
[error] 140-140: Replace ············
with ······
(prettier/prettier)
[error] 141-141: Delete ········
(prettier/prettier)
[error] 142-142: Replace ················
with ········
(prettier/prettier)
[error] 143-143: Delete ······
(prettier/prettier)
[error] 144-144: Replace ········
with ····
(prettier/prettier)
[error] 146-146: Replace ········it("should·acknowledge·OOO·request",·async·function
with ····it("should·acknowledge·OOO·request",·async·function·
(prettier/prettier)
[error] 147-151: Replace ············const·response·=·await·acknowledgeOOORequest(⏎················validOOORequest.id,⏎················acknowledgeOooRequest,⏎················testSuperUserId⏎············
with ······const·response·=·await·acknowledgeOOORequest(validOOORequest.id,·acknowledgeOooRequest,·testSuperUserId
(prettier/prettier)
[error] 152-152: Delete ······
(prettier/prettier)
[error] 153-153: Replace ············
with ······
(prettier/prettier)
[error] 154-154: Replace ············
with ······
(prettier/prettier)
[error] 155-155: Delete ····
(prettier/prettier)
[error] 157-157: Replace ········it("should·throw·error",·async·function
with ····it("should·throw·error",·async·function·
(prettier/prettier)
[error] 158-158: Replace ············
with ······
(prettier/prettier)
[error] 159-159: Delete ······
(prettier/prettier)
[error] 161-161: Delete ······
(prettier/prettier)
[error] 162-166: Replace ················await·acknowledgeOOORequest(⏎····················validOOORequest.id,⏎····················acknowledgeOooRequest,⏎····················testSuperUserId⏎················
with ········await·acknowledgeOOORequest(validOOORequest.id,·acknowledgeOooRequest,·testSuperUserId
(prettier/prettier)
[error] 167-167: Replace ············
with ······
(prettier/prettier)
[error] 168-168: Delete ········
(prettier/prettier)
[error] 169-169: Replace ················
with ········
(prettier/prettier)
[error] 169-169: Expected an assignment or function call and instead saw an expression.
(no-unused-expressions)
[error] 170-170: Delete ······
(prettier/prettier)
[error] 171-171: Delete ····
(prettier/prettier)
[error] 172-172: Delete ··
(prettier/prettier)
🔇 Additional comments (16)
test/unit/middlewares/oooRequests.test.ts (3)
6-8
: LGTM: Added import for new validator function.The import statement correctly includes the new
acknowledgeOOORequestsValidator
function.
9-9
: LGTM: Updated imports to include required fixture.The import statement correctly includes the
acknowledgeOooRequest
fixture needed for testing.
94-121
: Well-structured test suite for acknowledgeOOORequestsValidator.The test suite provides good coverage for the validator function:
- Validates that requests with type field are rejected
- Validates that requests with incorrect status are rejected
- Verifies successful validation for valid acknowledge requests
Each test case properly asserts the expected behavior of the validator function.
test/unit/services/oooRequest.test.ts (1)
1-13
: LGTM: Well-structured test file setup.The imports and initial setup look good, bringing in necessary dependencies and fixtures for testing the OOO request services.
🧰 Tools
🪛 ESLint
[error] 3-3: Replace
·INVALID_REQUEST_TYPE,·REQUEST_ALREADY_APPROVED,·REQUEST_ALREADY_REJECTED,·REQUEST_APPROVED_SUCCESSFULLY,·REQUEST_DOES_NOT_EXIST,·REQUEST_STATE,·REQUEST_TYPE·
with⏎··INVALID_REQUEST_TYPE,⏎··REQUEST_ALREADY_APPROVED,⏎··REQUEST_ALREADY_REJECTED,⏎··REQUEST_APPROVED_SUCCESSFULLY,⏎··REQUEST_DOES_NOT_EXIST,⏎··REQUEST_STATE,⏎··REQUEST_TYPE,⏎
(prettier/prettier)
test/integration/requests.test.ts (12)
3-20
: LGTM: Updated imports with required modules and fixtures.The imports have been properly updated to include the necessary modules, constants, and fixtures for the new tests, including:
- sinon for mocking
- UNAUTHORIZED_TO_ACKNOWLEDGE_OOO_REQUEST and INVALID_REQUEST_TYPE constants
- acknowledgeOooRequest and createOooRequests3 fixtures
- logUtils for testing error cases
49-49
: LGTM: Added superuser ID variable.The addition of
testSuperUserId
is necessary for testing authorization scenarios.
56-56
: LGTM: Updated beforeEach to set superuser ID.Setting the
testSuperUserId
to the returned value properly initializes the variable.
196-221
: LGTM: Well-structured setup for PATCH endpoint tests.The setup includes:
- New variables for test data
- Creation of different OOO requests with various states (pending, approved, rejected)
- An invalid request type for testing type validation
Each variable is correctly initialized with appropriate test data.
223-234
: LGTM: Authentication test for PATCH endpoint.This test properly verifies that the endpoint returns a 401 status when a user is not logged in, which is an important security check.
236-250
: LGTM: Feature flag test for PATCH endpoint.This test verifies that the endpoint returns a 501 status when the
dev
flag is false, indicating that the feature is controlled by a feature flag.
252-266
: LGTM: Validation test for non-existent requests.This test confirms that the endpoint returns a 404 status when the request ID doesn't exist.
268-282
: LGTM: Authorization test for PATCH endpoint.This test verifies that the endpoint returns a 401 status when a user doesn't have super user permissions, which is an important security check.
284-314
: LGTM: Request state validation tests.These tests check that the endpoint properly validates the current state of the request:
- Returns 400 if the request is already approved
- Returns 400 if the request is already rejected
These validations prevent duplicate processing of requests.
316-330
: LGTM: Request type validation test.This test verifies that the endpoint returns a 400 status when attempting to acknowledge a non-OOO request type, ensuring type validation.
332-362
: LGTM: Success case tests for approving and rejecting requests.These tests verify that the endpoint correctly:
- Approves OOO requests with 200 status
- Rejects OOO requests with 200 status
Both tests confirm the expected success messages for their operations.
364-378
: LGTM: Error handling test for unexpected errors.This test uses sinon to create a failure condition and verifies that the endpoint returns a 500 status with appropriate error message, demonstrating robust error handling.
80ef6f8
to
b17187b
Compare
@surajmaity1 Error in build it self, please have a look |
@surajmaity1 Build is faling, please check |
Hi @prakashchoudhary07 , it's fixed. |
Hi @prakashchoudhary07 , it's fixed now. |
854f1c8
to
1f545e6
Compare
1f545e6
to
acc56ec
Compare
…O requests (#2391) * feat: add tests for PATCH OOO request * feat: add tests for PATCH OOO request * fix: skip test cases * fix: test case * fix: test skipped
Date: 22 Mar, 2025
Developer Name: Suraj Maity ( @surajmaity1 )
Issue Ticket Number
Description
This PR adds test cases for the PATCH /requests/:id API for acknowledging OOO requests to ensure its correctness and reliability. The tests cover the following scenarios:
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Test Coverage
Screenshot 1
Additional Notes