In this video we're going to try to write out a test or two around these sign out functionality.
Now once again just like the last video we're not really going to see anything that new in the world
of testing.
So if you really just want to get on to some the more interesting stuff.
Skip to the next video once again.
Otherwise stick around and let's write out a single test around these sign out root handler so once
again inside my test directory I'll make a new file of sign out that test out.
Yes at the top we will import request from two protest and app from up to directories at.
So as you guess all we really want to do here is attempt to sign up for an account.
Once we sign up we should be it logged in.
And then after that we'll make a another request to sign out and we should be able to make a assertion
on the response we get back.
Something to say that the cookie has been cleared or something like that.
We'll probably have to inspect the actual response that gets sent back to figure out exactly how to
write out this expectation.
Let's just get started writing out the test first put together in its statements out of here.
We'll say it.
Here's the cookie.
After signing out
inside of here again we need to first sign up for an account so that we are authenticated.
We'll do in a wait.
Request over to app.
I'll make a post to API users sign up and we'll send off an email that is valid and a password that
is valid as well.
And then once again we will make sure that we get back a status code of not one but two a one.
So again this is just gonna make sure that we are successfully signed up.
Then after that we will make our request.
It's going to be a post request to API users sign out.
And again on the response we should be able to inspect that set cookie header and figure out exactly
what gets sent back when when we sign out we'll have to console log that thing to figure out exactly
how we should write that assertion we'll do a concert response is a weight request to app.
We'll do a post in this case to API users sign out in this case
we're gonna send along an anti object because it is a post request and then we will expect to get back
again a 200 the 200 is not strictly necessary here or this expectation.
It's really just to say hey we completed the request successfully.
Now we need to do a console log on that response and take a look at exactly what happens to that set
cookie header when we tried to clear that session.
So I will do for right now just a console log of response dot get set.
Cookie.
All right we'll save this.
Go back over to our terminal.
We've got that new test file inside there and there is our console log so it looks like whenever we
try to sign out we get back an empty session right there.
Essentially we're saying this to no data and the cookie is also set to expire way long ago in the past.
So we could tried to just copy this thing right here entirely and say that the set cookie header should
be equal to this.
That be one strategy I could really just copy that.
Maybe just that string right there
and then put in an expectation that looks like expect response that get that cookie.
That gives us back an array as you just saw.
So it is an array so we can take a look at the first entry inside there and we could say that must be
equal to and then put in that exact string that we saw inside of our terminal.
So again this will be one approach right here.
Alternatively we could just say set cookie is defined as we had previously.
That would also be on a percent valid.
It's really up to you.
I don't really expect the response right here or the structure to ever change.
I think that it will always look like this forever.
So I feel kind of okay using that string.
But again if you want to have a little bit more generic expectation you could once again just say oh
yeah that set cookie a header is defined either way totally fine.
All right I am going to save this and run the test just one time to make sure it works.
I'll pull it back over.
Very good.
All right.
Well that is it for sign out.
So now got to move on with pause and then take a look at current user which is going to have some new
stuff that we're going to have to consider.
We'll see you in just a moment.