In this video we're going to write out a couple of tests around our sign and request handler.
Now we're not gonna really run into anything too interesting around these tests.
It's gonna be pretty much pretty similar to what we just went through for sign up.
So if you are already bored with testing that is fine.
You can feel free to skip over this video otherwise stick around.
We're gonna write out just one or two quick tests just to make sure that this thing works correctly.
So let's get to it.
We're going to once again follow the same pattern of the creation of the test file.
So because we want to make a test around a sign and t us we'll go into the same directory find the underscore
underscore test folder and side there.
I'll make a new file called sign in not test thought to us at the very top then put in the exact same
boilerplate we had in the last test file so we'll import request from two protests and our app from
up to directories at All right let's very quickly open up that sign in root handler and try to figure
out what we should really be trying to test inside of here.
Well we could write out some more tests around making sure that we've got some validation put together.
If you want to do that I will leave it up to you.
You can really just take the exact same tests that we wrote or the last drought handler and move them
over.
The only thing you'll need to change is we don't really have any requirements around the password being
of some particular length.
So just keep in mind that if you copy paste those tests over you might have to update some tests around
validation of the password so the things we might attempt to test is to make sure that if we tried to
log in as someone who has never signed up before or essentially with an email that's never been used
and we should probably see a response with this as go to 400.
We should also probably tried to sign in with an incorrect password and expect to also see a 400.
And then finally if we attempt to sign in with some legit credentials then we should once again see
that's that cookie in the header.
So let's try to write out some tests for those three cases the case in which we reuse an email in which
we use an email that does not exist and in which everything goes successful.
So the very first one we'll say it fails when a.
Email that does not exist is supplied
to then inside of your we will do and await we'll make a request to our app.
We're going to do a post request to API.
I mean look up that root handler.
I can remember if we call the author users.
Looks like it's users API users sign in and we'll send along whatever email and whatever password they
just have to be valid then we will expect to get back to 400 because we are trying to sign in with an
account that does not exist.
Let's save that.
We'll go back over to our terminal.
You'll notice that now we've got a second file inside of here and it looks like all the tests inside
of that sign and test out to yes file are now working correctly.
Very good.
All right.
Now the next one we'll do.
We're going to attempt to sign into an existing account with the incorrect password.
So we'll do another it block and I'll say it fails when an incorrect password is supplied
now in this case we need to make sure first that there is actually an account for us to sign into.
So we need to first go over to our sign up Route read a new account and then attempt to sign into it
with an incorrect password.
So in this case we'll do and await request over to app.
We'll make a post to API users sign up.
In this case we'll send along some valid credentials
and I will expect that after signing up with these valid credentials I get back to a one because remember
that's what we sent back after someone signs up for an account
then after that we're going to attempt to sign in.
We also want to make sure we collect the response that comes back and we're going to inspect that response
and make sure that there is some set cookie header on there.
So we will do a a wait
request with that we'll make a post to API users sign in.
In this case we're going to send along the same email but an incorrect password they'll put in some
gibberish like so and then I'm going to expect to get a four hundred back.
Let's say that look back over
and looks good OK so now let's just do one more.
We're gonna handle a case in which we sign up for an account and then attempt to sign in with a correct
password.
And again on the response we get back in the sign in we should be able to take that response and say
that we've got some actual cookie being set we'll do it responds with a cookie when given the valid
credentials
so for this we can save a little bit of time by just taking everything out of the body of the previous
test.
It's going to take the sign up and the sign and stuff are gonna paste it down inside this new test make
some indentation I'm gonna make sure that the sign in request right here has the valid password or the
correct password so my correct password is password.
So update that string I'll make sure I update that status code right there because now that we're providing
a correct password I'm going to expect to get back a response of the 200 and then finally we're going
to get the response and we're going to make sure that that set cookie header is defined so we'll do
another expect response dot get set cookie to be defined.
All right.
Another save.
Now they're flip over to our terminal and after a brief pause we are good to go well it's fantastic.
So let's take a quick pause right here and move on to testing our next round handler.