1 00:00:00,480 --> 00:00:02,730 We are all done with some initial setup on tickets. 2 00:00:02,760 --> 00:00:07,530 So now it's time to actually go ahead and put some implementation together now just as a quick reminder 3 00:00:08,010 --> 00:00:11,730 these are the different route handlers are gonna build up inside of this ticket service. 4 00:00:11,730 --> 00:00:15,260 The first route handler we're going to work on is going to give us the ability to create a ticket. 5 00:00:15,270 --> 00:00:17,640 So this is gonna be the first one that we focus on. 6 00:00:17,700 --> 00:00:22,050 Now we definitely could just go ahead and run off and start to build out this road handler but maybe 7 00:00:22,050 --> 00:00:27,240 a better way to approach the development of the service would be to kind of take a test driven development 8 00:00:27,240 --> 00:00:28,440 sort of approach. 9 00:00:28,440 --> 00:00:33,540 So I would like to first write out some tests around this braided ticket root handler and then try to 10 00:00:33,570 --> 00:00:34,930 make those tests pass. 11 00:00:35,040 --> 00:00:40,800 So let's give that a shot back and said to my editor I'm gonna find the s RC directory inside there 12 00:00:40,830 --> 00:00:46,440 I'll make a new folder called routes inside that I'll make another new folder called underscore underscore 13 00:00:46,450 --> 00:00:52,770 test underscore underscore and then inside there I'll create a file called new test. 14 00:00:52,800 --> 00:00:58,800 Yes I'm calling his file new because we're going to eventually have a new root handler the new root 15 00:00:58,800 --> 00:01:00,570 handler is recruiting a new ticket. 16 00:01:02,140 --> 00:01:06,730 Then inside of here we'll put together some boilerplate very similar to what we did on our last application 17 00:01:06,730 --> 00:01:09,430 for testing a root handler at the very top. 18 00:01:09,430 --> 00:01:17,360 I'm going to import request from super test I'll then import app and that is the express application 19 00:01:17,930 --> 00:01:24,040 from up to directories at then we can start to write out some tests. 20 00:01:24,040 --> 00:01:28,150 So here comes a big question what do we want to test. 21 00:01:28,150 --> 00:01:31,450 Well I think you could probably take a good guess of what we need to do. 22 00:01:31,660 --> 00:01:36,820 We need to make sure that there is some root handler present at API slash tickets that will respond 23 00:01:36,820 --> 00:01:38,180 to it post request. 24 00:01:38,200 --> 00:01:42,580 We probably need to make sure that we write out a test that's going to make sure that we validate the 25 00:01:42,580 --> 00:01:44,270 incoming request body. 26 00:01:44,290 --> 00:01:49,210 So for example make sure there is a title and a price and that they are of the correct type. 27 00:01:49,210 --> 00:01:53,680 We probably may need to make sure that request to this row handler are always authenticated. 28 00:01:53,680 --> 00:01:59,230 So in other words a user must be signed into our application in order to access this row handler and 29 00:01:59,230 --> 00:02:03,430 then maybe eventually some test to make sure that say we actually create a ticket or something like 30 00:02:03,430 --> 00:02:04,270 that. 31 00:02:04,450 --> 00:02:09,070 So let's just write out some it blocks or it statements for some the tests that we're probably going 32 00:02:09,070 --> 00:02:17,780 to have to write instead the first one is going to be something like it's as a root handler listening 33 00:02:17,780 --> 00:02:24,620 to flash API slash tickets or post requests 34 00:02:27,880 --> 00:02:37,450 and I'll zoom out here in just a second so you can see this entire statement and there we go. 35 00:02:37,490 --> 00:02:42,380 I'm going to copy paste this down a couple of times and I'll just update the description on each one 36 00:02:42,390 --> 00:02:46,040 and will eventually go in and write out some implementation for each test. 37 00:02:46,070 --> 00:02:47,210 So how about on the second one. 38 00:02:47,240 --> 00:02:55,430 Let's change the description to something like it can only be accessed if the user is signed in so that 39 00:02:55,430 --> 00:03:00,700 will be a check to make sure we've got some authentication related stuff about for the next one we'll 40 00:03:00,700 --> 00:03:13,980 say it returns an air if an invalid title is provided for the next one we could do it returns an error 41 00:03:14,070 --> 00:03:22,080 if an invalid price is provided and then maybe for the last one done here we'll test and make sure that 42 00:03:22,080 --> 00:03:24,220 everything kind of works as expected. 43 00:03:24,240 --> 00:03:35,410 So how about something like it reads a ticket with valid parameters or have a valid inputs so these 44 00:03:35,410 --> 00:03:39,070 are gonna be the different tests we're going to write out and after we write out each test we'll try 45 00:03:39,070 --> 00:03:41,150 to actually make each one pass. 46 00:03:41,260 --> 00:03:45,820 Right now let's just save the file go back over to our terminal and remember how we actually run our 47 00:03:45,820 --> 00:03:47,000 test suite. 48 00:03:47,080 --> 00:03:53,060 So back at my terminal I'm going to make sure I'm inside my tickets project directory so I'm no longer 49 00:03:53,060 --> 00:03:57,590 inside of ticketing I'm inside of tickets and once I'm inside there I'm going to start my test suite 50 00:03:57,590 --> 00:04:05,370 by running NPM run test it found my test file I can run all the test inside there and right now they 51 00:04:05,370 --> 00:04:13,060 are all passing because we don't actually have any test code inside of any of them yet. 52 00:04:13,190 --> 00:04:16,600 So let's flip back over and let's start to focus on this first one. 53 00:04:16,610 --> 00:04:18,980 First of reports and we'll tackle it in the next video.