1 00:00:01,250 --> 00:00:02,930 Let's move on to our next two tests. 2 00:00:02,930 --> 00:00:06,780 All we're going to be doing here is making sure that a title and a price are provided. 3 00:00:06,860 --> 00:00:11,290 If they are not we're going to want to make sure that we return some kind of air to the user. 4 00:00:11,290 --> 00:00:14,000 So let's write out our test implementation first. 5 00:00:14,000 --> 00:00:19,430 So in this first one let's attempt to send in a request with some kind of invalid title. 6 00:00:19,430 --> 00:00:22,820 Now we haven't really said exactly what makes a title invalid. 7 00:00:22,820 --> 00:00:28,280 So for right now let's assume that if we put in a empty title or no title at all we should get back 8 00:00:28,340 --> 00:00:29,680 some kind of air. 9 00:00:29,900 --> 00:00:38,670 So going to write out a wait request to app I want to make a post to API tickets are going to make sure 10 00:00:38,670 --> 00:00:39,740 this thing is authenticated. 11 00:00:39,750 --> 00:00:48,160 So we're gonna set that cookie with global sign in and then send along some data. 12 00:00:48,210 --> 00:00:49,740 So what data we can send here. 13 00:00:49,750 --> 00:00:54,870 Again we want to make sure that the title is what we think is gonna be valid or invalid and we want 14 00:00:54,870 --> 00:00:57,150 to make sure that the price is valid. 15 00:00:57,150 --> 00:01:03,180 So I will first put in a title of about empty string and I'll put in a price of something it looks kind 16 00:01:03,180 --> 00:01:06,160 of valid to me looking to put in a number here of 10. 17 00:01:06,170 --> 00:01:10,140 Now you might recall we had a diagram a little bit ago that said we're going to send in price as a string. 18 00:01:10,140 --> 00:01:15,100 We'll just ignore that for right now let's say price is going to be a number. 19 00:01:15,120 --> 00:01:18,450 So how are we going to say that this should result in some kind of error. 20 00:01:18,450 --> 00:01:25,020 Well once again let's think about how we handle invalid request or invalid request data. 21 00:01:25,020 --> 00:01:29,910 If we go back over to our common module you might recall that we've got a middleware that we put together 22 00:01:30,060 --> 00:01:32,860 to help us validate incoming requests. 23 00:01:32,940 --> 00:01:35,430 So it's something about the incoming request was not valid. 24 00:01:35,430 --> 00:01:39,700 We would throw a error of request validation error. 25 00:01:39,760 --> 00:01:42,400 Let's go take a look at what that it really looks like. 26 00:01:42,400 --> 00:01:47,850 So inside my ears directory again inside the com module I will find request validation error and so 27 00:01:47,850 --> 00:01:53,490 something is wrong with the incoming request we return a status code of 400 along with the actual error 28 00:01:53,490 --> 00:01:55,160 messages and whatnot. 29 00:01:55,170 --> 00:01:57,000 I don't want to sweat that your messages right now. 30 00:01:57,000 --> 00:02:04,980 I kind of just want to make sure that we get back a status code of 400 so back inside of my test after 31 00:02:04,980 --> 00:02:09,930 making this invalid request I will expect a status code of 400 32 00:02:13,230 --> 00:02:19,040 if we want to be even a little bit more complete we could make that same request a second time and in 33 00:02:19,040 --> 00:02:23,470 the second request we could say let's not even send along a title at all. 34 00:02:23,510 --> 00:02:26,770 So if we send a title that is empty or if we don't send a title. 35 00:02:26,840 --> 00:02:33,020 In both cases we should be marking that request as invalid while that looks good to me. 36 00:02:33,020 --> 00:02:40,190 So I got to say the file and it looks like we've got our failed test now we could go and fix up our 37 00:02:40,190 --> 00:02:45,940 root handler right away but let's just continue and write out the test for invalid price as well because 38 00:02:46,180 --> 00:02:50,970 that's gonna be just about identical to what we did right here so I'm going to copy one these requests 39 00:02:50,970 --> 00:02:57,910 blocks again and move it down to the price stuff so for price let's take these same kind of approach. 40 00:02:57,940 --> 00:03:02,860 Let's first try to send in some data that feels like it should probably be invalid and we'll try to 41 00:03:02,860 --> 00:03:07,890 send in another request that doesn't even have the property we're talking about at all so I'm going 42 00:03:07,890 --> 00:03:14,870 to actually paste that thing in twice on the first one I will send in a title that is probably going 43 00:03:14,870 --> 00:03:18,710 to be valid and the reason I'm saying probably here again is because we have not set up any validation 44 00:03:18,710 --> 00:03:19,330 rules yet. 45 00:03:19,410 --> 00:03:22,600 I'm just kind of taking a guess on what we probably want to have. 46 00:03:22,640 --> 00:03:28,320 Now on the first one I'm gonna provide a price that is present but probably not a valid value. 47 00:03:28,370 --> 00:03:33,530 So in this case I can put in negative 10 chances are we probably don't want a user listing stuff for 48 00:03:33,560 --> 00:03:38,120 negative values so we're probably going to want to say that a price has to be greater than zero. 49 00:03:38,120 --> 00:03:41,330 And so this right here should probably result in some kind of error. 50 00:03:41,570 --> 00:03:47,770 Then on the second one we will once again put in a valid title but I won't put in a price at all that 51 00:03:47,870 --> 00:03:48,920 looks good. 52 00:03:49,100 --> 00:03:55,710 Say this again look back over and we now have both of our validation tests failing. 53 00:03:55,870 --> 00:03:57,230 That's good. 54 00:03:57,230 --> 00:04:02,390 So let's go over to our actual request handler. 55 00:04:02,580 --> 00:04:04,660 Here it is right here. 56 00:04:04,700 --> 00:04:06,750 I don't want to have this video running too long. 57 00:04:06,770 --> 00:04:08,740 So let's take a quick pause right here. 58 00:04:08,760 --> 00:04:12,080 We'll start to put in some logic to validate that income request in just a moment.