All right.
Let's do a quick series of tests around this expiration complete listener inside my order service.
I'll find the listeners directory test folder inside there and we'll make a new file of expiration complete
listener dot test dot to yes this listener Test File once again going to look identical to all the other
test files we put together for our listeners.
So at the very top we're going to add in a couple of imports for the listener.
Nats rapper that's actually gonna be the Nats rapper.
Mark of course but they're going to build a setup function do all that kind of data setup.
You get the idea.
Business as usual don't get to it at the very top.
I'm going to first imports.
The one thing I know that I absolutely need and that is the listener will get my expiration complete
listener from up one directory expiration complete I'll then build my setup function inside of here.
Well let's make our instance that will be a new expiration complete listener and we do have to provide
a Nats client to it.
That's the air we're getting right here.
So let's make sure that we import Nats rapper from up to directories.
Note 3 Nats rapper and then we can provide Nats rapper that client
get after that.
We're going to first build out in order we're going to associate with a ticket so everything is in the
right state and then we're going to save both the order and the ticket to do so we do have to get access
to the ticket model and the order model.
So let's do that at the top.
I'll get my order from up 3 directories models order
and then my ticket from up 3 directories models ticket
then down inside of setup.
Let's first build up our ticket and save it.
They'll say ticket is ticket dot build this thing will have some title then price.
And remember we have to provide this thing an idea as well.
We'll get this thing at a hardcoded I.D. which we're going to generate from Mongoose and I really should
not refer to that as a hard coded I.D. because we are randomly generating it both throw in here Mongoose
stock types object I.D. to hex string
we can then say that to get there we'll build up our order so we'll do an ordered up built
in order it's gonna get a couple of different properties.
So user I.D. status all this different stuff.
In this case we don't really care about the user I.D..
Once again we also don't really care all that much about expires that because we are canceling an order
no matter what whenever we received that expiration complete event so we get through in some arbitrary
string for expires out without a doubt.
However the status doesn't mean that ticket needs to be a real ticket and status needs to be the correct
status as well.
They're probably gonna have to import that order status in from our coming module once again.
Well let's begin with that up at the top of the file at the top.
We will get our order status
from our common module
then on our build statement we'll plug in a status of order status dot read it we'll just go through
all those other properties.
We've got a user I.D. that will be whatever we've gotten expires at.
That can be whatever and then a ticket which will be the ticket that we had defined right before now
getting an area around expires out right here.
Oh my mistake needs to be actually be a date not a plane string.
It's a plane string once we transmit it in our event.
But as we are plugging it into the build method it does need to be an actual date.
So we'll just make a new date object and throw that in now networks.
So we can now save that order though wait ordered save and that is it for our data level so we can create
our actual event or create the message as well.
And we should be good to go.
Let's first create the event to do so.
We should get the event interface from our common module as well that we will import the expiration
that complete event.
And while we're up here since we know we're going to need it let's also get that message type from the
Nats streaming library from node Nat streaming.
So now we can build up our fake data object it'll be of type order the expiration that complete event
at data every.
Just so many variable names floating around here.
It definitely does get confusing pretty quickly.
Now this event we're expected to provide some order I.D. property.
And of course you can mouse over that area there and we'll be told that we'll give the thing an order
I.D. which will come from order dot I.D..
That's the idea.
The order that we just built and saved will then also create our message it'll be of type message.
And as usual it's just going to have an ACH function.
There'll be adjust.
Mark and we're just going to tell typescript let it be Let it be.
So that's it.
So now we can't take all these variables.
We probably don't really need that ticket to be returned from setup.
But we will anyways.
We're going to take basically everything we just created and return it from setup so my listener my
order my ticket data and the message and that's our setup function.
Let's take a quick pause right here.
We'll start to write out our actual individual tests in just a moment.