feat(auth): #127 forgot-password + reset-password API (BDD + mail)
Made-with: Cursor
This commit is contained in:
@@ -9,6 +9,8 @@ describe('AuthController', () => {
|
||||
const authServiceMock = {
|
||||
verifyCreatePasswordToken: jest.fn(),
|
||||
createPasswordWithToken: jest.fn(),
|
||||
requestPasswordReset: jest.fn(),
|
||||
resetPasswordWithResetToken: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -70,4 +72,39 @@ describe('AuthController', () => {
|
||||
});
|
||||
expect(authServiceMock.createPasswordWithToken).toHaveBeenCalledWith('tok-123', 'Password1');
|
||||
});
|
||||
|
||||
it('forgot-password délègue au service et renvoie le message générique', async () => {
|
||||
authServiceMock.requestPasswordReset.mockResolvedValue({
|
||||
message: 'Si cette adresse est associée…',
|
||||
});
|
||||
await expect(controller.forgotPassword({ email: 'user@test.fr' })).resolves.toEqual({
|
||||
message: 'Si cette adresse est associée…',
|
||||
});
|
||||
expect(authServiceMock.requestPasswordReset).toHaveBeenCalledWith('user@test.fr');
|
||||
});
|
||||
|
||||
it('rejects reset-password when confirmation mismatches', async () => {
|
||||
await expect(
|
||||
controller.resetPassword({
|
||||
token: 'tok',
|
||||
password: 'Password1',
|
||||
password_confirmation: 'Password2',
|
||||
}),
|
||||
).rejects.toThrow(BadRequestException);
|
||||
expect(authServiceMock.resetPasswordWithResetToken).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls reset-password when payload is valid', async () => {
|
||||
authServiceMock.resetPasswordWithResetToken.mockResolvedValue({
|
||||
message: 'Mot de passe mis à jour.',
|
||||
});
|
||||
await expect(
|
||||
controller.resetPassword({
|
||||
token: 'tok-123',
|
||||
password: 'Password1',
|
||||
password_confirmation: 'Password1',
|
||||
}),
|
||||
).resolves.toEqual({ message: 'Mot de passe mis à jour.' });
|
||||
expect(authServiceMock.resetPasswordWithResetToken).toHaveBeenCalledWith('tok-123', 'Password1');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user