1 00:00:01,140 --> 00:00:01,400 All right. 2 00:00:01,410 --> 00:00:06,840 Let's do a quick series of tests around this expiration complete listener inside my order service. 3 00:00:06,840 --> 00:00:12,630 I'll find the listeners directory test folder inside there and we'll make a new file of expiration complete 4 00:00:13,040 --> 00:00:20,880 listener dot test dot to yes this listener Test File once again going to look identical to all the other 5 00:00:20,880 --> 00:00:23,190 test files we put together for our listeners. 6 00:00:23,260 --> 00:00:26,020 So at the very top we're going to add in a couple of imports for the listener. 7 00:00:26,050 --> 00:00:28,960 Nats rapper that's actually gonna be the Nats rapper. 8 00:00:28,980 --> 00:00:33,230 Mark of course but they're going to build a setup function do all that kind of data setup. 9 00:00:33,420 --> 00:00:34,590 You get the idea. 10 00:00:34,590 --> 00:00:37,950 Business as usual don't get to it at the very top. 11 00:00:37,950 --> 00:00:39,190 I'm going to first imports. 12 00:00:39,300 --> 00:00:45,990 The one thing I know that I absolutely need and that is the listener will get my expiration complete 13 00:00:45,990 --> 00:00:55,220 listener from up one directory expiration complete I'll then build my setup function inside of here. 14 00:00:55,270 --> 00:01:03,570 Well let's make our instance that will be a new expiration complete listener and we do have to provide 15 00:01:03,600 --> 00:01:05,310 a Nats client to it. 16 00:01:05,450 --> 00:01:06,510 That's the air we're getting right here. 17 00:01:06,540 --> 00:01:13,350 So let's make sure that we import Nats rapper from up to directories. 18 00:01:13,360 --> 00:01:18,580 Note 3 Nats rapper and then we can provide Nats rapper that client 19 00:01:21,770 --> 00:01:22,620 get after that. 20 00:01:22,620 --> 00:01:27,340 We're going to first build out in order we're going to associate with a ticket so everything is in the 21 00:01:27,340 --> 00:01:32,890 right state and then we're going to save both the order and the ticket to do so we do have to get access 22 00:01:32,890 --> 00:01:35,260 to the ticket model and the order model. 23 00:01:35,320 --> 00:01:37,030 So let's do that at the top. 24 00:01:37,030 --> 00:01:41,680 I'll get my order from up 3 directories models order 25 00:01:44,830 --> 00:01:48,260 and then my ticket from up 3 directories models ticket 26 00:01:51,570 --> 00:01:52,540 then down inside of setup. 27 00:01:52,570 --> 00:01:55,210 Let's first build up our ticket and save it. 28 00:01:55,210 --> 00:02:04,720 They'll say ticket is ticket dot build this thing will have some title then price. 29 00:02:04,730 --> 00:02:07,670 And remember we have to provide this thing an idea as well. 30 00:02:07,790 --> 00:02:15,410 We'll get this thing at a hardcoded I.D. which we're going to generate from Mongoose and I really should 31 00:02:15,410 --> 00:02:20,020 not refer to that as a hard coded I.D. because we are randomly generating it both throw in here Mongoose 32 00:02:20,020 --> 00:02:23,570 stock types object I.D. to hex string 33 00:02:26,420 --> 00:02:33,970 we can then say that to get there we'll build up our order so we'll do an ordered up built 34 00:02:37,040 --> 00:02:39,220 in order it's gonna get a couple of different properties. 35 00:02:39,380 --> 00:02:42,870 So user I.D. status all this different stuff. 36 00:02:43,070 --> 00:02:45,500 In this case we don't really care about the user I.D.. 37 00:02:45,530 --> 00:02:51,500 Once again we also don't really care all that much about expires that because we are canceling an order 38 00:02:51,530 --> 00:02:56,540 no matter what whenever we received that expiration complete event so we get through in some arbitrary 39 00:02:56,540 --> 00:02:59,280 string for expires out without a doubt. 40 00:02:59,360 --> 00:03:03,980 However the status doesn't mean that ticket needs to be a real ticket and status needs to be the correct 41 00:03:03,980 --> 00:03:05,060 status as well. 42 00:03:05,100 --> 00:03:08,860 They're probably gonna have to import that order status in from our coming module once again. 43 00:03:09,470 --> 00:03:12,700 Well let's begin with that up at the top of the file at the top. 44 00:03:12,710 --> 00:03:14,590 We will get our order status 45 00:03:18,170 --> 00:03:19,100 from our common module 46 00:03:22,210 --> 00:03:30,590 then on our build statement we'll plug in a status of order status dot read it we'll just go through 47 00:03:30,620 --> 00:03:31,650 all those other properties. 48 00:03:31,650 --> 00:03:35,650 We've got a user I.D. that will be whatever we've gotten expires at. 49 00:03:35,660 --> 00:03:43,670 That can be whatever and then a ticket which will be the ticket that we had defined right before now 50 00:03:43,730 --> 00:03:45,770 getting an area around expires out right here. 51 00:03:45,770 --> 00:03:49,870 Oh my mistake needs to be actually be a date not a plane string. 52 00:03:49,880 --> 00:03:52,430 It's a plane string once we transmit it in our event. 53 00:03:52,430 --> 00:03:55,640 But as we are plugging it into the build method it does need to be an actual date. 54 00:03:55,640 --> 00:04:00,380 So we'll just make a new date object and throw that in now networks. 55 00:04:00,540 --> 00:04:10,070 So we can now save that order though wait ordered save and that is it for our data level so we can create 56 00:04:10,100 --> 00:04:13,230 our actual event or create the message as well. 57 00:04:13,340 --> 00:04:15,020 And we should be good to go. 58 00:04:15,140 --> 00:04:17,390 Let's first create the event to do so. 59 00:04:17,390 --> 00:04:23,600 We should get the event interface from our common module as well that we will import the expiration 60 00:04:23,600 --> 00:04:25,910 that complete event. 61 00:04:26,010 --> 00:04:32,100 And while we're up here since we know we're going to need it let's also get that message type from the 62 00:04:32,940 --> 00:04:39,440 Nats streaming library from node Nat streaming. 63 00:04:39,510 --> 00:04:49,100 So now we can build up our fake data object it'll be of type order the expiration that complete event 64 00:04:49,190 --> 00:04:50,640 at data every. 65 00:04:50,690 --> 00:04:52,970 Just so many variable names floating around here. 66 00:04:53,020 --> 00:04:55,770 It definitely does get confusing pretty quickly. 67 00:04:55,850 --> 00:04:59,310 Now this event we're expected to provide some order I.D. property. 68 00:04:59,330 --> 00:05:03,170 And of course you can mouse over that area there and we'll be told that we'll give the thing an order 69 00:05:03,170 --> 00:05:05,330 I.D. which will come from order dot I.D.. 70 00:05:05,340 --> 00:05:05,860 That's the idea. 71 00:05:05,870 --> 00:05:14,440 The order that we just built and saved will then also create our message it'll be of type message. 72 00:05:14,980 --> 00:05:18,420 And as usual it's just going to have an ACH function. 73 00:05:18,490 --> 00:05:19,470 There'll be adjust. 74 00:05:19,480 --> 00:05:26,050 Mark and we're just going to tell typescript let it be Let it be. 75 00:05:26,250 --> 00:05:26,780 So that's it. 76 00:05:26,840 --> 00:05:29,050 So now we can't take all these variables. 77 00:05:29,050 --> 00:05:31,860 We probably don't really need that ticket to be returned from setup. 78 00:05:31,890 --> 00:05:32,950 But we will anyways. 79 00:05:33,070 --> 00:05:39,560 We're going to take basically everything we just created and return it from setup so my listener my 80 00:05:39,560 --> 00:05:47,070 order my ticket data and the message and that's our setup function. 81 00:05:47,080 --> 00:05:48,340 Let's take a quick pause right here. 82 00:05:48,340 --> 00:05:51,160 We'll start to write out our actual individual tests in just a moment.