The next day we're going to do is fix up a couple of tests.
Now these are specifically tests around our different root handlers.
Let's go back over to a terminal.
We're going to take another look at our test suite.
We're gonna run all the tests instead of what order service and we will see that a couple are failing.
OK so back to my terminal.
Here's my test suite inside the order service.
We are currently filtered and only running tests with the name listener inside the TEST file name.
So I want to undo that filter by pressing W..
And then a to run all tests so we're gonna see that these tests around are different route handlers
are going to fail pretty catastrophically.
And if we take a look at each of these you'll notice as I mentioned last video is because we are building
tickets without providing an I.D. at some point time when we are working all the on all these listeners
and all these events we said that we needed to make sure that we had consistent ideas being used between
the ticket service and the order service.
So we had required that whenever we called Ticket Talk Build we had to provide an I.D. property inside
of our test.
We still have some code where we are creating tickets without providing an I.D..
So we really have to do is go around to a different route handle our test files whenever we build a
ticket.
We have to include a randomly generated I.D. that's pretty much it so inside my order service I'm going
to find our roots directory I'm going gonna find the test folder inside there and I'll open up delete
test.
Yes so inside of you right away we're going to see some errors around building a ticket right here and
right here in both cases.
Oh you have to do is use Mongoose to generate a brand new random I.D. and assign it to the ticket dot
built that's it.
So at the very top we will import Mongoose from Mongoose then inside the build method allowed in an
I.D. which will be Mongoose that types dot object I.D. not to hex bring like so.
Now we're going to have to duplicate this line right here into pretty much all for these test files.
So I'm going to copy this line and we're going to go round to these four files and paste that line everywhere
that we build a ticket the first are going to scroll down a little bit lower in this file find the next
air and I'll paste in the 80 like so and that is it for the delete test file.
Fix it up.
So going to say this and close it Next up I'll move on to the next test file of index test.
Yes at the very top I will import Mongoose from mongoose.
And then once again paste in that 80
that is it for this file so I'll save it and close it onto the new test file.
We've already imported Mongoose at the top so we can scroll through here find every location where we
build a ticket and paste in that idea line.
There's one right there
ears to
and here's three.
So three locations in this file were we where we are going to paste in the idea thing that is it for
the new test file.
So close that one.
And then finally onto a show test.
Yes.
Once again at the very top I will import Mongoose
and then I will paste in the idea there's one right there.
One more error little bit down right here pasted in.
Let's two inside the show test.
Yes file it.
Let's say this was the file down and then go back over to our terminal and see how our tests are doing.
It looks like we still have a couple of failures but these are failures related to our root handlers.
As I mentioned we went through our different events inside the common module just a little bit ago and
we said that all of our different events had to include a version property inside of our different root
handlers.
Right now we have several locations where we are publishing events but we are not including any version
property.
And so that's what we're seeing from the delete Roc handler.
Right now we are getting an error from typescript that distinctly says hey you have to include a version
property whenever you are trying to publish a order it canceled events.
That's pretty much it.
We just have to go round to two different root handlers and make sure that we include that version property
let's take care of that right now.
Does other routes rectory.
I'll find delete.
Yes but here's the delete root handler is the one it's going to cancel in order there is a we published
an event and if you mouse over this.
Yep it pretty much says we have to include a version as we said that we would anytime we publish this
event.
The version is going to come off the order that we are canceling so remember the entire idea here is
that a lot of our different records are going to include these version flags as the primary means of
concurrency control that's what's going to make sure that we process all these different events in the
correct order.
So there's some other service out there that's going to eventually listen to the order canceled events.
It's going to use the version field of this order to make sure that the event gets processed in the
correct order they're going to take this order that we just canceled.
We're gonna take its version property and just include it inside the event.
We'll throw in version is going to be order DOD version.
Like so there's one other event that we are currently publishing that's inside of the root handler of
new t s so this is where we create a new order.
And if we scroll down a little bit we can see where we are publishing that event.
Here it is right here we're publishing the event and once again we're just not including in the version
when we said we would do so we'll throw in version is order dot version and that's it.
So let's save this at this point time all of our tests should now be working.
So I have to go back over to my terminal and I should see that all the tests inside my order service
are up and running.
Fantastic OK.
So as I mentioned this is just kind of going around and fixing a couple of odds and ends and I just
want to make sure that the goal of all this stuff was really crystal clear.
So at this point we're in a pretty good state.
I would say that our order service is reasonably processing incoming events related to tickets so we're
not going to start to move back over to our tickets service.
We're going to start to investigate some other issues between the ticket service and the order service
specifically around making sure that we actually reserve tickets properly and while a ticket is reserved
we need to also make sure that a user cannot edit 8 tickets title or price.
So a couple more kind of business rule things.
Let's start to tackle this stuff in the next video.