All right.
Let's wrap up these two tests.
So in both these tests we're going to need to call our setup function.
Remember these set of function is a sync and actually is required to be a sync this time because we
are creating that ticket and saving it to the database so inside of our first test I'm going to call
the setup function and I'm going to pull out the message data object ticket and listener from a wait.
Now we can take the listener.
We're going to call the on message function with a data object and message and we can write out some
expectations to make sure that this thing worked as expected they'll do in a wait listener on message
and pass in data and message.
So now how are we going to actually write out some expectation.
Well let's try to fetch our ticket out of the tickets collection.
Well then make sure that we have processed the new or that data object right there and we should make
sure that this new ticket that we just refresh has the updated title and the updated price.
We also might want to make sure that it has some updated version as well.
That would probably be pretty handy as well they'll say updated ticket is going to be a wait ticket
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
phase that we'll put in ticket dot I.D. so we can write out some different expectations we'll do.
How about expect updated ticket exclamation.
We've been over that exclamation enough so I'm not going to cover again and we'll say maybe this thing
has the updated title.
So two equal data that title so the updated tickets title should be equal to whatever the data object
title is.
We could essentially repeat that.
VOICEOVER With the price equal to data price
Andy version as well.
Let's say it looks pretty good.
So let's say this and do a quick test back at my terminal.
I got my test suite.
It looks like the filter I had set is capturing the ticket update and listener file.
If you are only still running the ticket created then press W and then P and we can output in a more
generous pattern right here to make sure we capture both those test files we are running right now.
So both the ticket created listener and the ticket update the listener pattern we can use for that is
just simply listener that's going to capture both those two listener test files and run both them it
looks like the tests we just put together is running successfully but as usual we always always always
have to put in something just to make sure that this test is really working as expected.
I'm going to try to come in out the on message call right there which means that we're not going to
actually process the message which means that our ticket should never get the updated title price or
version.
Don't expect to see some failure around the assertion around the title and yep there we go.
Perfect.
That means that that test is working as expected let's now take care of the second test right here.
Give me just about identical to the test we had written back inside of the ticket created listener.
So we're going to once again get message data ticket listener from calling setup will then call the
listener and await that thing with data and message.
And then finally we'll take a look at the ACT function on message and just make sure that was invoked
by will expect message dot EQ to have been called.
Let's say that
looks like we're good to go as usual I'm going to comment out on message save it again.
Make sure the thing fails.
Very good.
OK well I'd say that this looks pretty good.
Maybe it last quick thing you're going to clean up ticket since we're technically not using it in this
second little test right here.
Well I'd say that we've captured this kind of success case of our listener pretty darn well.
But maybe there are one or two other things that we're going to want to test around this listener.
For example we might want to test this behavior around that find by event thing right there and make
sure that if we pass in some kind of out of order event so some event with a version number that is
too far into the future we might want to make sure that we do not call the act function or possibly
that we just throw an error.
So let's add in one or two more tests to make sure that this thing works correctly when everything is
not quite going as expected.
Let's take care of that in the next video.