1 00:00:01,020 --> 00:00:04,770 We've now put together our very first test right here which is fantastic. 2 00:00:04,770 --> 00:00:07,590 We're gonna start to write out a couple of more tests around that sign up. 3 00:00:07,590 --> 00:00:08,790 Root handler. 4 00:00:08,790 --> 00:00:13,200 Now the nice thing about using super test is it's really easy to write out a test. 5 00:00:13,260 --> 00:00:15,540 So we're gonna put together a fair number. 6 00:00:15,540 --> 00:00:19,500 I just wanted to give you a good example of all the different ways in which we could test a very basic 7 00:00:19,500 --> 00:00:20,400 root handler. 8 00:00:20,400 --> 00:00:21,720 So let's get to it. 9 00:00:21,960 --> 00:00:27,030 The next test I want to put together is just make sure that if we put in some kind of request or try 10 00:00:27,030 --> 00:00:33,060 to sign up would say an invalid email or password the requests should fail and we certainly could write 11 00:00:33,060 --> 00:00:38,340 out a test to say hey let's make sure that we fail the request and send back some very appropriate error 12 00:00:38,340 --> 00:00:43,560 message where we're gonna take an even more basic approach in that we're gonna say that if we send in 13 00:00:43,920 --> 00:00:49,960 some invalid email or password let's just expect that we get a response that has a status code of four 14 00:00:49,980 --> 00:00:56,890 hundred which would indicate that we failed to sign it we absolutely can try to write out an assertion 15 00:00:56,890 --> 00:01:01,270 to make sure we get the appropriate error message but again we'll just keep it really quick really simple 16 00:01:01,390 --> 00:01:08,180 and make sure we get back a status go to 400 to back inside my test file Aladdin in its statement and 17 00:01:08,180 --> 00:01:14,130 say it returns a four hundred with an invalid email 18 00:01:20,140 --> 00:01:22,090 rather than writing out the entire request again. 19 00:01:22,090 --> 00:01:23,660 Let's just do a quick copy paste. 20 00:01:23,770 --> 00:01:25,510 So I'm going to copy that block right there. 21 00:01:25,510 --> 00:01:31,770 But into the second one and now all we have to do is update the email to be something invalid and change 22 00:01:31,770 --> 00:01:32,930 the status code. 23 00:01:33,180 --> 00:01:40,540 So I will put in an invalid e-mail and I will expect to get back a status code of 400 so going to say 24 00:01:40,540 --> 00:01:45,070 that go back to where my terminal and there we go. 25 00:01:45,100 --> 00:01:47,210 You'll notice that I'm getting a console log right here. 26 00:01:47,290 --> 00:01:52,570 That's just because we still have a leftover console log inside of our era handle middleware. 27 00:01:52,570 --> 00:01:57,130 Remember our air handler middleware anytime it sees an error is going to do a log of the air that's 28 00:01:57,130 --> 00:01:58,390 coming across. 29 00:01:58,390 --> 00:02:00,640 We probably don't really want to see this in that test environment. 30 00:02:00,640 --> 00:02:04,640 So let's just go delete that console log from that area handler. 31 00:02:04,760 --> 00:02:06,670 I'm going to go and find my middleware directory. 32 00:02:06,800 --> 00:02:10,640 I'll find the air handler inside there and I'll just delete that console log. 33 00:02:10,640 --> 00:02:14,540 Pretty sure we just had that in there for testing purposes or manual testing purposes. 34 00:02:14,540 --> 00:02:18,180 I suppose a little bit ago Jeff I flipped back over. 35 00:02:18,230 --> 00:02:18,780 Awesome. 36 00:02:18,800 --> 00:02:22,210 We have to test passing anything on to mention. 37 00:02:22,320 --> 00:02:26,640 I meant to mention that earlier when we first started up our test suite the very first time you start 38 00:02:26,640 --> 00:02:31,010 up the test suite that's going to take about eight or all the way up to 20 seconds to start up. 39 00:02:31,080 --> 00:02:36,150 And that's because that in memory copy of Mongo Debbie just takes a little bit to load but after it 40 00:02:36,150 --> 00:02:39,320 has been loaded we no longer have to restart Mongo DB. 41 00:02:39,420 --> 00:02:41,390 For each individual test run. 42 00:02:41,390 --> 00:02:47,650 So after that long initial startup all of our tests are going to run very very quickly I can hit enter 43 00:02:47,860 --> 00:02:53,970 while at the terminal to rerun my tests and as you can see these two tests run very very fast. 44 00:02:53,990 --> 00:02:55,410 All right let's add in a couple more. 45 00:02:55,460 --> 00:03:02,380 Very quickly I'm going to just do another copy paste of this entire block right here there's the paste. 46 00:03:02,700 --> 00:03:09,910 I'll say it returns a 400 with an invalid password so an invalid password as you'll recall is any that 47 00:03:09,910 --> 00:03:13,400 has a length less than four or greater than 20. 48 00:03:13,420 --> 00:03:15,640 Let's just try putting a password with one character. 49 00:03:15,640 --> 00:03:17,860 I'll put in a password appear right there. 50 00:03:17,860 --> 00:03:22,570 If we have an invalid password we should get a 400 so we'll save this. 51 00:03:22,570 --> 00:03:24,790 Go back over awesome. 52 00:03:24,800 --> 00:03:26,090 Got another passing test. 53 00:03:27,860 --> 00:03:28,270 Let's try. 54 00:03:28,270 --> 00:03:30,380 Just doing one more will do. 55 00:03:30,380 --> 00:03:34,790 We'll try saying that if we send in a request that does not have an email or a password. 56 00:03:34,850 --> 00:03:41,310 We should get a 400 as well so I'll do another copy paste that it block and I'll change the description 57 00:03:41,340 --> 00:03:43,080 to it returns a 400 58 00:03:46,370 --> 00:03:49,850 with missing email and password 59 00:03:52,670 --> 00:03:57,480 and then I'll just send in an empty object like so. 60 00:03:57,660 --> 00:04:01,600 Now of course we could write out two separate tests one to just have the email missing one at the pass 61 00:04:01,600 --> 00:04:06,630 from missing absolute feel free to do so if you want to in fact I'll just show you how to do that. 62 00:04:06,630 --> 00:04:10,530 If you want to write out to submit requests inside of one handler that's when we'll start to use that 63 00:04:10,560 --> 00:04:17,640 async await syntax so you'll copy that block right there a step right above the return and then on the 64 00:04:17,640 --> 00:04:20,130 first request we have to add in and wait. 65 00:04:20,190 --> 00:04:24,390 So we will await this request to be completed and then we will return the next one. 66 00:04:24,450 --> 00:04:30,320 Behind the scenes just is going to automatically await this request for us so we technically don't even 67 00:04:30,320 --> 00:04:31,130 need the return there. 68 00:04:31,130 --> 00:04:33,950 We could instead use a wait and see. 69 00:04:33,950 --> 00:04:35,990 Same thing is true of everything up here. 70 00:04:36,020 --> 00:04:38,780 We just need to make sure we either return requests or await it. 71 00:04:38,780 --> 00:04:42,560 Either one is fine now maybe and the first one we could put in a valid email 72 00:04:46,720 --> 00:04:49,030 and in the second one we could put in a valid password 73 00:04:52,120 --> 00:04:54,040 on and say this flip back over 74 00:04:57,010 --> 00:05:02,560 all right so you can see it is pretty darn easy to write tests with Super Test but well right now we 75 00:05:02,570 --> 00:05:07,550 are really just making expectations around the response 70 some more complex behaviors going on inside 76 00:05:07,550 --> 00:05:08,180 of here. 77 00:05:08,270 --> 00:05:09,380 So let's take a quick pause. 78 00:05:09,380 --> 00:05:13,100 We'll start to test them the actual infrastructure of this thing in just a moment.