1 00:00:00,760 --> 00:00:03,490 In this video we're going to work on our first test right here. 2 00:00:03,490 --> 00:00:08,330 So we need to somehow make a request or a POST request specifically to API slash tickets. 3 00:00:08,350 --> 00:00:12,200 We're just gonna make sure that we get back a status code that is not a four a four. 4 00:00:12,340 --> 00:00:14,490 Why would we not want to form a four. 5 00:00:14,500 --> 00:00:19,420 Well if we open up our apt to yes file you might recall that inside of here when we copy pasted all 6 00:00:19,420 --> 00:00:23,800 that code over from our service we had previously put together this root handler right here. 7 00:00:23,800 --> 00:00:25,770 This catch all root handler. 8 00:00:25,930 --> 00:00:31,570 So if we ever got a request coming into our application on any method to any routes that we did not 9 00:00:31,570 --> 00:00:37,450 somehow recognize we were going to immediately throw if not found error that results in a 4 0 4 status 10 00:00:37,450 --> 00:00:40,730 code being sent back to whoever made the request. 11 00:00:40,750 --> 00:00:46,630 So if we could somehow make a request or a POST request to API slash tickets and then inspect the response 12 00:00:46,630 --> 00:00:51,130 code or the status code and make sure it's not a for a for now I'd be a pretty good way of implementing 13 00:00:51,130 --> 00:00:52,250 the test right here. 14 00:00:52,300 --> 00:00:54,440 So let's give that a shot. 15 00:00:54,580 --> 00:01:02,590 I'm gonna write out response is a wait we'll make a request to our app I want to make specifically a 16 00:01:02,590 --> 00:01:06,190 POST request to API slash tickets. 17 00:01:06,420 --> 00:01:12,210 I'm going to send along an empty object so eventually we're going to require that we send along a title 18 00:01:12,210 --> 00:01:13,410 and a price and so on. 19 00:01:13,440 --> 00:01:18,240 But for right now we can just send some empty request because all we really care about is that we don't 20 00:01:18,240 --> 00:01:23,730 get a four a four if we get back a status code of say four hundred which is an invalid request. 21 00:01:23,850 --> 00:01:24,630 That's fine. 22 00:01:24,720 --> 00:01:29,130 I just want to make sure that well we get something besides a forum for. 23 00:01:29,190 --> 00:01:32,730 Not to somehow get the status code back and make an assertion about it. 24 00:01:32,730 --> 00:01:35,430 We can take a look at this response right here. 25 00:01:35,430 --> 00:01:39,840 So the response is going to have a status code property assigned to it and that's gonna be the status 26 00:01:39,840 --> 00:01:41,810 code of the response we got sent back. 27 00:01:41,970 --> 00:01:48,690 So we can write out an expectation and look at that status I'll put it in response dot status. 28 00:01:48,740 --> 00:01:58,880 Now I'm going to expect that to not to equal or for I'll save this I'm going to go back over to my terminal 29 00:01:58,880 --> 00:02:00,400 and let's see how we're doing. 30 00:02:00,440 --> 00:02:02,400 So it looks like that test is failing. 31 00:02:02,420 --> 00:02:03,020 That's good. 32 00:02:03,020 --> 00:02:05,530 That means that right now you're getting a four a four. 33 00:02:05,540 --> 00:02:10,490 So now we can start to create that root handler and as soon as we define it and send back some other 34 00:02:10,490 --> 00:02:15,750 kind of response like maybe a four hundred to two hundred whatever else then that test should pass. 35 00:02:15,750 --> 00:02:18,430 So let's give that a shot. 36 00:02:18,590 --> 00:02:22,060 I'm going to find my roots directory inside of roots. 37 00:02:22,060 --> 00:02:28,220 I'm going to make a new file called new dot t s so this new file is gonna responsible for creating a 38 00:02:28,220 --> 00:02:30,700 root handler to create a new ticket. 39 00:02:31,930 --> 00:02:36,510 To create this right handler at the very top we're gonna add in a couple of imports. 40 00:02:36,910 --> 00:02:44,680 So I'm going to import express I'm going to import the request and response types from Express 41 00:02:47,900 --> 00:02:56,350 I'll then create a router using express stop router on the router I'll tell it to expect a post request 42 00:02:56,350 --> 00:03:05,050 to API slash tickets and I'll put in my actual route handling function I'll put in my arguments of req 43 00:03:05,350 --> 00:03:12,000 and I will annotate that as type request and rez an entity that has type response then inside of here 44 00:03:12,270 --> 00:03:17,640 we get put together for right now just some implementation that will make this test pass so all we really 45 00:03:17,640 --> 00:03:21,500 care about right now is sending back something that is not a status code for a 4. 46 00:03:21,660 --> 00:03:27,720 It's all simply do a red dot send status which is how we send back just a status code by itself of about 47 00:03:27,730 --> 00:03:28,230 200 48 00:03:31,350 --> 00:03:35,610 then at the very bottom I'm going to export the router and remember and all those other rep files we 49 00:03:35,610 --> 00:03:40,410 had done back in cyber auth service we had it renamed this router variable because we're going to eventually 50 00:03:40,410 --> 00:03:44,450 have many different routers created and in use inside of our abductees file. 51 00:03:44,610 --> 00:03:51,300 So I'm going to rename the thing on the fly and call it as rate ticket router. 52 00:03:51,330 --> 00:03:56,880 The reason I'm not calling it new ticket router is that someone might kind of misread this and think 53 00:03:56,880 --> 00:04:03,360 that it's new ticket router as in trying to create an object out of ticket router to simply call it 54 00:04:03,360 --> 00:04:03,990 create instead 55 00:04:07,160 --> 00:04:12,720 going to save the file I'm going to go back over to my apt yes file remember after creating the router 56 00:04:12,750 --> 00:04:16,950 we have to import it into this file and then wired up to our Express application. 57 00:04:17,050 --> 00:04:18,810 So at the very top I'm going to import 58 00:04:21,670 --> 00:04:26,890 great ticket router from roots new 59 00:04:30,190 --> 00:04:35,650 then right after our cookie session middleware I will wire this thing up so app use and we're gonna 60 00:04:35,650 --> 00:04:37,420 tell it to use it to get router 61 00:04:41,550 --> 00:04:45,580 let's save this to go back or my terminal and now in theory our tests should be passing. 62 00:04:45,610 --> 00:04:50,000 Yep looks like it is definitely good step forward. 63 00:04:50,160 --> 00:04:54,540 Let's take a pause right here we come back the next video we'll move on to our second third fourth and 64 00:04:54,540 --> 00:04:55,230 so on tests.