In this video we're going to move on to testing our last root handler of current user now on the last
two tests we put together the last two things we have tested.
I've said that they were optional videos.
In this case I really recommend you stick around as we're going to very quickly encounter a little problem
around testing this robot handler that's going to have some far reaching impact on some tests we're
going to write for other services in the future.
So with that in mind let's just tackle this thing.
Let's try to put some implementation together and we're going to start to see that there is a little
issue around testing current user.
All right.
So as usual I'm going to find the test directory inside there.
I'll make a new file called current user dot test dot t s at the top.
We will once again add in some imports very similar to the two we put together previously.
So we will get request from super test and we'll get app from up to directories at OK after that.
Let's go ahead and put together a very simple statement.
So chances are we want to try to sign in and then make a request to current user and get a response
back and verify that the response we get back says that we have a current user of whoever we had signed
in or signed up as it's all put together in its statement that says something like It's responds with
details about the current user
so in order to really test this thing out we first have to sign up.
We have to somehow create a new account and then make our request to the current user endpoint.
So we're going to sign up very similar to how we had previously back inside of our sign up test.
So we'll do an await request to app we'll make a post request to API users sign up.
I'm going to send along a valid e-mail and a valid password
and then we'll put on the assertion to this thing just make sure that we signed up correctly.
So I'll put in and expect of 2 0 1 so after this request we should be signed up or authenticated with
the application.
Right.
Makes sense so now we can make a follow up request.
Right down here we can attempt to reach out to the current user end point and try to get some details
about this user that we just signed up as we can then take the response.
Take a look at the body the response and make some assertion around it at least that is what we hope
to do.
I can tell you right now that's not going to quite work out as we hope but let's try it out anyways
so I'll get the response
from making a request to API users current user
I'm going to send that off and the response we get back should have a 200.
So I'll put on an expected of 200 like so sound theory information about the current user should be
on response right there now to actually get the information from the body of that response we can refer
to.
Response dot body that's where the user should exist but down here rather than writing out an expectation
right away.
Let's do a console log of response dot body like so let's just take a look at that and see what we get
back.
All right.
I'm going to save this.
I'll go back over to my terminal.
Looks like my tests are running and sure enough I get a current user of no which means that I am not
signed in.
Well why is that.
We had made a request right here to sign up to the application.
After signing up we should be authenticated.
So why are we not seeing some current user coming back in the response body when we make that request
to current user.
Well here's the issue.
We've been working in the browser and we've been working with postmen to test out all these different
root handlers so far the browser and postmen have some functionality included inside them to automatically
manage cookies and send cookie data along with any follow up requests to our server.
We are currently making use of super tests however inside of our testing setup right here and Super
Test by default is not going to manage cookies for us automatically.
So while we do get back a cookie during this first request right here that will supposedly authenticate
us with our server that cookie it does not get included with the follow up request.
That's the big issue so even though we have gotten back a cookie from the first request it does not
get sent along with the second one.
And so our server assumes that hey we are not authenticated and that's why we saw a response stop body
right here with a current user of no so beyond just making this test pass right here.
As you can imagine at some point in the future we're going to want to send authenticated requests to
test out other services we put together.
That's really not something right here that is just relevant to this test.
It's very relevant to tests we write in the future as well.
So we need to make sure that we come up with some kind of solution to sign up take the cookie from that
and make it really easy to include that cookie with follow up requests as well.
Let's take a pause right here and start to figure out some solution to that in the next video.