1 00:00:00,970 --> 00:00:03,780 All this concurrency stuff is actually kind of working out. 2 00:00:03,800 --> 00:00:07,970 So now to make sure that these listeners are working correctly we're gonna start to write a couple of 3 00:00:07,970 --> 00:00:09,170 tests around them. 4 00:00:09,230 --> 00:00:13,370 We're going to first write a test around the ticket create a listener inside of all the tests we're 5 00:00:13,370 --> 00:00:14,690 going to write around these listeners. 6 00:00:14,690 --> 00:00:19,460 We're going to essentially repeat the same operation over and over again inside of every test we're 7 00:00:19,460 --> 00:00:21,670 going to create an instance of this listener. 8 00:00:21,740 --> 00:00:27,440 We're then going to fabricate a data object and fabricate a fake message as well. 9 00:00:27,680 --> 00:00:32,300 We'll then take that fake data object and the fake message pass it into the on message function and 10 00:00:32,350 --> 00:00:36,260 then make sure that the on message function does some appropriate thing. 11 00:00:36,260 --> 00:00:40,580 So in this case for the ticket created listener we're going to make sure that if we pass in some valid 12 00:00:40,580 --> 00:00:42,500 data object it's a valid message. 13 00:00:42,500 --> 00:00:48,320 We should end up creating a ticket saving into the database and we should also end up calling the messages 14 00:00:48,510 --> 00:00:50,980 back function or acknowledge function. 15 00:00:51,050 --> 00:00:55,520 That's the goal of all these different tests or in the listener rate the listener call on message. 16 00:00:55,520 --> 00:00:59,730 Make sure it does something appropriately so to get started. 17 00:00:59,730 --> 00:01:01,770 I'm going to find my listeners directory. 18 00:01:02,070 --> 00:01:08,000 I'll make a new folder of underscore underscore test underscore underscore inside of there. 19 00:01:08,000 --> 00:01:17,310 I'll make a new file of ticket created listener test dot T.S. before we add in any import statements 20 00:01:17,310 --> 00:01:18,210 into this Test File. 21 00:01:18,210 --> 00:01:23,130 I'd like to just write out a test definition and put some comments into it kind of outline what we really 22 00:01:23,130 --> 00:01:23,920 need to do. 23 00:01:23,940 --> 00:01:25,900 We're going to end up having to write a lot of imports. 24 00:01:25,980 --> 00:01:29,550 So if you just write the imports right away we're going to end up with a lot of stuff inside of here 25 00:01:29,550 --> 00:01:31,260 that might not make a lot of sense. 26 00:01:31,260 --> 00:01:34,050 So let's just put together a couple of comments first. 27 00:01:34,050 --> 00:01:41,070 So I want to have a test of something like it rates and saves a ticket. 28 00:01:41,210 --> 00:01:46,180 That is ideally what our ticket grid listener is going to do it's going to create and save a ticket. 29 00:01:46,190 --> 00:01:51,890 The other thing they would do ideally if we provided some valid data object and message is it's going 30 00:01:51,890 --> 00:02:00,860 to also ask the message and to make the sentence here with it kind of read correctly I'm going to change 31 00:02:00,860 --> 00:02:07,750 it to it's X the message. 32 00:02:07,880 --> 00:02:11,660 So again I want to write out just a couple of comments in both these just to make sure that what we're 33 00:02:11,660 --> 00:02:14,540 going to do inside of your all the setup is can make a lot of sense. 34 00:02:14,570 --> 00:02:21,780 So instead of here we're going to first create an instance of the listener we're then going to create 35 00:02:21,810 --> 00:02:27,960 a fake data event that's gonna be our data object it's gonna be this argument right here. 36 00:02:27,960 --> 00:02:33,420 So it's got to be some kind of object that has an I.D. version titled price and user I.D. 37 00:02:36,680 --> 00:02:44,370 We're then going to fabricate also a fake message object that's gonna be this message argument right 38 00:02:44,370 --> 00:02:44,820 here. 39 00:02:44,820 --> 00:02:49,500 It's supposed to be of type message and remember message is a type of object coming from the node that 40 00:02:49,500 --> 00:02:50,460 streaming library. 41 00:02:50,640 --> 00:02:54,160 The only thing we care about that message object is for the ACT function. 42 00:02:54,210 --> 00:02:57,290 It has several other functions on it but we don't care about them at all. 43 00:02:57,300 --> 00:03:01,420 And that's actually to be very relevant very quickly after that. 44 00:03:01,430 --> 00:03:12,530 We're then going to call the on message function with the data object plus message object and then finally 45 00:03:12,530 --> 00:03:19,140 we're going to write assertions to make sure a ticket was created and that's pretty much it. 46 00:03:21,590 --> 00:03:26,900 Now down here the second it statement or the second test as you guessed all these setup steps need to 47 00:03:26,900 --> 00:03:28,250 be done down there as well. 48 00:03:28,250 --> 00:03:31,350 So we sought to create an instance of the listener big data object blah blah blah. 49 00:03:31,370 --> 00:03:36,730 All that stuff so I could put down all the comments like so and then finally at the very end. 50 00:03:36,730 --> 00:03:44,430 Add in something else we'll say right assertions to make sure act function is called right away. 51 00:03:44,560 --> 00:03:47,800 I want you to just notice all these setup comments look identical. 52 00:03:47,800 --> 00:03:50,890 And chances are we don't want to duplicate all this setup code. 53 00:03:50,890 --> 00:03:56,020 So rather than setting up all this stuff inside of each individual test I think it would definitely 54 00:03:56,020 --> 00:04:00,340 make a lot of sense to make some kind of reusable setup function at the top of the file. 55 00:04:00,380 --> 00:04:06,010 We call it simply setup and make an async function because we'll probably eventually end up doing some 56 00:04:06,040 --> 00:04:11,180 async stuff inside there and we can do all of our common setup for both these tests inside the setup 57 00:04:11,180 --> 00:04:18,740 function so I'm going to move all these comments around the setup. 58 00:04:18,890 --> 00:04:23,480 The first three really into that setup function. 59 00:04:23,890 --> 00:04:27,850 That's what we're going to do inside of setup and we'll eventually call setup from inside of our actual 60 00:04:27,850 --> 00:04:29,000 tests. 61 00:04:29,050 --> 00:04:31,150 I'll fix up the comments inside the second test as well. 62 00:04:34,900 --> 00:04:35,660 Okay so that's it. 63 00:04:35,680 --> 00:04:40,780 That's the plan for this file and this is the plan that we're going to go through for every lesson listener 64 00:04:40,780 --> 00:04:42,530 that we write tests out for. 65 00:04:42,550 --> 00:04:46,420 That's why I wanted to just take a little bit of time to outline what we have to do because we really 66 00:04:46,420 --> 00:04:51,590 are going to be repeating these steps many many times for all of our different listeners no good puzzle 67 00:04:51,590 --> 00:04:54,780 here starts put together this setup function in the next video.