1 00:00:01,760 --> 00:00:06,620 As I just mentioned we're going to write out a really quick test around this show a root handler inside 2 00:00:06,620 --> 00:00:07,510 my test directory. 3 00:00:07,550 --> 00:00:10,180 I'll make a new file of show test. 4 00:00:10,190 --> 00:00:14,360 T.S. then at the top couple of imports here. 5 00:00:14,390 --> 00:00:22,460 As usual we will get requests no brackets on their from super test. 6 00:00:22,520 --> 00:00:31,530 We'll get our Express app from up to directories app and we'll also all in the ticket model so that 7 00:00:31,530 --> 00:00:39,730 we can create a ticket so that we can associate that thing with a new order so we'll get ticket from 8 00:00:39,810 --> 00:00:48,870 up to directories as well models ticket will write out our actual test will say it matches the order 9 00:00:50,210 --> 00:00:58,660 pretty simple inside of here we're going to once again create a ticket will then make a request to build 10 00:00:58,660 --> 00:01:07,370 an order with this ticket and then finally make a request to match the order 11 00:01:10,550 --> 00:01:14,030 when we make the request to build the order with the ticket and then the follow up request to fetch 12 00:01:14,030 --> 00:01:14,540 the order. 13 00:01:14,540 --> 00:01:19,010 We once again need to make sure that we're making those two requests as the same user because if we 14 00:01:19,010 --> 00:01:23,840 make these as different users then chances are trying to fetch that order is going to fail because we're 15 00:01:23,840 --> 00:01:27,540 trying to access a order that's been created by a different user. 16 00:01:27,560 --> 00:01:31,850 So again it's just going to look pretty similar to what we did back inside of our index test file not 17 00:01:31,850 --> 00:01:33,230 a lot more explanation needed. 18 00:01:33,230 --> 00:01:38,330 So let's get this code together first thing create the ticket because we're only creating one ticket 19 00:01:38,360 --> 00:01:38,900 inside of here. 20 00:01:38,910 --> 00:01:43,940 Right now we'll just create the ticket directly in line rather than creating a helper function will 21 00:01:44,000 --> 00:01:59,210 say ticket is ticket dot build with some title and a price then save our ticket after that we'll create 22 00:01:59,240 --> 00:02:05,220 our user with global sign in and when I say create the user I'm really saying we're going to create 23 00:02:05,250 --> 00:02:11,720 a cookie that encodes some particular user inside of it we can then make a request to build that order 24 00:02:11,990 --> 00:02:19,660 with that user and we're going to build the order with that ticket so we'll do it in a weight request 25 00:02:19,660 --> 00:02:27,740 to app we want to do a post request to API orders we definitely want to authenticate ourselves as the 26 00:02:27,740 --> 00:02:34,310 user that we just created and we're gonna send along a ticket I.D. of ticket dot I.D. And then finally 27 00:02:35,120 --> 00:02:37,180 I'll expect that that goes successfully. 28 00:02:37,310 --> 00:02:42,350 So we'll do it in an expect of 2 a 1. 29 00:02:42,390 --> 00:02:46,620 Now when we built up this order it's going to give us back our response and inside of that response 30 00:02:46,680 --> 00:02:49,440 is gonna be the idea of the order that was created. 31 00:02:49,440 --> 00:02:54,090 We need that order I.D. because when we access the showroom handler we have to specify the idea of the 32 00:02:54,090 --> 00:02:56,300 order that we are attempting to fetch. 33 00:02:56,460 --> 00:03:00,490 Don't make sure that we get the response here. 34 00:03:00,490 --> 00:03:03,040 Once again we don't really care about the entire response. 35 00:03:03,100 --> 00:03:08,010 So we could do structure off just the property we care about which is body we don't even care about 36 00:03:08,010 --> 00:03:10,130 having a variable name necessarily body. 37 00:03:10,140 --> 00:03:15,270 We really kind of made you want to rename this thing on the fly once again and say that this is the 38 00:03:15,360 --> 00:03:16,710 order that we are trying to find 39 00:03:22,040 --> 00:03:31,170 now we'll make our follow up request to fetch that order I'll do in await request to app we'll do a 40 00:03:31,170 --> 00:03:38,260 get we're gonna use some string templating here so notice the tactics we'll put in API orders and get 41 00:03:38,260 --> 00:03:40,170 the idea of the order that we are trying to fetch. 42 00:03:40,250 --> 00:03:43,670 And that idea is gonna come out of that order variable right there. 43 00:03:43,700 --> 00:03:50,570 So we'll do some string interpolation order dot I.T. we'll make sure that we set our cookie so that 44 00:03:50,570 --> 00:03:59,440 we are making this request as the same user are going to set it to user. 45 00:03:59,610 --> 00:04:01,650 We will send this request off. 46 00:04:01,650 --> 00:04:04,680 And then finally we will expect to get a two hundred back 47 00:04:07,710 --> 00:04:12,250 and we could definitely tried to get the response that comes back and take a look at the data that we 48 00:04:12,250 --> 00:04:13,960 actually received. 49 00:04:13,960 --> 00:04:19,150 So for that we could do structure off body once again in this case. 50 00:04:19,160 --> 00:04:27,120 I will rename that body variable just to distinguish it from the body up here as batch order and then 51 00:04:27,130 --> 00:04:31,340 we can write out an expectation to make sure that this thing has the same ideas as the order that we 52 00:04:31,340 --> 00:04:31,690 created. 53 00:04:31,690 --> 00:04:44,720 Up here so we could do an expect batch order not I.D. to equal order dot I.D. gets Alex good we're gonna 54 00:04:44,720 --> 00:04:45,650 save this. 55 00:04:45,650 --> 00:04:50,510 Take a look at our terminal and see how we're doing and it looks like we're passing. 56 00:04:50,510 --> 00:04:55,220 As usual I'm gonna change one these expectations to say five hundred just to make sure the file actually 57 00:04:55,220 --> 00:04:59,860 got saved updated by just Yep looks like it did. 58 00:04:59,870 --> 00:05:01,900 So we're good to go okay. 59 00:05:01,930 --> 00:05:06,200 So this right here really tests out the happy path or everything going as expected. 60 00:05:06,280 --> 00:05:11,350 We could also add in one or two tests to make sure that if the order is not found we return it for a 61 00:05:11,350 --> 00:05:15,810 four or probably more importantly if the user tries to fetch an order that doesn't belong to them. 62 00:05:16,000 --> 00:05:19,760 We sent back a for a one of not authorized. 63 00:05:19,990 --> 00:05:23,380 I'm not really gonna sweat the forum for you could definitely write out a test on your own if you want 64 00:05:23,380 --> 00:05:27,880 to test that but I think that it would be kind of nice to make sure that one user is not able to fetch 65 00:05:27,940 --> 00:05:33,550 another user's orders so I can write out a very quick test for that and I'm only going to write out 66 00:05:33,550 --> 00:05:38,020 very quickly because well we can really just copy paste the test we already wrote changed one or two 67 00:05:38,020 --> 00:05:40,940 variables and make it all work as expected. 68 00:05:40,950 --> 00:05:49,040 It's gonna take the entire test we just wrote or copy it and then paste it down right underneath I'll 69 00:05:49,040 --> 00:05:52,020 change the description of this copy paste to it. 70 00:05:53,220 --> 00:05:59,660 Returns an error if one user tries to fetch another user's order. 71 00:05:59,790 --> 00:06:05,570 We could probably write out a better description there but I think that's pretty well descriptive now 72 00:06:05,570 --> 00:06:06,200 in this case. 73 00:06:06,230 --> 00:06:10,940 We're going to still build up a ticket it's still going to create up in order but then when we make 74 00:06:10,940 --> 00:06:16,130 the request to fetch that order we do not want to make this request as the same user. 75 00:06:16,250 --> 00:06:20,000 So rather than putting in the same use right there I'm going to create a new user by calling global 76 00:06:20,000 --> 00:06:26,810 sign in so now we're going to in theory get back a 4 or 1 status code from this. 77 00:06:26,920 --> 00:06:31,450 I don't really care about the body that we get anymore so I'll delete all that stuff and also delete 78 00:06:31,450 --> 00:06:36,630 the expectation at the bottom and I should be able to just change the status code on the expected 2 79 00:06:36,630 --> 00:06:39,430 4 0 1 All right. 80 00:06:39,440 --> 00:06:40,970 Let's say this and see how we're doing 81 00:06:44,420 --> 00:06:46,010 and it passes as usual. 82 00:06:46,010 --> 00:06:47,840 Real quick change here. 83 00:06:47,840 --> 00:06:49,200 So I'll take it over to 500. 84 00:06:49,220 --> 00:06:50,390 Make sure the thing fails 85 00:06:53,150 --> 00:06:53,460 Yep. 86 00:06:53,520 --> 00:06:54,360 Looks good. 87 00:06:54,360 --> 00:06:55,870 Back to 4 0 1. 88 00:06:56,010 --> 00:06:57,380 And we are all set. 89 00:06:59,170 --> 00:07:00,710 Well that's pretty much it for our show. 90 00:07:00,710 --> 00:07:05,800 Root handler pretty effective test for it so we just have one last row handler. 91 00:07:05,890 --> 00:07:10,000 We've got the one that's going to allow us to delete in order or essentially cancel it. 92 00:07:10,000 --> 00:07:14,080 Turns out we're not going to actually delete it out of our database but we will go ahead and cancel 93 00:07:14,080 --> 00:07:14,490 it. 94 00:07:14,500 --> 00:07:16,930 We'll take a look at what we really mean by that in the next video.