1 00:00:01,300 --> 00:00:06,340 In this video we're going to move on to testing our last root handler of current user now on the last 2 00:00:06,340 --> 00:00:09,160 two tests we put together the last two things we have tested. 3 00:00:09,160 --> 00:00:10,750 I've said that they were optional videos. 4 00:00:10,750 --> 00:00:15,490 In this case I really recommend you stick around as we're going to very quickly encounter a little problem 5 00:00:15,580 --> 00:00:19,970 around testing this robot handler that's going to have some far reaching impact on some tests we're 6 00:00:19,970 --> 00:00:22,200 going to write for other services in the future. 7 00:00:22,210 --> 00:00:24,460 So with that in mind let's just tackle this thing. 8 00:00:24,460 --> 00:00:28,870 Let's try to put some implementation together and we're going to start to see that there is a little 9 00:00:28,870 --> 00:00:31,650 issue around testing current user. 10 00:00:31,660 --> 00:00:31,900 All right. 11 00:00:31,930 --> 00:00:35,700 So as usual I'm going to find the test directory inside there. 12 00:00:35,710 --> 00:00:42,110 I'll make a new file called current user dot test dot t s at the top. 13 00:00:42,110 --> 00:00:46,910 We will once again add in some imports very similar to the two we put together previously. 14 00:00:47,060 --> 00:00:59,460 So we will get request from super test and we'll get app from up to directories at OK after that. 15 00:00:59,610 --> 00:01:02,340 Let's go ahead and put together a very simple statement. 16 00:01:02,430 --> 00:01:08,940 So chances are we want to try to sign in and then make a request to current user and get a response 17 00:01:08,940 --> 00:01:14,790 back and verify that the response we get back says that we have a current user of whoever we had signed 18 00:01:14,790 --> 00:01:21,890 in or signed up as it's all put together in its statement that says something like It's responds with 19 00:01:21,890 --> 00:01:26,000 details about the current user 20 00:01:29,400 --> 00:01:32,890 so in order to really test this thing out we first have to sign up. 21 00:01:33,010 --> 00:01:38,050 We have to somehow create a new account and then make our request to the current user endpoint. 22 00:01:38,050 --> 00:01:42,450 So we're going to sign up very similar to how we had previously back inside of our sign up test. 23 00:01:42,490 --> 00:01:50,620 So we'll do an await request to app we'll make a post request to API users sign up. 24 00:01:50,760 --> 00:01:56,620 I'm going to send along a valid e-mail and a valid password 25 00:01:59,670 --> 00:02:03,660 and then we'll put on the assertion to this thing just make sure that we signed up correctly. 26 00:02:03,690 --> 00:02:12,770 So I'll put in and expect of 2 0 1 so after this request we should be signed up or authenticated with 27 00:02:12,770 --> 00:02:13,610 the application. 28 00:02:13,640 --> 00:02:14,100 Right. 29 00:02:14,120 --> 00:02:17,570 Makes sense so now we can make a follow up request. 30 00:02:17,600 --> 00:02:22,820 Right down here we can attempt to reach out to the current user end point and try to get some details 31 00:02:22,880 --> 00:02:26,560 about this user that we just signed up as we can then take the response. 32 00:02:26,600 --> 00:02:31,790 Take a look at the body the response and make some assertion around it at least that is what we hope 33 00:02:31,790 --> 00:02:32,530 to do. 34 00:02:32,540 --> 00:02:36,980 I can tell you right now that's not going to quite work out as we hope but let's try it out anyways 35 00:02:38,640 --> 00:02:39,750 so I'll get the response 36 00:02:42,390 --> 00:02:49,070 from making a request to API users current user 37 00:02:52,790 --> 00:02:58,850 I'm going to send that off and the response we get back should have a 200. 38 00:02:58,860 --> 00:03:05,250 So I'll put on an expected of 200 like so sound theory information about the current user should be 39 00:03:05,250 --> 00:03:11,490 on response right there now to actually get the information from the body of that response we can refer 40 00:03:11,490 --> 00:03:11,930 to. 41 00:03:11,970 --> 00:03:19,080 Response dot body that's where the user should exist but down here rather than writing out an expectation 42 00:03:19,080 --> 00:03:19,590 right away. 43 00:03:19,590 --> 00:03:25,140 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 44 00:03:25,140 --> 00:03:26,230 back. 45 00:03:26,250 --> 00:03:26,550 All right. 46 00:03:26,600 --> 00:03:28,170 I'm going to save this. 47 00:03:28,170 --> 00:03:30,390 I'll go back over to my terminal. 48 00:03:30,580 --> 00:03:37,270 Looks like my tests are running and sure enough I get a current user of no which means that I am not 49 00:03:37,270 --> 00:03:38,550 signed in. 50 00:03:38,560 --> 00:03:40,110 Well why is that. 51 00:03:40,210 --> 00:03:43,000 We had made a request right here to sign up to the application. 52 00:03:43,030 --> 00:03:45,310 After signing up we should be authenticated. 53 00:03:45,970 --> 00:03:51,310 So why are we not seeing some current user coming back in the response body when we make that request 54 00:03:51,310 --> 00:03:53,050 to current user. 55 00:03:53,050 --> 00:03:54,330 Well here's the issue. 56 00:03:54,520 --> 00:03:59,320 We've been working in the browser and we've been working with postmen to test out all these different 57 00:03:59,320 --> 00:04:05,440 root handlers so far the browser and postmen have some functionality included inside them to automatically 58 00:04:05,440 --> 00:04:10,380 manage cookies and send cookie data along with any follow up requests to our server. 59 00:04:10,500 --> 00:04:15,430 We are currently making use of super tests however inside of our testing setup right here and Super 60 00:04:15,430 --> 00:04:20,360 Test by default is not going to manage cookies for us automatically. 61 00:04:20,380 --> 00:04:25,630 So while we do get back a cookie during this first request right here that will supposedly authenticate 62 00:04:25,630 --> 00:04:31,250 us with our server that cookie it does not get included with the follow up request. 63 00:04:31,270 --> 00:04:36,950 That's the big issue so even though we have gotten back a cookie from the first request it does not 64 00:04:36,950 --> 00:04:38,490 get sent along with the second one. 65 00:04:38,570 --> 00:04:45,020 And so our server assumes that hey we are not authenticated and that's why we saw a response stop body 66 00:04:45,020 --> 00:04:51,540 right here with a current user of no so beyond just making this test pass right here. 67 00:04:51,570 --> 00:04:56,400 As you can imagine at some point in the future we're going to want to send authenticated requests to 68 00:04:56,400 --> 00:04:58,520 test out other services we put together. 69 00:04:58,710 --> 00:05:02,130 That's really not something right here that is just relevant to this test. 70 00:05:02,130 --> 00:05:05,070 It's very relevant to tests we write in the future as well. 71 00:05:05,070 --> 00:05:10,260 So we need to make sure that we come up with some kind of solution to sign up take the cookie from that 72 00:05:10,380 --> 00:05:15,170 and make it really easy to include that cookie with follow up requests as well. 73 00:05:15,170 --> 00:05:18,700 Let's take a pause right here and start to figure out some solution to that in the next video.