All this concurrency stuff is actually kind of working out.
So now to make sure that these listeners are working correctly we're gonna start to write a couple of
tests around them.
We're going to first write a test around the ticket create a listener inside of all the tests we're
going to write around these listeners.
We're going to essentially repeat the same operation over and over again inside of every test we're
going to create an instance of this listener.
We're then going to fabricate a data object and fabricate a fake message as well.
We'll then take that fake data object and the fake message pass it into the on message function and
then make sure that the on message function does some appropriate thing.
So in this case for the ticket created listener we're going to make sure that if we pass in some valid
data object it's a valid message.
We should end up creating a ticket saving into the database and we should also end up calling the messages
back function or acknowledge function.
That's the goal of all these different tests or in the listener rate the listener call on message.
Make sure it does something appropriately so to get started.
I'm going to find my listeners directory.
I'll make a new folder of underscore underscore test underscore underscore inside of there.
I'll make a new file of ticket created listener test dot T.S. before we add in any import statements
into this Test File.
I'd like to just write out a test definition and put some comments into it kind of outline what we really
need to do.
We're going to end up having to write a lot of imports.
So if you just write the imports right away we're going to end up with a lot of stuff inside of here
that might not make a lot of sense.
So let's just put together a couple of comments first.
So I want to have a test of something like it rates and saves a ticket.
That is ideally what our ticket grid listener is going to do it's going to create and save a ticket.
The other thing they would do ideally if we provided some valid data object and message is it's going
to also ask the message and to make the sentence here with it kind of read correctly I'm going to change
it to it's X the message.
So again I want to write out just a couple of comments in both these just to make sure that what we're
going to do inside of your all the setup is can make a lot of sense.
So instead of here we're going to first create an instance of the listener we're then going to create
a fake data event that's gonna be our data object it's gonna be this argument right here.
So it's got to be some kind of object that has an I.D. version titled price and user I.D.
We're then going to fabricate also a fake message object that's gonna be this message argument right
here.
It's supposed to be of type message and remember message is a type of object coming from the node that
streaming library.
The only thing we care about that message object is for the ACT function.
It has several other functions on it but we don't care about them at all.
And that's actually to be very relevant very quickly after that.
We're then going to call the on message function with the data object plus message object and then finally
we're going to write assertions to make sure a ticket was created and that's pretty much it.
Now down here the second it statement or the second test as you guessed all these setup steps need to
be done down there as well.
So we sought to create an instance of the listener big data object blah blah blah.
All that stuff so I could put down all the comments like so and then finally at the very end.
Add in something else we'll say right assertions to make sure act function is called right away.
I want you to just notice all these setup comments look identical.
And chances are we don't want to duplicate all this setup code.
So rather than setting up all this stuff inside of each individual test I think it would definitely
make a lot of sense to make some kind of reusable setup function at the top of the file.
We call it simply setup and make an async function because we'll probably eventually end up doing some
async stuff inside there and we can do all of our common setup for both these tests inside the setup
function so I'm going to move all these comments around the setup.
The first three really into that setup function.
That's what we're going to do inside of setup and we'll eventually call setup from inside of our actual
tests.
I'll fix up the comments inside the second test as well.
Okay so that's it.
That's the plan for this file and this is the plan that we're going to go through for every lesson listener
that we write tests out for.
That's why I wanted to just take a little bit of time to outline what we have to do because we really
are going to be repeating these steps many many times for all of our different listeners no good puzzle
here starts put together this setup function in the next video.