1 00:00:01,140 --> 00:00:05,940 Let's put a test together around our order cancel listener s I mentioned this is an entirely optional 2 00:00:05,940 --> 00:00:09,900 video so if you don't want to do any testing if you're just tired of it inside this course no problem. 3 00:00:09,900 --> 00:00:12,320 Just pause right here and move on to the next video. 4 00:00:12,360 --> 00:00:14,690 Otherwise stick around and let's get to it. 5 00:00:14,700 --> 00:00:16,860 Let's get started inside of our test directory. 6 00:00:16,860 --> 00:00:23,230 We'll make a new file of order canceled listener test not t s 7 00:00:26,750 --> 00:00:27,760 and then inside of here. 8 00:00:27,850 --> 00:00:33,600 Once again we'll make a setup function it'll be async at the top. 9 00:00:33,610 --> 00:00:38,560 We'll immediately add in a bunch of different imports and then write out the entire setup function so 10 00:00:38,620 --> 00:00:39,170 as usual. 11 00:00:39,190 --> 00:00:47,520 We definitely need our order answer listener from up one directory order and a listener. 12 00:00:47,580 --> 00:00:55,300 We definitely need our Nats rapper from up 3 directories we get that Nats rapper let's great the listener 13 00:00:55,300 --> 00:01:02,380 right away so make a listener as New Order canceled listener and past in my Nats rapper 14 00:01:05,900 --> 00:01:09,380 after that we're going to create a new order and save it to our database. 15 00:01:09,410 --> 00:01:12,550 This is going to be the order that we're going to eventually try to cancel. 16 00:01:12,550 --> 00:01:18,670 So at the top once again I will import my order model from up 3 directories 17 00:01:23,290 --> 00:01:26,500 then create an order with order dot build 18 00:01:29,800 --> 00:01:33,110 and we do have to provide a different a few different properties for the thing. 19 00:01:33,250 --> 00:01:39,400 So we do have to give it a realistic looking I.D. a version probably hardcoded at zero and then a user 20 00:01:39,400 --> 00:01:43,200 I.D. at the price and the status over the I.D. and the status. 21 00:01:43,240 --> 00:01:48,130 We're going to need the Mongoose library to generate the I.D. and we'll need our order status in from 22 00:01:48,160 --> 00:01:49,450 our com module. 23 00:01:49,450 --> 00:01:50,980 Let's add those imports at the very top 24 00:01:57,040 --> 00:02:02,470 and our order status income from the company module. 25 00:02:02,550 --> 00:02:07,680 So now instead of order duck billed we'll pass it an I.D. coming from Mongoose stock type start object 26 00:02:07,680 --> 00:02:12,790 I.D. to hex string. 27 00:02:13,020 --> 00:02:19,460 I'll give it a status of order status dot created a price. 28 00:02:19,460 --> 00:02:24,820 How about 10 user I.D. of whatever and what other property am I missing here. 29 00:02:24,820 --> 00:02:28,240 Let's see version of course we'll give a version of 0 30 00:02:31,420 --> 00:02:33,530 then immediately after creating the order let's save it. 31 00:02:33,550 --> 00:02:38,050 So we'll do an order not save and we'll make sure to await that 32 00:02:41,480 --> 00:02:41,730 case. 33 00:02:41,740 --> 00:02:43,330 That is our initial setups. 34 00:02:43,330 --> 00:02:49,000 Now we can create a data object that's going to try to mark this order as being canceled so for that 35 00:02:49,000 --> 00:02:54,370 we're definitely going to need our order canceled event interface from the common module let's import 36 00:02:54,370 --> 00:02:55,390 that as well. 37 00:02:55,480 --> 00:02:58,240 So order canceled event 38 00:03:02,470 --> 00:03:05,440 and then after we create our order we'll make our data object. 39 00:03:05,710 --> 00:03:09,310 It will be of type order canceled event at data 40 00:03:12,250 --> 00:03:16,300 so we need to make sure that this thing has the same ideas as the order we had just created. 41 00:03:16,300 --> 00:03:22,130 Well given an idea coming from order dot I.D. and there's a couple of other properties we have to define 42 00:03:22,130 --> 00:03:27,650 as well we need to make sure this thing also has a version a ticket and inside there should be some 43 00:03:27,650 --> 00:03:28,280 kind of I.D.. 44 00:03:28,490 --> 00:03:31,460 That's the idea that ticket doesn't only matter because we're not using it here. 45 00:03:31,460 --> 00:03:36,080 Well that really matters is the version number in the version should definitely be the previous version 46 00:03:36,110 --> 00:03:41,040 plus one we'll get a version add 1 47 00:03:44,540 --> 00:03:47,510 then we'll give it a ticket with an I.D.. 48 00:03:47,570 --> 00:03:52,950 And again we can give it any I.D. we want because we're not really using that I.D.. 49 00:03:53,030 --> 00:03:59,650 And then finally our message object to the message object as usual we will import the message type from 50 00:03:59,830 --> 00:04:05,560 node that string at the top. 51 00:04:05,760 --> 00:04:10,110 I'm going to tell typescript to ignore this next line and we'll make our message 52 00:04:14,910 --> 00:04:16,070 so it'll have the ACT function. 53 00:04:16,090 --> 00:04:17,190 It's going to just mark. 54 00:04:17,200 --> 00:04:22,540 Same exact thing we've done it many times for now that we've got everything put together as usual time 55 00:04:22,540 --> 00:04:23,080 to return it. 56 00:04:23,080 --> 00:04:27,490 So the return listener data message in the order as well 57 00:04:32,320 --> 00:04:40,200 said we can write out the actual test and we'll say it updates the status of the order and I'll make 58 00:04:40,200 --> 00:04:44,460 a second test just to say again X the message 59 00:04:49,370 --> 00:04:59,420 will D structure off our listener data message in order from calling a weight setup and then await the 60 00:04:59,690 --> 00:05:08,740 listeners on message function to which we'll pass in our data and message and then as usual we really 61 00:05:08,740 --> 00:05:10,830 want those two lines inside of both our tests. 62 00:05:10,840 --> 00:05:15,830 So I will copy paste them down to 4 update the status of the order. 63 00:05:15,890 --> 00:05:17,330 Well I bet you can guess what we're gonna do there. 64 00:05:17,330 --> 00:05:21,350 We're going to refresh the order out of the database and make sure that its status was updated you to 65 00:05:21,350 --> 00:05:22,070 canceled. 66 00:05:22,070 --> 00:05:25,410 That's pretty much it. 67 00:05:25,450 --> 00:05:33,750 Give an updated order and that will come from a wait order find by I.D. And we want to look up the order 68 00:05:33,750 --> 00:05:40,940 I.D. So the existing order one is the same idea right there the order dot I.D. we can expect the updated 69 00:05:41,000 --> 00:05:49,670 order exclamation not status to equal the order status enum canceled property 70 00:05:54,860 --> 00:05:57,240 date and then our second test right here. 71 00:05:57,270 --> 00:05:59,230 I bet you can guess what we're gonna do here. 72 00:05:59,240 --> 00:05:59,490 Yeah. 73 00:05:59,520 --> 00:06:08,020 Just a simple expect message dot EQ to have been called and that's it let's flip back over to a terminal 74 00:06:08,020 --> 00:06:10,340 and make sure these two tests are passing. 75 00:06:10,540 --> 00:06:13,900 So back over at my terminal Yep looks like everything's good to go. 76 00:06:13,900 --> 00:06:19,180 However as usual we'll do a quick comment out of the on message call on both and it just makes sure 77 00:06:19,180 --> 00:06:23,540 we now have two test failures get two failures. 78 00:06:23,550 --> 00:06:26,220 That means that our tests are working as expected. 79 00:06:26,220 --> 00:06:32,440 So I will uncommon but those await listener on message calls and we are also at this test again. 80 00:06:32,460 --> 00:06:36,050 I know I said it so many times really boring test looks identical to everything else. 81 00:06:36,060 --> 00:06:39,080 But again we now know that this thing works as expected. 82 00:06:39,270 --> 00:06:42,090 Does pause right here and move on to our next topic in just a moment.