In my authentication service based on React and Node.js, the password reset feature is divided in two parts. One consists in password reset link. Second is to use the link to change the password. This video shows the second part and how i'm testing it using Sinon and Mocha.
Category
🦄
CreativityTranscript
00:00In MyAuthenticationService, the password reset process is divided into two parts.
00:12First, the user must request a password reset link by using the email here and click on this button.
00:25After these actions, the user will receive a password reset link by email like this.
00:41Now it's time for the second part of password reset.
00:49The user should enter a new password, which will replace the previous one, and the password was changed.
01:15In the previous video, I explained how I tested the password reset request.
01:24Now I will show how I'm testing the password change using the link.
01:33And this is the function used for password change.
01:41Here I'm extracting the code used to identify the user.
01:50And this is the new password.
01:56Next, I'm trying to extract the user ID from the code.
02:07And here I'm trying to update the user password using the user ID.
02:21To test this function, I have created in my test file two tabs.
02:32One to substitute the method to decode the code and extract the user ID.
02:47And the second to substitute this method, which is updating the user password.
03:06These tabs will replace the real methods with a fake function.
03:14And here I'm specifying what will return this code when it will be tested.
03:27And this will return a true value.
03:35That means the user password was updated.
03:40And when I will call the change password function, I will provide two mocks.
03:57One for the express request object and the second for the express response object.
04:15Finally, I'm verifying if the response is as expected.
04:26This test case is for success password change.
04:33If I want to test a failed password change,
04:41I will provide two different passwords.
05:11Now, let's run a test.
05:41Anything is working as expected.