1 00:00:01,860 --> 00:00:05,840 In this video we're going to write out a couple of tests around our sign and request handler. 2 00:00:05,850 --> 00:00:09,140 Now we're not gonna really run into anything too interesting around these tests. 3 00:00:09,150 --> 00:00:12,500 It's gonna be pretty much pretty similar to what we just went through for sign up. 4 00:00:12,570 --> 00:00:15,100 So if you are already bored with testing that is fine. 5 00:00:15,120 --> 00:00:17,880 You can feel free to skip over this video otherwise stick around. 6 00:00:17,910 --> 00:00:21,950 We're gonna write out just one or two quick tests just to make sure that this thing works correctly. 7 00:00:21,990 --> 00:00:23,240 So let's get to it. 8 00:00:23,290 --> 00:00:26,850 We're going to once again follow the same pattern of the creation of the test file. 9 00:00:26,850 --> 00:00:32,490 So because we want to make a test around a sign and t us we'll go into the same directory find the underscore 10 00:00:32,520 --> 00:00:34,430 underscore test folder and side there. 11 00:00:34,440 --> 00:00:41,180 I'll make a new file called sign in not test thought to us at the very top then put in the exact same 12 00:00:41,180 --> 00:00:49,520 boilerplate we had in the last test file so we'll import request from two protests and our app from 13 00:00:50,120 --> 00:00:56,710 up to directories at All right let's very quickly open up that sign in root handler and try to figure 14 00:00:56,710 --> 00:00:59,040 out what we should really be trying to test inside of here. 15 00:01:00,580 --> 00:01:04,540 Well we could write out some more tests around making sure that we've got some validation put together. 16 00:01:04,540 --> 00:01:06,630 If you want to do that I will leave it up to you. 17 00:01:06,640 --> 00:01:11,740 You can really just take the exact same tests that we wrote or the last drought handler and move them 18 00:01:11,740 --> 00:01:12,210 over. 19 00:01:12,220 --> 00:01:16,030 The only thing you'll need to change is we don't really have any requirements around the password being 20 00:01:16,120 --> 00:01:18,090 of some particular length. 21 00:01:18,220 --> 00:01:22,750 So just keep in mind that if you copy paste those tests over you might have to update some tests around 22 00:01:22,840 --> 00:01:29,300 validation of the password so the things we might attempt to test is to make sure that if we tried to 23 00:01:29,300 --> 00:01:34,100 log in as someone who has never signed up before or essentially with an email that's never been used 24 00:01:34,380 --> 00:01:38,390 and we should probably see a response with this as go to 400. 25 00:01:38,460 --> 00:01:43,380 We should also probably tried to sign in with an incorrect password and expect to also see a 400. 26 00:01:43,440 --> 00:01:47,700 And then finally if we attempt to sign in with some legit credentials then we should once again see 27 00:01:47,720 --> 00:01:50,440 that's that cookie in the header. 28 00:01:50,560 --> 00:01:55,830 So let's try to write out some tests for those three cases the case in which we reuse an email in which 29 00:01:55,830 --> 00:02:01,570 we use an email that does not exist and in which everything goes successful. 30 00:02:01,620 --> 00:02:08,460 So the very first one we'll say it fails when a. 31 00:02:08,590 --> 00:02:13,430 Email that does not exist is supplied 32 00:02:16,990 --> 00:02:23,910 to then inside of your we will do and await we'll make a request to our app. 33 00:02:24,090 --> 00:02:28,740 We're going to do a post request to API. 34 00:02:28,770 --> 00:02:29,940 I mean look up that root handler. 35 00:02:29,940 --> 00:02:31,900 I can remember if we call the author users. 36 00:02:31,960 --> 00:02:43,290 Looks like it's users API users sign in and we'll send along whatever email and whatever password they 37 00:02:43,290 --> 00:02:50,010 just have to be valid then we will expect to get back to 400 because we are trying to sign in with an 38 00:02:50,010 --> 00:02:52,170 account that does not exist. 39 00:02:52,350 --> 00:02:53,820 Let's save that. 40 00:02:53,820 --> 00:02:55,920 We'll go back over to our terminal. 41 00:02:55,920 --> 00:02:59,910 You'll notice that now we've got a second file inside of here and it looks like all the tests inside 42 00:02:59,910 --> 00:03:03,350 of that sign and test out to yes file are now working correctly. 43 00:03:03,360 --> 00:03:05,150 Very good. 44 00:03:05,320 --> 00:03:05,630 All right. 45 00:03:05,650 --> 00:03:06,780 Now the next one we'll do. 46 00:03:06,880 --> 00:03:11,560 We're going to attempt to sign into an existing account with the incorrect password. 47 00:03:12,340 --> 00:03:19,660 So we'll do another it block and I'll say it fails when an incorrect password is supplied 48 00:03:23,100 --> 00:03:28,200 now in this case we need to make sure first that there is actually an account for us to sign into. 49 00:03:28,230 --> 00:03:34,230 So we need to first go over to our sign up Route read a new account and then attempt to sign into it 50 00:03:34,230 --> 00:03:35,360 with an incorrect password. 51 00:03:36,030 --> 00:03:40,120 So in this case we'll do and await request over to app. 52 00:03:40,220 --> 00:03:43,850 We'll make a post to API users sign up. 53 00:03:43,940 --> 00:03:48,880 In this case we'll send along some valid credentials 54 00:03:55,310 --> 00:04:00,530 and I will expect that after signing up with these valid credentials I get back to a one because remember 55 00:04:00,560 --> 00:04:03,320 that's what we sent back after someone signs up for an account 56 00:04:06,310 --> 00:04:10,380 then after that we're going to attempt to sign in. 57 00:04:10,430 --> 00:04:14,510 We also want to make sure we collect the response that comes back and we're going to inspect that response 58 00:04:14,540 --> 00:04:17,130 and make sure that there is some set cookie header on there. 59 00:04:17,480 --> 00:04:19,310 So we will do a a wait 60 00:04:22,410 --> 00:04:28,030 request with that we'll make a post to API users sign in. 61 00:04:28,030 --> 00:04:36,450 In this case we're going to send along the same email but an incorrect password they'll put in some 62 00:04:36,450 --> 00:04:45,060 gibberish like so and then I'm going to expect to get a four hundred back. 63 00:04:45,350 --> 00:04:47,120 Let's say that look back over 64 00:04:50,410 --> 00:04:55,460 and looks good OK so now let's just do one more. 65 00:04:55,550 --> 00:05:01,200 We're gonna handle a case in which we sign up for an account and then attempt to sign in with a correct 66 00:05:01,200 --> 00:05:01,700 password. 67 00:05:01,740 --> 00:05:06,330 And again on the response we get back in the sign in we should be able to take that response and say 68 00:05:06,360 --> 00:05:15,940 that we've got some actual cookie being set we'll do it responds with a cookie when given the valid 69 00:05:16,420 --> 00:05:17,050 credentials 70 00:05:21,280 --> 00:05:25,490 so for this we can save a little bit of time by just taking everything out of the body of the previous 71 00:05:25,490 --> 00:05:26,270 test. 72 00:05:26,330 --> 00:05:33,410 It's going to take the sign up and the sign and stuff are gonna paste it down inside this new test make 73 00:05:33,410 --> 00:05:40,940 some indentation I'm gonna make sure that the sign in request right here has the valid password or the 74 00:05:40,970 --> 00:05:43,660 correct password so my correct password is password. 75 00:05:43,820 --> 00:05:49,460 So update that string I'll make sure I update that status code right there because now that we're providing 76 00:05:49,490 --> 00:05:55,240 a correct password I'm going to expect to get back a response of the 200 and then finally we're going 77 00:05:55,240 --> 00:06:01,270 to get the response and we're going to make sure that that set cookie header is defined so we'll do 78 00:06:01,270 --> 00:06:11,190 another expect response dot get set cookie to be defined. 79 00:06:11,270 --> 00:06:11,670 All right. 80 00:06:11,670 --> 00:06:12,580 Another save. 81 00:06:12,990 --> 00:06:21,070 Now they're flip over to our terminal and after a brief pause we are good to go well it's fantastic. 82 00:06:21,090 --> 00:06:25,470 So let's take a quick pause right here and move on to testing our next round handler.