Repository navigation
fix(#641): trim member full name before persistence #798
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
Open
IrynaLypnyk
wants to merge
5
commits into
Women-Coding-Community:main
Choose a base branch
from
IrynaLypnyk:fix/641-trim-member-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39e9d8c
fix(#641): trim member full name before persistence
IrynaLypnyk a932fb5
fix(#641): trim member full name in create form
IrynaLypnyk b44a243
chore(#641): remove unrelated import changes
IrynaLypnyk 82732af
Merge remote-tracking branch 'upstream/main' into fix/641-trim-member…
IrynaLypnyk 842ffe6
fix(#641): trim member Slack display name
IrynaLypnyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
admin-wcc-app/__tests__/pages/admin/members/create.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import '@testing-library/jest-dom'; | ||
| import { render, screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import CreateMemberPage from '@/pages/admin/members/create'; | ||
| import * as api from '@/lib/api'; | ||
| import * as AuthProvider from '@/components/AuthProvider'; | ||
| import mockRouter from 'next-router-mock'; | ||
|
|
||
| jest.mock('next/router', () => jest.requireActual('next-router-mock')); | ||
| jest.mock('@/lib/api'); | ||
| jest.mock('@/components/AuthProvider'); | ||
| jest.mock('@/lib/auth', () => ({ | ||
| getStoredToken: jest.fn(() => 'mock-token'), | ||
| })); | ||
|
|
||
| global.scrollTo = jest.fn(); | ||
|
|
||
| const mockApiFetch = api.apiFetch as jest.MockedFunction<typeof api.apiFetch>; | ||
| const mockUseAuth = AuthProvider.useAuth as jest.Mock; | ||
|
|
||
| describe('CreateMemberPage', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockRouter.setCurrentUrl('/admin/members/create'); | ||
|
|
||
| mockUseAuth.mockReturnValue({ | ||
| token: 'mock-token', | ||
| roles: ['ADMIN'], | ||
| member: null, | ||
| logout: jest.fn(), | ||
| }); | ||
| }); | ||
|
|
||
| const fillRequiredFields = async (user: ReturnType<typeof userEvent.setup>) => { | ||
| await user.type(screen.getByLabelText(/full name/i), ' Jane Doe '); | ||
| await user.type(screen.getByLabelText(/email/i), 'jane@example.com'); | ||
| await user.type(screen.getByLabelText(/position/i), 'Developer'); | ||
| await user.type(screen.getByLabelText(/slack display name/i), ' jane doe '); | ||
|
|
||
| const countryInput = screen.getByLabelText(/country/i); | ||
| await user.click(countryInput); | ||
| await user.type(countryInput, 'United'); | ||
|
|
||
| const countryOption = await screen.findByRole('option', { | ||
| name: /united states \(us\)/i, | ||
| }); | ||
| await user.click(countryOption); | ||
|
|
||
| const memberTypesInput = screen.getByLabelText(/member types/i); | ||
| await user.click(memberTypesInput); | ||
|
|
||
| const memberOption = await screen.findByRole('option', { | ||
| name: /^member$/i, | ||
| }); | ||
| await user.click(memberOption); | ||
| }; | ||
|
|
||
| it('trims full name and Slack display name before submitting member data', async () => { | ||
| mockApiFetch.mockResolvedValueOnce({}); | ||
|
|
||
| const user = userEvent.setup(); | ||
|
|
||
| render(<CreateMemberPage />); | ||
| await fillRequiredFields(user); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /create member/i })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockApiFetch).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| const payload = mockApiFetch.mock.calls[0][1]?.body; | ||
|
|
||
| expect(payload).toMatchObject({ | ||
| fullName: 'Jane Doe', | ||
| slackDisplayName: 'jane doe', | ||
| }); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['full name', /full name/i, 'Full name is required'], | ||
| ['Slack display name', /slack display name/i, 'Slack display name is required'], | ||
| ])('rejects a whitespace-only %s', async (_field, label, message) => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| render(<CreateMemberPage />); | ||
|
|
||
| await fillRequiredFields(user); | ||
| const input = screen.getByLabelText(label); | ||
| await user.clear(input); | ||
| await user.type(input, ' '); | ||
| await user.click(screen.getByRole('button', { name: /create member/i })); | ||
|
|
||
| expect(await screen.findByText(message)).toBeInTheDocument(); | ||
| expect(mockApiFetch).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of adding this "StringUtils.trim()" this should be handled at the time of deserialization. And then for the fields we do not need the Trim can have custom annotation say - NoTrim can be used if we do not want to strip the leading/trailing spaces.
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.
Hi @Sowmiya07 and @goelsonali
@Sowmiya07, you mentioned collecting the other fields that need trimming. @goelsonali, you suggested a global trimming deserializer.
That approach would trim JSON string values across the API, with explicit opt-outs for passwords and other whitespace-sensitive fields, so it broadens the scope beyond member names.
Could you confirm whether you’d prefer to keep this PR focused on member fields and introduce the global deserializer in a follow-up, or include it here?
In the meantime, I’ve addressed Slack display name trimming and validation in the admin form.