Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/api/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The country object in the dto includes both code and isoAlpha3Code. Ensure that the isoAlpha3Code is always provided and validated, as missing or incorrect values could lead to incorrect data being stored.

},
};

await service.registerUser(dto);

expect(mockMemberPrisma.member.create).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
homeCountryCode: 'USA',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
Consider adding validation to ensure that homeCountryCode and competitionCountryCode are correctly set to valid ISO Alpha-3 codes. This will prevent potential data integrity issues.

competitionCountryCode: 'USA',
}),
}),
);
});

it('should throw BadRequestException for missing handle, email, or password', async () => {
await expect(
service.registerUser({
Expand Down
7 changes: 7 additions & 0 deletions src/api/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The validateString method is used to check if userParams.country?.isoAlpha3Code is valid. Ensure that validateString correctly handles all edge cases, such as empty strings or unexpected input types, to prevent potential issues with setting homeCountryCode and competitionCountryCode to null inadvertently.

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,
Expand Down
Loading