Let's move on to our next test.
So on this one we're gonna make sure that a heir is returned.
If the ticket is already reserved.
So what does it mean to have a reserve ticket.
Well as you will recall inside of our ticket model just a little bit ago we put together that is reserved
function so we are saying that a ticket is reserved if there is an already an order inside of our database
that has that ticket associated with it and the order has the status of created a waiting payment or
complete.
So in order to do a little bit of setup for this test we have to first create a ticket save it to the
database then create an order save it to the database and make sure that the order and the ticket are
associated with each other.
Then we will finally make the request.
So a little bit of setup for this test to get started.
I will go to the top of the file and imports order from up to directories models order and ticket models.
Ticket
then down inside of our test we will first create a ticket and then save it to the database.
If we forget about the different properties that a ticket requires to create one because mouse over
the little is right there you can touch script will tell us we have to provide a title and a price that
will put in a title of concert and a price of twenty well then go ahead and save this ticket.
So do it in a wait.
Ticket dot save
then after that we'll go ahead and create our order and we win we create the order we will make sure
that we associate this ticket and put the order in the correct state as well so we will add in order
is ordered up built and once again if we forget what we have to provide here we can mouse over and we
have to provide a user I.D. status expires that and ticket the ticket will be the ticket that we just
created a moment ago.
So I will stick in ticket like so.
Next up a user I.D..
Nothing special about this.
We could just put in some random I.D. then the status and a status of this order remember is going to
come off of our order status in them.
So we do have to make sure we also import order status at the top of the file.
I can go back up to the top.
I'm going to find where we import order and I'll get order status
and status.
We will enter order status dot read it.
And then finally very last property the expires at time so for expires at will put in a new date.
Like so now if we put a new date right here that implies that the ticket or Sammy the order is going
to expire essentially instantly.
But that doesn't really matter.
There's nothing inside of our reservation code right now or whether or not deciding a ticket is reserved.
That's going to take a look at the orders expires at property.
So we're not going to ever have our order service necessarily look at that expires that property to
decide if this thing is expired.
Instead we're going to always rely upon the status flag right here to decide if the order is expired.
That might sound a bit confusing or a little bit backwards but it really comes down to how we are going
to implement a expiration service later on in the future.
The expiration service is going to be the thing in charge of marking in order as being expired not the
presence of this expires at Flag.
I know little bit confusing.
Don't sweat it.
We'll see what that is later on.
All right.
So after we create the order.
Well then go ahead and save it to our database.
The order dot save so now we can make our request and we should get back that status code of 400 saying
sorry but this ticket's already been reserved.
So put in an a wait request to at we want to make a post to API orders.
We need to set that cookie dough cookie global dot sign in
we will send along the idea that ticket that we are trying to reserve so ticket I.D. is ticket dot I.D.
And then finally we will expect to get back a 400 and that should be at let's say this will back over
and looks like we are good to go.
And once again I don't really know if that test is failing or passing erroneously.
So in this case I could very easily just change this expect right here and say hey we expect this to
resolve but they for one by say that flip back over.
No we are definitely getting correctly four hundred battery request.
So looks good.
All right just one more test.
So quick pause right here.
And the last test will really be pretty straightforward.
It's really just going to be requests like this.
We're gonna make sure that we get back some kind of success status code.