1 00:00:00,910 --> 00:00:01,180 All right. 2 00:00:01,210 --> 00:00:02,890 Let's wrap up these two tests. 3 00:00:02,890 --> 00:00:05,910 So in both these tests we're going to need to call our setup function. 4 00:00:05,950 --> 00:00:10,480 Remember these set of function is a sync and actually is required to be a sync this time because we 5 00:00:10,480 --> 00:00:17,280 are creating that ticket and saving it to the database so inside of our first test I'm going to call 6 00:00:17,280 --> 00:00:28,420 the setup function and I'm going to pull out the message data object ticket and listener from a wait. 7 00:00:28,510 --> 00:00:29,880 Now we can take the listener. 8 00:00:29,920 --> 00:00:34,330 We're going to call the on message function with a data object and message and we can write out some 9 00:00:34,330 --> 00:00:40,750 expectations to make sure that this thing worked as expected they'll do in a wait listener on message 10 00:00:41,220 --> 00:00:46,070 and pass in data and message. 11 00:00:46,210 --> 00:00:48,860 So now how are we going to actually write out some expectation. 12 00:00:48,860 --> 00:00:53,230 Well let's try to fetch our ticket out of the tickets collection. 13 00:00:53,300 --> 00:00:57,920 Well then make sure that we have processed the new or that data object right there and we should make 14 00:00:57,920 --> 00:01:03,180 sure that this new ticket that we just refresh has the updated title and the updated price. 15 00:01:03,180 --> 00:01:05,960 We also might want to make sure that it has some updated version as well. 16 00:01:05,960 --> 00:01:13,080 That would probably be pretty handy as well they'll say updated ticket is going to be a wait ticket 17 00:01:13,170 --> 00:01:18,210 find by I.D. And we want to find a ticket with the same I.D. as the one we had created during the setup 18 00:01:18,210 --> 00:01:25,840 phase that we'll put in ticket dot I.D. so we can write out some different expectations we'll do. 19 00:01:25,840 --> 00:01:29,920 How about expect updated ticket exclamation. 20 00:01:30,020 --> 00:01:35,200 We've been over that exclamation enough so I'm not going to cover again and we'll say maybe this thing 21 00:01:35,200 --> 00:01:36,520 has the updated title. 22 00:01:36,580 --> 00:01:45,040 So two equal data that title so the updated tickets title should be equal to whatever the data object 23 00:01:45,050 --> 00:01:46,270 title is. 24 00:01:46,550 --> 00:01:48,160 We could essentially repeat that. 25 00:01:48,230 --> 00:01:55,580 VOICEOVER With the price equal to data price 26 00:01:59,750 --> 00:02:00,830 Andy version as well. 27 00:02:06,980 --> 00:02:07,960 Let's say it looks pretty good. 28 00:02:07,960 --> 00:02:11,970 So let's say this and do a quick test back at my terminal. 29 00:02:12,130 --> 00:02:13,000 I got my test suite. 30 00:02:13,000 --> 00:02:17,590 It looks like the filter I had set is capturing the ticket update and listener file. 31 00:02:17,590 --> 00:02:24,190 If you are only still running the ticket created then press W and then P and we can output in a more 32 00:02:24,190 --> 00:02:28,480 generous pattern right here to make sure we capture both those test files we are running right now. 33 00:02:28,510 --> 00:02:33,100 So both the ticket created listener and the ticket update the listener pattern we can use for that is 34 00:02:33,100 --> 00:02:40,550 just simply listener that's going to capture both those two listener test files and run both them it 35 00:02:40,550 --> 00:02:45,620 looks like the tests we just put together is running successfully but as usual we always always always 36 00:02:45,680 --> 00:02:49,420 have to put in something just to make sure that this test is really working as expected. 37 00:02:49,560 --> 00:02:53,900 I'm going to try to come in out the on message call right there which means that we're not going to 38 00:02:53,900 --> 00:02:59,030 actually process the message which means that our ticket should never get the updated title price or 39 00:02:59,030 --> 00:02:59,820 version. 40 00:02:59,900 --> 00:03:05,960 Don't expect to see some failure around the assertion around the title and yep there we go. 41 00:03:05,960 --> 00:03:07,210 Perfect. 42 00:03:07,340 --> 00:03:13,710 That means that that test is working as expected let's now take care of the second test right here. 43 00:03:13,750 --> 00:03:18,260 Give me just about identical to the test we had written back inside of the ticket created listener. 44 00:03:18,260 --> 00:03:28,340 So we're going to once again get message data ticket listener from calling setup will then call the 45 00:03:28,340 --> 00:03:36,340 listener and await that thing with data and message. 46 00:03:36,490 --> 00:03:40,940 And then finally we'll take a look at the ACT function on message and just make sure that was invoked 47 00:03:41,350 --> 00:03:48,920 by will expect message dot EQ to have been called. 48 00:03:49,190 --> 00:03:49,790 Let's say that 49 00:03:52,620 --> 00:03:57,420 looks like we're good to go as usual I'm going to comment out on message save it again. 50 00:03:57,420 --> 00:04:01,930 Make sure the thing fails. 51 00:04:01,940 --> 00:04:03,230 Very good. 52 00:04:03,230 --> 00:04:06,350 OK well I'd say that this looks pretty good. 53 00:04:06,350 --> 00:04:10,540 Maybe it last quick thing you're going to clean up ticket since we're technically not using it in this 54 00:04:10,540 --> 00:04:12,500 second little test right here. 55 00:04:12,500 --> 00:04:17,270 Well I'd say that we've captured this kind of success case of our listener pretty darn well. 56 00:04:17,270 --> 00:04:21,930 But maybe there are one or two other things that we're going to want to test around this listener. 57 00:04:22,010 --> 00:04:26,960 For example we might want to test this behavior around that find by event thing right there and make 58 00:04:26,960 --> 00:04:32,660 sure that if we pass in some kind of out of order event so some event with a version number that is 59 00:04:32,660 --> 00:04:37,940 too far into the future we might want to make sure that we do not call the act function or possibly 60 00:04:37,940 --> 00:04:39,550 that we just throw an error. 61 00:04:39,590 --> 00:04:45,260 So let's add in one or two more tests to make sure that this thing works correctly when everything is 62 00:04:45,260 --> 00:04:47,690 not quite going as expected. 63 00:04:47,690 --> 00:04:49,070 Let's take care of that in the next video.