Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Test the confirmedPassword
attribute added to the User model and the VIRTUAL
data type change made to the password
attribute.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now it's time to test
the confirmedPassword attribute
0:00
added to the user model,
0:03
as well as the virtual data type
change made to the password attribute.
0:05
If the confirmedPassword and
password values match, the setter and
0:09
confirmedPassword should hash
the password and set the value to store.
0:14
And, setting passwords datatype to virtual
0:19
should prevent the unhatched password
from being stored in the database.
0:22
In Postman, our first test sending a POST
request with passwords that do not match
0:27
I get a 400 status with the error both
passwords must match in the response.
0:37
Now I'll make sure that
the password's match.
0:44
This time, I receive a 201 Created
status code with the message,
0:49
Account successfully
created in the response.
0:53
Sending a GET request to the API
users route returns the new user and
0:58
notice how confirmedPassword
displays the hash password value.
1:03
And it's the only password
field we get back.
1:08
The virtual password field never
gets inserted into the database.
1:11
All right, excellent work writing
the validations, constraints, and
1:15
custom error messages for the user model.
1:20
Now you can apply what you've
learned in this workshop
1:22
to just about all your Sequelize
models moving forward.
1:25
Be sure to review and
1:28
try out some of the other validators
listed in the Sequelize docs.
1:29
I've posted the resource in
the teachers notes with this video.
1:32
Happy coding everyone.
1:35
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up