1 00:00:01,690 --> 00:00:06,460 In this video we're going to try to write out a test or two around these sign out functionality. 2 00:00:06,460 --> 00:00:10,390 Now once again just like the last video we're not really going to see anything that new in the world 3 00:00:10,390 --> 00:00:11,140 of testing. 4 00:00:11,140 --> 00:00:14,140 So if you really just want to get on to some the more interesting stuff. 5 00:00:14,230 --> 00:00:15,490 Skip to the next video once again. 6 00:00:15,610 --> 00:00:20,730 Otherwise stick around and let's write out a single test around these sign out root handler so once 7 00:00:20,730 --> 00:00:25,090 again inside my test directory I'll make a new file of sign out that test out. 8 00:00:25,120 --> 00:00:38,060 Yes at the top we will import request from two protest and app from up to directories at. 9 00:00:38,200 --> 00:00:42,370 So as you guess all we really want to do here is attempt to sign up for an account. 10 00:00:42,370 --> 00:00:44,640 Once we sign up we should be it logged in. 11 00:00:44,920 --> 00:00:50,440 And then after that we'll make a another request to sign out and we should be able to make a assertion 12 00:00:50,470 --> 00:00:51,520 on the response we get back. 13 00:00:51,520 --> 00:00:54,970 Something to say that the cookie has been cleared or something like that. 14 00:00:55,090 --> 00:00:59,110 We'll probably have to inspect the actual response that gets sent back to figure out exactly how to 15 00:00:59,110 --> 00:01:00,660 write out this expectation. 16 00:01:00,670 --> 00:01:05,600 Let's just get started writing out the test first put together in its statements out of here. 17 00:01:05,620 --> 00:01:06,940 We'll say it. 18 00:01:07,190 --> 00:01:08,390 Here's the cookie. 19 00:01:08,470 --> 00:01:09,850 After signing out 20 00:01:13,330 --> 00:01:17,280 inside of here again we need to first sign up for an account so that we are authenticated. 21 00:01:17,420 --> 00:01:18,400 We'll do in a wait. 22 00:01:18,400 --> 00:01:20,700 Request over to app. 23 00:01:20,880 --> 00:01:32,020 I'll make a post to API users sign up and we'll send off an email that is valid and a password that 24 00:01:32,020 --> 00:01:33,140 is valid as well. 25 00:01:33,170 --> 00:01:40,830 And then once again we will make sure that we get back a status code of not one but two a one. 26 00:01:40,830 --> 00:01:44,020 So again this is just gonna make sure that we are successfully signed up. 27 00:01:44,170 --> 00:01:46,260 Then after that we will make our request. 28 00:01:46,520 --> 00:01:50,510 It's going to be a post request to API users sign out. 29 00:01:50,510 --> 00:01:55,200 And again on the response we should be able to inspect that set cookie header and figure out exactly 30 00:01:55,260 --> 00:01:59,550 what gets sent back when when we sign out we'll have to console log that thing to figure out exactly 31 00:01:59,820 --> 00:02:07,940 how we should write that assertion we'll do a concert response is a weight request to app. 32 00:02:07,940 --> 00:02:12,500 We'll do a post in this case to API users sign out in this case 33 00:02:15,430 --> 00:02:22,290 we're gonna send along an anti object because it is a post request and then we will expect to get back 34 00:02:22,710 --> 00:02:29,520 again a 200 the 200 is not strictly necessary here or this expectation. 35 00:02:29,520 --> 00:02:33,950 It's really just to say hey we completed the request successfully. 36 00:02:33,980 --> 00:02:38,960 Now we need to do a console log on that response and take a look at exactly what happens to that set 37 00:02:38,960 --> 00:02:41,870 cookie header when we tried to clear that session. 38 00:02:41,950 --> 00:02:46,610 So I will do for right now just a console log of response dot get set. 39 00:02:46,610 --> 00:02:51,320 Cookie. 40 00:02:51,410 --> 00:02:52,600 All right we'll save this. 41 00:02:52,610 --> 00:02:54,850 Go back over to our terminal. 42 00:02:54,920 --> 00:03:00,890 We've got that new test file inside there and there is our console log so it looks like whenever we 43 00:03:01,070 --> 00:03:05,240 try to sign out we get back an empty session right there. 44 00:03:05,240 --> 00:03:11,450 Essentially we're saying this to no data and the cookie is also set to expire way long ago in the past. 45 00:03:11,450 --> 00:03:16,430 So we could tried to just copy this thing right here entirely and say that the set cookie header should 46 00:03:16,430 --> 00:03:17,440 be equal to this. 47 00:03:17,450 --> 00:03:21,140 That be one strategy I could really just copy that. 48 00:03:21,380 --> 00:03:22,670 Maybe just that string right there 49 00:03:26,050 --> 00:03:33,320 and then put in an expectation that looks like expect response that get that cookie. 50 00:03:33,430 --> 00:03:35,530 That gives us back an array as you just saw. 51 00:03:35,560 --> 00:03:40,480 So it is an array so we can take a look at the first entry inside there and we could say that must be 52 00:03:40,720 --> 00:03:47,860 equal to and then put in that exact string that we saw inside of our terminal. 53 00:03:47,860 --> 00:03:49,510 So again this will be one approach right here. 54 00:03:49,870 --> 00:03:54,000 Alternatively we could just say set cookie is defined as we had previously. 55 00:03:54,010 --> 00:03:56,050 That would also be on a percent valid. 56 00:03:56,050 --> 00:03:57,150 It's really up to you. 57 00:03:57,190 --> 00:04:00,310 I don't really expect the response right here or the structure to ever change. 58 00:04:00,310 --> 00:04:02,860 I think that it will always look like this forever. 59 00:04:02,860 --> 00:04:04,780 So I feel kind of okay using that string. 60 00:04:04,780 --> 00:04:09,010 But again if you want to have a little bit more generic expectation you could once again just say oh 61 00:04:09,010 --> 00:04:13,470 yeah that set cookie a header is defined either way totally fine. 62 00:04:13,480 --> 00:04:17,790 All right I am going to save this and run the test just one time to make sure it works. 63 00:04:17,910 --> 00:04:20,160 I'll pull it back over. 64 00:04:20,180 --> 00:04:21,530 Very good. 65 00:04:21,530 --> 00:04:21,770 All right. 66 00:04:21,770 --> 00:04:23,600 Well that is it for sign out. 67 00:04:23,610 --> 00:04:28,310 So now got to move on with pause and then take a look at current user which is going to have some new 68 00:04:28,310 --> 00:04:30,290 stuff that we're going to have to consider. 69 00:04:30,320 --> 00:04:31,270 We'll see you in just a moment.