-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Achieved 100% Code Coverage for OrganizationCard Component #3464
Achieved 100% Code Coverage for OrganizationCard Component #3464
Conversation
WalkthroughThe pull request focuses on enhancing the test suite for the Changes
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
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: 2
🧹 Nitpick comments (3)
src/components/OrganizationCard/OrganizationCard.spec.tsx (3)
351-395
: Improve test name to be more descriptive.The current test name "should log development error and show generic error toast" could be more specific about the scenario being tested.
- it('should log development error and show generic error toast', async () => { + it('should log error in development and show toast when membership withdrawal fails', async () => {Also, fix the formatting issues to resolve the Prettier warnings:
expect(consoleErrorSpy).toHaveBeenCalledWith( - 'Failed to withdraw membership request:', + 'Failed to withdraw membership request:', expect.any(Error) );🧰 Tools
🪛 ESLint
[error] 352-352: Replace
.spyOn(console,·'error')
with⏎······.spyOn(console,·'error')⏎······
(prettier/prettier)
[error] 353-353: Delete
····
(prettier/prettier)
[error] 357-357: Delete
··
(prettier/prettier)
[error] 364-364: Delete
··
(prettier/prettier)
[error] 374-374: Delete
··
(prettier/prettier)
[error] 378-378: Insert
,
(prettier/prettier)
[error] 380-380: Delete
··
(prettier/prettier)
[error] 383-383: Delete
··
(prettier/prettier)
[error] 386-386: Delete
·
(prettier/prettier)
[error] 387-387: Insert
,
(prettier/prettier)
[error] 391-391: Delete
··
(prettier/prettier)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.
397-431
: Consider moving error mock to common error mocks section.The
errorMocksWithAlreadyJoined
could be moved to the common error mocks section at the top of the file for better organization and reusability.Also, fix the formatting issues to resolve the Prettier warnings:
<TestWrapper mocks={errorMocksWithAlreadyJoined}> - <OrganizationCard - {...defaultProps} - userRegistrationRequired={false} - isJoined={false} - /> + <OrganizationCard + {...defaultProps} + userRegistrationRequired={false} + isJoined={false} + /> </TestWrapper>🧰 Tools
🪛 ESLint
[error] 414-414: Delete
··
(prettier/prettier)
[error] 417-417: Delete
·
(prettier/prettier)
[error] 418-418: Delete
·
(prettier/prettier)
[error] 419-419: Delete
·
(prettier/prettier)
[error] 420-420: Delete
·
(prettier/prettier)
[error] 422-422: Insert
,
(prettier/prettier)
[error] 424-424: Delete
··
(prettier/prettier)
[error] 427-427: Delete
··
(prettier/prettier)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.
Line range hint
269-502
: Overall good test coverage with some improvements needed.The new tests effectively cover various error scenarios, which helps achieve the PR's objective of 100% code coverage. However, there are some consistent issues that should be addressed:
- Run Prettier to fix formatting issues throughout the file
- Fix incorrect assertion syntax (
not.toHaveBeenCalled
→not.toHaveBeenCalled()
)- Verify that all error messages are defined in translations
- Consider organizing error mocks in the common section
Despite these issues, the tests are well-structured and provide good coverage of error scenarios.
🧰 Tools
🪛 ESLint
[error] 352-352: Replace
.spyOn(console,·'error')
with⏎······.spyOn(console,·'error')⏎······
(prettier/prettier)
[error] 353-353: Delete
····
(prettier/prettier)
[error] 357-357: Delete
··
(prettier/prettier)
[error] 364-364: Delete
··
(prettier/prettier)
[error] 374-374: Delete
··
(prettier/prettier)
[error] 378-378: Insert
,
(prettier/prettier)
[error] 380-380: Delete
··
(prettier/prettier)
[error] 383-383: Delete
··
(prettier/prettier)
[error] 386-386: Delete
·
(prettier/prettier)
[error] 387-387: Insert
,
(prettier/prettier)
[error] 391-391: Delete
··
(prettier/prettier)
[error] 396-396: Delete
··
(prettier/prettier)
[error] 414-414: Delete
··
(prettier/prettier)
[error] 417-417: Delete
·
(prettier/prettier)
[error] 418-418: Delete
·
(prettier/prettier)
[error] 419-419: Delete
·
(prettier/prettier)
[error] 420-420: Delete
·
(prettier/prettier)
[error] 422-422: Insert
,
(prettier/prettier)
[error] 424-424: Delete
··
(prettier/prettier)
[error] 427-427: Delete
··
(prettier/prettier)
[error] 432-432: Delete
··
(prettier/prettier)
[error] 433-433: Delete
··
(prettier/prettier)
[error] 434-434: Delete
··
(prettier/prettier)
[error] 435-435: Delete
······
(prettier/prettier)
[error] 436-436: Delete
··
(prettier/prettier)
[error] 437-437: Delete
··
(prettier/prettier)
[error] 438-438: Delete
··
(prettier/prettier)
[error] 439-439: Delete
··
(prettier/prettier)
[error] 440-440: Delete
··
(prettier/prettier)
[error] 441-441: Replace
··{·
with{
(prettier/prettier)
[error] 442-442: Replace
············_id:·'requestId',·
with··········_id:·'requestId',
(prettier/prettier)
[error] 443-443: Replace
··user:·{·
withuser:·{
(prettier/prettier)
[error] 444-444: Replace
··············_id:·'differentUserId'·
with············_id:·'differentUserId',
(prettier/prettier)
[error] 445-445: Replace
··}·
with},
(prettier/prettier)
[error] 446-446: Replace
··········}
with········},
(prettier/prettier)
[error] 447-447: Delete
··
(prettier/prettier)
[error] 448-448: Replace
······
with····
(prettier/prettier)
[error] 449-449: Delete
······
(prettier/prettier)
[error] 450-450: Delete
··
(prettier/prettier)
[error] 451-451: Delete
··
(prettier/prettier)
[error] 452-452: Replace
··········
with········
(prettier/prettier)
[error] 453-453: Replace
··</TestWrapper>
with</TestWrapper>,
(prettier/prettier)
[error] 454-454: Delete
··
(prettier/prettier)
[error] 455-455: Delete
······
(prettier/prettier)
[error] 456-456: Delete
··
(prettier/prettier)
[error] 457-457: Delete
··
(prettier/prettier)
[error] 458-458: Delete
··
(prettier/prettier)
[error] 459-459: Delete
······
(prettier/prettier)
[error] 460-460: Delete
··
(prettier/prettier)
[error] 461-461: Delete
··
(prettier/prettier)
[error] 462-462: Delete
··
(prettier/prettier)
[error] 463-463: Delete
··
(prettier/prettier)
[error] 464-464: Delete
······
(prettier/prettier)
[error] 465-465: Delete
··
(prettier/prettier)
[error] 466-466: Replace
······
with····
(prettier/prettier)
[error] 467-467: Replace
········mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with······(mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 468-468: Delete
··
(prettier/prettier)
[error] 469-469: Delete
··
(prettier/prettier)
[error] 469-469: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 469-469: Matchers must be called to assert
(jest/valid-expect)
[error] 470-472: Replace
··});⏎⏎··
with});
(prettier/prettier)
[error] 477-477: Delete
····
(prettier/prettier)
[error] 483-483: Delete
····
(prettier/prettier)
[error] 487-487: Insert
,
(prettier/prettier)
[error] 489-489: Delete
····
(prettier/prettier)
[error] 492-492: Delete
····
(prettier/prettier)
[error] 496-496: Delete
····
(prettier/prettier)
[error] 498-502: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 500-500: Replace
mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with(mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 501-501: Insert
,
(prettier/prettier)
[error] 502-502: Matchers must be called to assert
(jest/valid-expect)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/OrganizationCard/OrganizationCard.spec.tsx
(2 hunks)
🧰 Additional context used
🪛 ESLint
src/components/OrganizationCard/OrganizationCard.spec.tsx
[error] 269-270: Delete ⏎··
(prettier/prettier)
[error] 352-352: Replace .spyOn(console,·'error')
with ⏎······.spyOn(console,·'error')⏎······
(prettier/prettier)
[error] 353-353: Delete ····
(prettier/prettier)
[error] 357-357: Delete ··
(prettier/prettier)
[error] 364-364: Delete ··
(prettier/prettier)
[error] 374-374: Delete ··
(prettier/prettier)
[error] 378-378: Insert ,
(prettier/prettier)
[error] 380-380: Delete ··
(prettier/prettier)
[error] 383-383: Delete ··
(prettier/prettier)
[error] 386-386: Delete ·
(prettier/prettier)
[error] 387-387: Insert ,
(prettier/prettier)
[error] 391-391: Delete ··
(prettier/prettier)
[error] 396-396: Delete ··
(prettier/prettier)
[error] 414-414: Delete ··
(prettier/prettier)
[error] 417-417: Delete ·
(prettier/prettier)
[error] 418-418: Delete ·
(prettier/prettier)
[error] 419-419: Delete ·
(prettier/prettier)
[error] 420-420: Delete ·
(prettier/prettier)
[error] 422-422: Insert ,
(prettier/prettier)
[error] 424-424: Delete ··
(prettier/prettier)
[error] 427-427: Delete ··
(prettier/prettier)
[error] 432-432: Delete ··
(prettier/prettier)
[error] 433-433: Delete ··
(prettier/prettier)
[error] 434-434: Delete ··
(prettier/prettier)
[error] 435-435: Delete ······
(prettier/prettier)
[error] 436-436: Delete ··
(prettier/prettier)
[error] 437-437: Delete ··
(prettier/prettier)
[error] 438-438: Delete ··
(prettier/prettier)
[error] 439-439: Delete ··
(prettier/prettier)
[error] 440-440: Delete ··
(prettier/prettier)
[error] 441-441: Replace ··{·
with {
(prettier/prettier)
[error] 442-442: Replace ············_id:·'requestId',·
with ··········_id:·'requestId',
(prettier/prettier)
[error] 443-443: Replace ··user:·{·
with user:·{
(prettier/prettier)
[error] 444-444: Replace ··············_id:·'differentUserId'·
with ············_id:·'differentUserId',
(prettier/prettier)
[error] 445-445: Replace ··}·
with },
(prettier/prettier)
[error] 446-446: Replace ··········}
with ········},
(prettier/prettier)
[error] 447-447: Delete ··
(prettier/prettier)
[error] 448-448: Replace ······
with ····
(prettier/prettier)
[error] 449-449: Delete ······
(prettier/prettier)
[error] 450-450: Delete ··
(prettier/prettier)
[error] 451-451: Delete ··
(prettier/prettier)
[error] 452-452: Replace ··········
with ········
(prettier/prettier)
[error] 453-453: Replace ··</TestWrapper>
with </TestWrapper>,
(prettier/prettier)
[error] 454-454: Delete ··
(prettier/prettier)
[error] 455-455: Delete ······
(prettier/prettier)
[error] 456-456: Delete ··
(prettier/prettier)
[error] 457-457: Delete ··
(prettier/prettier)
[error] 458-458: Delete ··
(prettier/prettier)
[error] 459-459: Delete ······
(prettier/prettier)
[error] 460-460: Delete ··
(prettier/prettier)
[error] 461-461: Delete ··
(prettier/prettier)
[error] 462-462: Delete ··
(prettier/prettier)
[error] 463-463: Delete ··
(prettier/prettier)
[error] 464-464: Delete ······
(prettier/prettier)
[error] 465-465: Delete ··
(prettier/prettier)
[error] 466-466: Replace ······
with ····
(prettier/prettier)
[error] 467-467: Replace ········mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with ······(mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 468-468: Delete ··
(prettier/prettier)
[error] 469-469: Delete ··
(prettier/prettier)
[error] 469-469: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 469-469: Matchers must be called to assert
(jest/valid-expect)
[error] 470-472: Replace ··});⏎⏎··
with });
(prettier/prettier)
[error] 477-477: Delete ····
(prettier/prettier)
[error] 483-483: Delete ····
(prettier/prettier)
[error] 487-487: Insert ,
(prettier/prettier)
[error] 489-489: Delete ····
(prettier/prettier)
[error] 492-492: Delete ····
(prettier/prettier)
[error] 496-496: Delete ····
(prettier/prettier)
[error] 498-502: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 500-500: Replace mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with (mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 501-501: Insert ,
(prettier/prettier)
[error] 502-502: Matchers must be called to assert
(jest/valid-expect)
🪛 GitHub Actions: PR Workflow
src/components/OrganizationCard/OrganizationCard.spec.tsx
[warning] Code style issues found. File needs to be formatted using Prettier.
it('should handle membership request not found', async () => { | ||
// Mock getItem to return a userId that exists | ||
mockGetItem.mockReturnValue('testUserId'); | ||
|
||
const props = { | ||
...defaultProps, | ||
membershipRequestStatus: 'pending', | ||
// Create a membership requests array with a different user ID | ||
membershipRequests: [ | ||
{ | ||
_id: 'requestId', | ||
user: { | ||
_id: 'differentUserId' // Different from the mocked userId | ||
} | ||
} | ||
], | ||
}; | ||
|
||
render( | ||
<TestWrapper mocks={successMocks}> | ||
<OrganizationCard {...props} isJoined={false} /> | ||
</TestWrapper> | ||
); | ||
|
||
// Find and click the withdraw button | ||
const withdrawButton = screen.getByTestId('withdrawBtn'); | ||
await fireEvent.click(withdrawButton); | ||
|
||
// Verify that the error toast is shown | ||
await waitFor(() => { | ||
expect(toast.error).toHaveBeenCalledWith('MembershipRequestNotFound'); | ||
}); | ||
|
||
// Verify the mutation was not called | ||
const cancelMutation = successMocks.find( | ||
mock => mock.request.query === CANCEL_MEMBERSHIP_REQUEST | ||
); | ||
expect(cancelMutation?.result).not.toHaveBeenCalled; | ||
}); |
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.
Fix incorrect assertion syntax and formatting issues.
The test has an incorrect assertion syntax and multiple formatting issues that need to be addressed.
const cancelMutation = successMocks.find(
- mock => mock.request.query === CANCEL_MEMBERSHIP_REQUEST
+ (mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST,
);
- expect(cancelMutation?.result).not.toHaveBeenCalled;
+ expect(cancelMutation?.result).not.toHaveBeenCalled();
Also, fix the formatting issues in the membership requests array:
membershipRequests: [
- {
- _id: 'requestId',
- user: {
- _id: 'differentUserId' // Different from the mocked userId
- }
- }
+ {
+ _id: 'requestId',
+ user: {
+ _id: 'differentUserId',
+ },
+ },
],
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
it('should handle membership request not found', async () => { | |
// Mock getItem to return a userId that exists | |
mockGetItem.mockReturnValue('testUserId'); | |
const props = { | |
...defaultProps, | |
membershipRequestStatus: 'pending', | |
// Create a membership requests array with a different user ID | |
membershipRequests: [ | |
{ | |
_id: 'requestId', | |
user: { | |
_id: 'differentUserId' // Different from the mocked userId | |
} | |
} | |
], | |
}; | |
render( | |
<TestWrapper mocks={successMocks}> | |
<OrganizationCard {...props} isJoined={false} /> | |
</TestWrapper> | |
); | |
// Find and click the withdraw button | |
const withdrawButton = screen.getByTestId('withdrawBtn'); | |
await fireEvent.click(withdrawButton); | |
// Verify that the error toast is shown | |
await waitFor(() => { | |
expect(toast.error).toHaveBeenCalledWith('MembershipRequestNotFound'); | |
}); | |
// Verify the mutation was not called | |
const cancelMutation = successMocks.find( | |
mock => mock.request.query === CANCEL_MEMBERSHIP_REQUEST | |
); | |
expect(cancelMutation?.result).not.toHaveBeenCalled; | |
}); | |
it('should handle membership request not found', async () => { | |
// Mock getItem to return a userId that exists | |
mockGetItem.mockReturnValue('testUserId'); | |
const props = { | |
...defaultProps, | |
membershipRequestStatus: 'pending', | |
// Create a membership requests array with a different user ID | |
membershipRequests: [ | |
{ | |
_id: 'requestId', | |
user: { | |
_id: 'differentUserId', | |
}, | |
}, | |
], | |
}; | |
render( | |
<TestWrapper mocks={successMocks}> | |
<OrganizationCard {...props} isJoined={false} /> | |
</TestWrapper> | |
); | |
// Find and click the withdraw button | |
const withdrawButton = screen.getByTestId('withdrawBtn'); | |
await fireEvent.click(withdrawButton); | |
// Verify that the error toast is shown | |
await waitFor(() => { | |
expect(toast.error).toHaveBeenCalledWith('MembershipRequestNotFound'); | |
}); | |
// Verify the mutation was not called | |
const cancelMutation = successMocks.find( | |
(mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST, | |
); | |
expect(cancelMutation?.result).not.toHaveBeenCalled(); | |
}); |
🧰 Tools
🪛 ESLint
[error] 432-432: Delete ··
(prettier/prettier)
[error] 433-433: Delete ··
(prettier/prettier)
[error] 434-434: Delete ··
(prettier/prettier)
[error] 435-435: Delete ······
(prettier/prettier)
[error] 436-436: Delete ··
(prettier/prettier)
[error] 437-437: Delete ··
(prettier/prettier)
[error] 438-438: Delete ··
(prettier/prettier)
[error] 439-439: Delete ··
(prettier/prettier)
[error] 440-440: Delete ··
(prettier/prettier)
[error] 441-441: Replace ··{·
with {
(prettier/prettier)
[error] 442-442: Replace ············_id:·'requestId',·
with ··········_id:·'requestId',
(prettier/prettier)
[error] 443-443: Replace ··user:·{·
with user:·{
(prettier/prettier)
[error] 444-444: Replace ··············_id:·'differentUserId'·
with ············_id:·'differentUserId',
(prettier/prettier)
[error] 445-445: Replace ··}·
with },
(prettier/prettier)
[error] 446-446: Replace ··········}
with ········},
(prettier/prettier)
[error] 447-447: Delete ··
(prettier/prettier)
[error] 448-448: Replace ······
with ····
(prettier/prettier)
[error] 449-449: Delete ······
(prettier/prettier)
[error] 450-450: Delete ··
(prettier/prettier)
[error] 451-451: Delete ··
(prettier/prettier)
[error] 452-452: Replace ··········
with ········
(prettier/prettier)
[error] 453-453: Replace ··</TestWrapper>
with </TestWrapper>,
(prettier/prettier)
[error] 454-454: Delete ··
(prettier/prettier)
[error] 455-455: Delete ······
(prettier/prettier)
[error] 456-456: Delete ··
(prettier/prettier)
[error] 457-457: Delete ··
(prettier/prettier)
[error] 458-458: Delete ··
(prettier/prettier)
[error] 459-459: Delete ······
(prettier/prettier)
[error] 460-460: Delete ··
(prettier/prettier)
[error] 461-461: Delete ··
(prettier/prettier)
[error] 462-462: Delete ··
(prettier/prettier)
[error] 463-463: Delete ··
(prettier/prettier)
[error] 464-464: Delete ······
(prettier/prettier)
[error] 465-465: Delete ··
(prettier/prettier)
[error] 466-466: Replace ······
with ····
(prettier/prettier)
[error] 467-467: Replace ········mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with ······(mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 468-468: Delete ··
(prettier/prettier)
[error] 469-469: Delete ··
(prettier/prettier)
[error] 469-469: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 469-469: Matchers must be called to assert
(jest/valid-expect)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.
it('should handle withdrawal attempt with no userId', async () => { | ||
// Mock getItem to return null to simulate no userId | ||
mockGetItem.mockReturnValue(null); | ||
|
||
const props = { | ||
...defaultProps, | ||
membershipRequestStatus: 'pending', | ||
membershipRequests: [{ _id: 'requestId', user: { _id: 'mockUserId' } }], | ||
}; | ||
|
||
render( | ||
<TestWrapper mocks={successMocks}> | ||
<OrganizationCard {...props} isJoined={false} /> | ||
</TestWrapper> | ||
); | ||
|
||
const withdrawButton = screen.getByTestId('withdrawBtn'); | ||
await fireEvent.click(withdrawButton); | ||
|
||
await waitFor(() => { | ||
expect(toast.error).toHaveBeenCalledWith('MembershipRequestNotFound'); | ||
expect(toast.error).toHaveBeenCalledWith('UserIdNotFound'); | ||
}); | ||
|
||
// Verify that the cancelMembershipRequest mutation was not called | ||
expect( | ||
successMocks.find( | ||
mock => mock.request.query === CANCEL_MEMBERSHIP_REQUEST | ||
)?.result | ||
).not.toHaveBeenCalled; |
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.
💡 Codebase verification
Fix assertion syntax and use proper translation key for error message
The test has two issues that need to be addressed:
- Incorrect assertion syntax (missing parentheses)
- Using non-existent translation key 'UserIdNotFound'
expect(
successMocks.find(
(mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST
)?.result
- ).not.toHaveBeenCalled;
+ ).not.toHaveBeenCalled();
await waitFor(() => {
- expect(toast.error).toHaveBeenCalledWith('UserIdNotFound');
+ expect(toast.error).toHaveBeenCalledWith('notFound');
});
Consider using an existing translation key like 'notFound' or add a new specific translation key for this error case in the translation files.
🔗 Analysis chain
Fix assertion syntax and verify error message translation.
The test has multiple issues that need to be addressed:
- Incorrect assertion syntax
- The error message 'UserIdNotFound' might not be defined in the translations
expect(
successMocks.find(
- mock => mock.request.query === CANCEL_MEMBERSHIP_REQUEST
+ (mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST,
)?.result
- ).not.toHaveBeenCalled;
+ ).not.toHaveBeenCalled();
Let's verify if the error message is defined in the translations:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for 'UserIdNotFound' in translation files
rg -l "UserIdNotFound" --type json
Length of output: 34
Script:
#!/bin/bash
# First, let's find all potential translation/locale files
echo "=== Searching for translation files ==="
fd -e json -e yaml -e yml . | grep -iE 'translation|locale|i18n|lang'
echo -e "\n=== Searching for similar message patterns ==="
# Search for various forms of the message
rg -i "userid.*not.*found|user.*id.*not.*found|user_id_not_found" --type json --type ts --type tsx
echo -e "\n=== Looking for message constants ==="
# Search for message definitions in TypeScript/JavaScript files
ast-grep --pattern 'const $_ = $$$"UserIdNotFound"$$$'
Length of output: 1021
Script:
#!/bin/bash
# Check content of error translation files
echo "=== Content of English error translations ==="
cat public/locales/en/errors.json
echo -e "\n=== Searching for any user-related error messages ==="
rg -i "user" public/locales/en/errors.json
Length of output: 1245
🧰 Tools
🪛 ESLint
[error] 477-477: Delete ····
(prettier/prettier)
[error] 483-483: Delete ····
(prettier/prettier)
[error] 487-487: Insert ,
(prettier/prettier)
[error] 489-489: Delete ····
(prettier/prettier)
[error] 492-492: Delete ····
(prettier/prettier)
[error] 496-496: Delete ····
(prettier/prettier)
[error] 498-502: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
[error] 500-500: Replace mock·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST
with (mock)·=>·mock.request.query·===·CANCEL_MEMBERSHIP_REQUEST,
(prettier/prettier)
[error] 501-501: Insert ,
(prettier/prettier)
[error] 502-502: Matchers must be called to assert
(jest/valid-expect)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.
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: 0
🧹 Nitpick comments (3)
src/components/OrganizationCard/OrganizationCard.spec.tsx (3)
366-374
: Consider usingerrorPolicy
in error mock for better Apollo Client integration.The current error mock might not accurately represent how Apollo Client handles errors. Consider using the
result
field witherrors
array instead:const errorMocks: MockedResponse[] = [ { request: { query: CANCEL_MEMBERSHIP_REQUEST, variables: { membershipRequestId: 'requestId' }, }, - error: new Error('Withdrawal failed'), + result: { + errors: [ + { + message: 'Withdrawal failed', + extensions: { code: 'WITHDRAWAL_FAILED' }, + }, + ], + }, }, ];
399-414
: Simplify error mock setup using a helper function.Consider extracting the error mock setup to a helper function for better reusability and readability:
+const createGraphQLErrorMock = (query: any, variables: any, message: string, code: string) => ({ + request: { query, variables }, + result: { + errors: [ + { + message, + extensions: { code }, + }, + ], + }, +}); -const errorMocksWithAlreadyJoined: MockedResponse[] = [ - { - request: { - query: JOIN_PUBLIC_ORGANIZATION, - variables: { organizationId: '123' }, - }, - result: { - errors: [ - { - message: 'Already a member', - extensions: { code: 'ALREADY_MEMBER' }, - }, - ], - }, - }, -]; +const errorMocksWithAlreadyJoined: MockedResponse[] = [ + createGraphQLErrorMock( + JOIN_PUBLIC_ORGANIZATION, + { organizationId: '123' }, + 'Already a member', + 'ALREADY_MEMBER' + ), +];
Line range hint
350-502
: Consider restructuring error handling tests for better organization.The error handling tests could be better organized under a dedicated describe block:
+ describe('Error Handling', () => { + describe('Membership Withdrawal', () => { it('should log development error and show generic error toast', async () => { // ... existing test }); it('should handle withdrawal attempt with no userId', async () => { // ... existing test }); }); + describe('Organization Joining', () => { it('should handle already joined error when joining organization', async () => { // ... existing test }); it('should handle membership request not found', async () => { // ... existing test }); }); });This structure:
- Groups related error scenarios together
- Makes it easier to find and maintain error-related tests
- Provides better context for each test case
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/OrganizationCard/OrganizationCard.spec.tsx
(2 hunks)
🔇 Additional comments (2)
src/components/OrganizationCard/OrganizationCard.spec.tsx (2)
433-471
:⚠️ Potential issueFix formatting issues and assertion syntax.
The test has several issues that need to be addressed:
- Fix the formatting issues:
membershipRequestStatus: 'pending', - // Create a membership requests array with a different user ID membershipRequests: [ { _id: 'requestId', user: { - _id: 'differentUserId', // Different from the mocked userId + _id: 'differentUserId', }, }, ],
- Fix the assertion syntax:
const cancelMutation = successMocks.find( (mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST, ); - expect(cancelMutation?.result).not.toHaveBeenCalled(); + expect(cancelMutation?.result).not.toHaveBeenCalled();
- Remove unnecessary comments that don't add value to the test's readability.
Likely invalid or redundant comment.
473-502
:⚠️ Potential issueFix error message key and assertion syntax.
The test has several issues that need to be addressed:
- Use an existing translation key for the error message:
await waitFor(() => { - expect(toast.error).toHaveBeenCalledWith('UserIdNotFound'); + expect(toast.error).toHaveBeenCalledWith('notFound'); });
- Fix the assertion syntax:
expect( successMocks.find( (mock) => mock.request.query === CANCEL_MEMBERSHIP_REQUEST, - )?.result, - ).not.toHaveBeenCalled(); + )?.result + ).not.toHaveBeenCalled();Likely invalid or redundant comment.
What kind of change does this PR introduce?
Achieved 100% Code Coverage for OrganizationCard Component
Issue Number: 3459
Snapshots/Videos:
Does this PR introduce a breaking change?
No, this PR does not introduce a breaking chan
Checklist
CodeRabbit AI Review
Test Coverage
Other information
Have you read the contributing guide?
Summary by CodeRabbit
OrganizationCard
component.