-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1147 add feature to resend new user emails (#1343)
Signed-off-by: Hristiyan <[email protected]> Signed-off-by: Svetoslav Borislavov <[email protected]> Co-authored-by: Svetoslav Borislavov <[email protected]>
- Loading branch information
1 parent
8e6b4bb
commit 2aca253
Showing
6 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -950,6 +950,10 @@ The Initial Developer of [email protected], | |
is David Mark Clements (https://github.com/davidmarkclements/atomic-sleep). | ||
Copyright David Mark Clements. All Rights Reserved. | ||
|
||
The Initial Developer of [email protected], | ||
is Matt Zabriskie (https://github.com/axios/axios). | ||
Copyright Matt Zabriskie. All Rights Reserved. | ||
|
||
The Initial Developer of [email protected], | ||
is Matt Zabriskie (https://github.com/axios/axios). | ||
Copyright Matt Zabriskie. All Rights Reserved. | ||
|
This file contains 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 |
---|---|---|
|
@@ -84,15 +84,31 @@ describe('AuthController', () => { | |
expect(await controller.signUp({ email: '[email protected]' }, request)).toBe(result); | ||
}); | ||
|
||
it('should throw an error if the user already exists', async () => { | ||
it('should throw an error if the user already exists or return an updated user if it exists but its status is NEW', async () => { | ||
jest.mocked(request.get).mockImplementationOnce(() => 'localhost'); | ||
jest | ||
.spyOn(controller, 'signUp') | ||
.mockRejectedValue(new UnprocessableEntityException('Email already exists.')); | ||
|
||
.spyOn(authService, 'signUpByAdmin') | ||
.mockRejectedValueOnce(new UnprocessableEntityException('Email already exists.')); | ||
await expect(controller.signUp({ email: '[email protected]' }, request)).rejects.toThrow( | ||
'Email already exists.', | ||
); | ||
|
||
jest.spyOn(authService, 'signUpByAdmin').mockResolvedValueOnce({ | ||
id: 1, | ||
email: '[email protected]', | ||
status: UserStatus.NEW, | ||
password: 'newHashedPassword', | ||
} as User); | ||
|
||
const result = await controller.signUp({ email: '[email protected]' }, request); | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
email: '[email protected]', | ||
status: UserStatus.NEW, | ||
password: 'newHashedPassword', | ||
}), | ||
); | ||
}); | ||
|
||
it('should throw an error if no email is supplied', async () => { | ||
|
This file contains 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 |
---|---|---|
|
@@ -135,6 +135,39 @@ describe('AuthService', () => { | |
); | ||
}); | ||
|
||
it('should update the password and resend an email for an existing user with status NEW', async () => { | ||
const dto: SignUpUserDto = { email: '[email protected]' }; | ||
|
||
jest.spyOn(userService, 'getUser').mockResolvedValue({ | ||
id: 1, | ||
email: dto.email, | ||
status: UserStatus.NEW, | ||
deletedAt: null, | ||
} as User); | ||
|
||
jest.spyOn(userService, 'getSaltedHash').mockResolvedValue('hashedPassword'); | ||
|
||
jest.spyOn(userService, 'updateUserById').mockResolvedValue({ | ||
id: 1, | ||
email: dto.email, | ||
status: UserStatus.NEW, | ||
password: 'hashedPassword', | ||
} as User); | ||
|
||
await service.signUpByAdmin(dto, 'http://localhost'); | ||
|
||
expect(userService.getUser).toHaveBeenCalledWith({ email: dto.email }, true); | ||
|
||
expect(userService.getSaltedHash).toHaveBeenCalledWith(expect.any(String)); | ||
|
||
expect(userService.updateUserById).toHaveBeenCalledWith(1, { password: 'hashedPassword' }); | ||
|
||
expect(notificationsService.emit).toHaveBeenCalledWith( | ||
'notify_email', | ||
expect.objectContaining({ email: dto.email }), | ||
); | ||
}); | ||
|
||
it('should login user', async () => { | ||
const { user } = await invokeLogin(false); | ||
|
||
|
This file contains 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 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 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