-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): Add test cases for forget password flow and password res…
…et functionality
- Loading branch information
1 parent
7dd105b
commit b70dfea
Showing
6 changed files
with
130 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
expectBadRequestResponseForValidationError, | ||
expectFindUserByUsernameSuccess, | ||
expectForgetPasswordSuccess, | ||
expectLoginFailed, | ||
expectLoginSuccess, | ||
expectOTPVerificationSuccess, | ||
expectResetPasswordSuccess, | ||
expectSignUpSuccess, | ||
findUserByUsername, | ||
forgetPassword, | ||
login, | ||
resetPassword, | ||
retrieveOTP, | ||
signUp, | ||
verifyAccount, | ||
verifyOTP, | ||
} from '@/utils/test'; | ||
import { Response } from 'supertest'; | ||
import { GetUser } from '../../user/user.validation'; | ||
|
||
const user = { | ||
username: 'username', | ||
email: 'validemail@example.com', | ||
password: 'ValidPassword123!', | ||
confirmPassword: 'ValidPassword123!', | ||
}; | ||
|
||
describe('Reset Password', () => { | ||
let verifiedOTPResponse: Response; | ||
|
||
beforeAll(async () => { | ||
const response = await signUp(user); | ||
expectSignUpSuccess(response); | ||
|
||
verifyAccount(user); | ||
}); | ||
|
||
it('should throw error if token, password, confirmPassword is not provided', async () => { | ||
const res = await resetPassword({ token: '', password: '', confirmPassword: '' }); | ||
expectBadRequestResponseForValidationError(res); | ||
}); | ||
|
||
it('should throw error if token is invalid', async () => { | ||
const res = await resetPassword({ token: 'a', password: 'a', confirmPassword: 'a' }); | ||
expectBadRequestResponseForValidationError(res); | ||
}); | ||
|
||
it('should throw error if password and confirmPassword do not match', async () => { | ||
const res = await resetPassword({ token: 'a', password: 'a', confirmPassword: 'b' }); | ||
expectBadRequestResponseForValidationError(res); | ||
}); | ||
|
||
it('should verify OTP successfully', async () => { | ||
const res = await forgetPassword(user.email); | ||
expectForgetPasswordSuccess(res); | ||
|
||
const userResponse = await findUserByUsername(user.username); | ||
expectFindUserByUsernameSuccess(userResponse, user); | ||
const userDetails: GetUser = userResponse.body.user; | ||
|
||
const otpData = await retrieveOTP(userDetails.id, 'sendForgetPasswordOTP'); | ||
verifiedOTPResponse = await verifyOTP(otpData, user.email); | ||
expectOTPVerificationSuccess(verifiedOTPResponse); | ||
}); | ||
|
||
it('should reset password successfully', async () => { | ||
const { token } = verifiedOTPResponse.body; | ||
|
||
const res = await resetPassword({ token, password: 'ValidPassword123@', confirmPassword: 'ValidPassword123@' }); | ||
expectResetPasswordSuccess(res); | ||
}); | ||
|
||
it('should not login with old password', async () => { | ||
const res = await login(user); | ||
expectLoginFailed(res); | ||
}); | ||
|
||
it('should login with new password', async () => { | ||
const res = await login({ ...user, password: 'ValidPassword123@' }); | ||
expectLoginSuccess(res); | ||
}); | ||
}); |
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
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