-
Notifications
You must be signed in to change notification settings - Fork 5
Fix for storing country at registration #24
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1145,6 +1145,28 @@ describe('UserService', () => { | |
| expect(result).toEqual(mockCreatedUser); | ||
| }); | ||
|
|
||
| it('should store isoAlpha3Code for home and competition country codes', async () => { | ||
| const dto: CreateUserBodyDto = { | ||
| param: { | ||
| ...createUserDto.param, | ||
| handle: 'countryuser', | ||
| email: 'countryuser@example.com', | ||
| country: { code: 'US', isoAlpha3Code: 'USA' }, | ||
| }, | ||
| }; | ||
|
|
||
| await service.registerUser(dto); | ||
|
|
||
| expect(mockMemberPrisma.member.create).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| data: expect.objectContaining({ | ||
| homeCountryCode: 'USA', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| competitionCountryCode: 'USA', | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should throw BadRequestException for missing handle, email, or password', async () => { | ||
| await expect( | ||
| service.registerUser({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -999,12 +999,19 @@ export class UserService { | |
| // Create the member record outside of the interactive transaction | ||
| // to avoid cross-client work while a Prisma transaction is open | ||
| try { | ||
| const isoAlpha3Code = CommonUtils.validateString( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| userParams.country?.isoAlpha3Code, | ||
| ) | ||
| ? userParams.country?.isoAlpha3Code | ||
| : null; | ||
| await this.memberPrisma.member.create({ | ||
| data: { | ||
| userId: Number(nextUserId), | ||
| handle: userParams.handle, | ||
| handleLower: userParams.handle.toLowerCase(), | ||
| email: userParams.email, | ||
| homeCountryCode: isoAlpha3Code, | ||
| competitionCountryCode: isoAlpha3Code, | ||
| tracks: [], | ||
| createdBy: String(nextUserId), | ||
| firstName: userParams.firstName ?? null, | ||
|
|
||
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.
[⚠️
correctness]The
countryobject in thedtoincludes bothcodeandisoAlpha3Code. Ensure that theisoAlpha3Codeis always provided and validated, as missing or incorrect values could lead to incorrect data being stored.