1 00:00:00,830 --> 00:00:05,520 Set up function complete let's write out our tests so our tests are going to be pretty straightforward 2 00:00:05,520 --> 00:00:06,090 in nature. 3 00:00:06,090 --> 00:00:08,800 We really just want to make sure that we can call on message. 4 00:00:08,880 --> 00:00:14,160 We're going to make sure that we update the order status and save it and we'll also make sure that we 5 00:00:14,160 --> 00:00:18,840 emit some new events of order canceled publisher and at some point time we should probably also make 6 00:00:18,840 --> 00:00:23,740 sure we call the act function back inside the TEST file. 7 00:00:23,760 --> 00:00:25,920 I'm gonna write out three separate test this time. 8 00:00:26,010 --> 00:00:31,060 We previously just combined three tests together into one and I'd said you probably shouldn't do this. 9 00:00:31,170 --> 00:00:33,950 I really dislike in the course doing one thing and saying Oh yeah. 10 00:00:33,960 --> 00:00:36,650 Don't do this so we're just gonna write this out correctly. 11 00:00:36,640 --> 00:00:45,480 We're going to make three separate tests going to first say it updates the order status to canceled. 12 00:00:45,660 --> 00:00:46,470 That's the first thing we want. 13 00:00:46,470 --> 00:00:47,780 We want to take care of. 14 00:00:48,070 --> 00:01:01,200 Well then make sure that we emit a an order canceled event and then naturally we should ask a message. 15 00:01:01,230 --> 00:01:01,510 All right. 16 00:01:01,510 --> 00:01:02,020 Each of these. 17 00:01:02,020 --> 00:01:03,410 We've pretty much done before. 18 00:01:03,430 --> 00:01:05,330 So should be pretty straightforward in nature. 19 00:01:05,410 --> 00:01:13,180 In all three of them we definitely want to pull the listener order ticket data and message from a weight 20 00:01:13,390 --> 00:01:13,830 setup. 21 00:01:15,330 --> 00:01:18,770 And we're definitely going to want to in all three of them awaits listener. 22 00:01:18,850 --> 00:01:25,110 On message and pass in data and message because they all need this. 23 00:01:25,120 --> 00:01:27,100 Let's just do a copy paste right away. 24 00:01:27,190 --> 00:01:31,940 I'm going to take those two lines and paste them in the other two tests and then we can go through and 25 00:01:31,940 --> 00:01:34,720 fill out the expectations for each. 26 00:01:34,780 --> 00:01:37,520 So on this first one I bet you could guess we're gonna do here. 27 00:01:37,520 --> 00:01:41,870 We're going to reach into to our order collection we're gonna find the order that has been saved hopefully 28 00:01:41,870 --> 00:01:46,430 updated we're gonna fetch it out of that collection and then just make sure that these stats property 29 00:01:46,430 --> 00:01:56,360 was updated to canceled pretty much at so we'll do a an updated order will be and a wait order find 30 00:01:56,440 --> 00:02:00,420 by order I.D. number. 31 00:02:00,430 --> 00:02:06,910 We do have the order right there but in theory that is an out of date version of the order so then we'll 32 00:02:06,910 --> 00:02:08,070 do it in expectation. 33 00:02:08,080 --> 00:02:19,000 I'll make sure that the updated order status property equals order status dot cancelled as usual. 34 00:02:19,080 --> 00:02:21,960 Let's say that exclamation on there we've been over that so many times now. 35 00:02:23,050 --> 00:02:27,640 Is that should be it for a test number one we'll run all these and make sure they all fail at the end. 36 00:02:27,670 --> 00:02:32,270 Let's just make them or put together some implementation for all three to get started. 37 00:02:32,270 --> 00:02:34,330 Next up is order cancelled. 38 00:02:34,370 --> 00:02:39,650 So we need to somehow take a look at our Nats wrapper mock right here. 39 00:02:39,650 --> 00:02:41,900 We've been over this once before as well. 40 00:02:41,930 --> 00:02:46,650 Remember the Nats wrapper it is a mock function or specifically the public function inside there. 41 00:02:46,700 --> 00:02:52,370 So we're going to get the Nats wrapper dot client dot publish and we're gonna take a look at that mock 42 00:02:52,520 --> 00:02:57,490 and just make sure that it was called and if we want to we can also make sure there was called with 43 00:02:57,490 --> 00:03:04,210 a very specific set of arguments to back down at the order canceled events. 44 00:03:04,450 --> 00:03:12,400 We're gonna throw in a Nats wrapper client not publish and then remember this Polish function is a just 45 00:03:12,480 --> 00:03:12,970 Mark. 46 00:03:13,420 --> 00:03:21,050 So to help typescript understand that we can then put down as just dots mark it's an typescript is gonna 47 00:03:21,050 --> 00:03:24,650 understand that this thing is supposed to be a mock function and it's going to give us access to all 48 00:03:24,650 --> 00:03:27,670 the appropriate properties on there without complaining to us a whole bunch. 49 00:03:28,840 --> 00:03:32,880 Going gonna wrap that with parentheses and then remember if you want to get access to all the different 50 00:03:32,880 --> 00:03:34,690 times its function has been invoked. 51 00:03:34,800 --> 00:03:40,680 We can chain on a dot calls or see me marked calls. 52 00:03:40,690 --> 00:03:41,620 That's better. 53 00:03:42,680 --> 00:03:46,160 And that's gonna be an array of all the different times all the different arguments that this thing 54 00:03:46,160 --> 00:03:52,070 has been provided over time so publish should have only been invoked one single time. 55 00:03:52,070 --> 00:03:57,440 So take a look at the first time it was called and then maybe we want to just make sure that this event 56 00:03:57,440 --> 00:03:59,000 that we just published. 57 00:03:59,000 --> 00:04:03,050 How about let's say that we make sure it has the correct order I.D. inside of it back inside of our 58 00:04:03,050 --> 00:04:03,710 listener. 59 00:04:03,710 --> 00:04:04,960 Here's what we are publishing. 60 00:04:05,060 --> 00:04:11,330 So we might just want to make sure that we are emitting the event with the correct order i.e. so that 61 00:04:11,360 --> 00:04:14,600 we can get access to the second argument inside there. 62 00:04:14,600 --> 00:04:19,550 Because remember the first argument is the subject or the channel name that we are publishing this event 63 00:04:19,550 --> 00:04:23,670 to this is gonna give us back the entire data object as Jason. 64 00:04:23,680 --> 00:04:28,710 So we have to turn it into an actual object and we can pull the I.D. property out of it. 65 00:04:28,900 --> 00:04:37,770 So do a Jason pass wrap that entire thing with a set of parentheses and I'll sign this to you about 66 00:04:37,860 --> 00:04:42,040 event data because that line is getting really long 67 00:04:45,640 --> 00:04:53,450 then let's do an expectation here and we'll say that we expect event data dot I.T. to equal order i.e. 68 00:04:55,110 --> 00:04:58,480 we can also just very simply maybe on the line right above all that stuff. 69 00:04:58,620 --> 00:05:03,810 We could add in a very simple expectation just to make sure that the MOC itself is published function 70 00:05:03,810 --> 00:05:08,820 actually was invoked though kind of two stage expectation is really nice in that regard because you 71 00:05:08,820 --> 00:05:12,540 can first make sure that the thing called and then maybe even if it was called it might have been given 72 00:05:12,540 --> 00:05:13,950 the incorrect arguments. 73 00:05:13,950 --> 00:05:19,320 And so the two stage kind of setup or two expectations helps you debug stuff in the future. 74 00:05:19,320 --> 00:05:28,500 So right above that event data stuff I'll put in a Nats wrapper client publish Do you have come on Ben 75 00:05:28,680 --> 00:05:29,040 felt 76 00:05:33,000 --> 00:05:37,260 now if you do not really remember this part right here from the last time we did it you could take that 77 00:05:37,260 --> 00:05:40,830 value right there and just do a quick console log of it just to get a quick reminder of. 78 00:05:40,860 --> 00:05:41,110 OK. 79 00:05:41,130 --> 00:05:41,430 Yes. 80 00:05:41,430 --> 00:05:47,890 Calls is the array of all the different times is my function was invoked on the last one. 81 00:05:47,920 --> 00:05:52,360 Let's take this really quickly so we definitely done this one many times. 82 00:05:52,360 --> 00:05:57,320 We're gonna take a look at our message and make sure that the ACH function wasn't booked. 83 00:05:57,360 --> 00:06:04,550 I'll do it and expect message not EQ to have been called and that is it. 84 00:06:04,560 --> 00:06:06,030 We are all done. 85 00:06:06,030 --> 00:06:11,610 Let's save this we could definitely clean up some of the destruction arguments in here if we want to 86 00:06:11,610 --> 00:06:15,210 by the way didn't really need ticket here I guess. 87 00:06:15,210 --> 00:06:20,380 Didn't take it up here Charlie up to you at any rate let's make sure we just save the file and we'll 88 00:06:20,380 --> 00:06:27,770 go run our tests the back of my terminal will change in two orders do an MP run test and for the first 89 00:06:27,770 --> 00:06:33,170 go round we're gonna pray really just hope I suppose that all of our tests pass as we're looking for 90 00:06:34,800 --> 00:06:38,790 yep looks good now that everything is passing as usual. 91 00:06:38,790 --> 00:06:42,480 Still want to make sure that we can get our test to fail because they might be passing through some 92 00:06:42,480 --> 00:06:49,920 fault on our side for all three tests we just wrote out I going to comment out the on message call so 93 00:06:49,980 --> 00:06:55,330 there's three comments I'll then save this we'll now flip back over and just make sure that we've got 94 00:06:55,450 --> 00:06:57,160 exactly three failures 95 00:07:00,030 --> 00:07:01,650 Yep three failed. 96 00:07:01,770 --> 00:07:03,000 Very good. 97 00:07:03,000 --> 00:07:07,450 All right I'll undo those changes though they're now all on commented. 98 00:07:07,470 --> 00:07:10,380 Say this again and we are all set. 99 00:07:10,500 --> 00:07:10,810 All right. 100 00:07:10,830 --> 00:07:12,610 That's one more step down. 101 00:07:12,630 --> 00:07:15,690 We're getting closer and closer to finishing up this application. 102 00:07:15,690 --> 00:07:17,390 We still have a pretty good amount to do. 103 00:07:17,410 --> 00:07:19,820 So let's take a pause right here and move forward in just a moment.