Skip to content

Commit ccc8a99

Browse files
authored
BC-11143 - validate account during registration completion (#6016)
1 parent e5e0609 commit ccc8a99

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

apps/server/src/modules/registration/domain/service/registration.service.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('RegistrationService', () => {
2929
let userService: DeepMocked<UserService>;
3030
let mailService: DeepMocked<MailService>;
3131
let logger: DeepMocked<Logger>;
32+
let accountService: DeepMocked<AccountService>;
3233

3334
beforeAll(async () => {
3435
module = await Test.createTestingModule({
@@ -77,6 +78,7 @@ describe('RegistrationService', () => {
7778
schoolService = module.get(SchoolService);
7879
mailService = module.get(MailService);
7980
logger = module.get(Logger);
81+
accountService = module.get(AccountService);
8082
});
8183

8284
afterAll(async () => {
@@ -317,6 +319,11 @@ describe('RegistrationService', () => {
317319
const registration = registrationFactory.build();
318320
registrationRepo.findBySecret.mockResolvedValue(registration);
319321

322+
userService.save.mockImplementation((user) => {
323+
user.id = new ObjectId().toHexString();
324+
return Promise.resolve(user);
325+
});
326+
320327
await service.completeRegistration(registration, LanguageType.EN, 'SecurePassword123!');
321328

322329
expect(userService.save).toHaveBeenCalledWith(
@@ -326,6 +333,13 @@ describe('RegistrationService', () => {
326333
lastName: registration.lastName,
327334
})
328335
);
336+
337+
expect(accountService.saveWithValidation).toHaveBeenCalledWith(
338+
expect.objectContaining({
339+
username: registration.email,
340+
password: 'SecurePassword123!',
341+
})
342+
);
329343
});
330344

331345
describe('when external person role is missing', () => {

apps/server/src/modules/registration/domain/service/registration.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class RegistrationService {
4747
const userDo = await this.createUser(registration, language);
4848
const user = await this.userService.save(userDo);
4949
const account = this.createAccount(user, password);
50-
await this.accountService.save(account);
50+
await this.accountService.saveWithValidation(account);
5151

5252
if (user.id === undefined) {
5353
throw new InternalServerErrorException('User ID is undefined after saving user.');

0 commit comments

Comments
 (0)