Let's move on to our next two tests.
All we're going to be doing here is making sure that a title and a price are provided.
If they are not we're going to want to make sure that we return some kind of air to the user.
So let's write out our test implementation first.
So in this first one let's attempt to send in a request with some kind of invalid title.
Now we haven't really said exactly what makes a title invalid.
So for right now let's assume that if we put in a empty title or no title at all we should get back
some kind of air.
So going to write out a wait request to app I want to make a post to API tickets are going to make sure
this thing is authenticated.
So we're gonna set that cookie with global sign in and then send along some data.
So what data we can send here.
Again we want to make sure that the title is what we think is gonna be valid or invalid and we want
to make sure that the price is valid.
So I will first put in a title of about empty string and I'll put in a price of something it looks kind
of valid to me looking to put in a number here of 10.
Now you might recall we had a diagram a little bit ago that said we're going to send in price as a string.
We'll just ignore that for right now let's say price is going to be a number.
So how are we going to say that this should result in some kind of error.
Well once again let's think about how we handle invalid request or invalid request data.
If we go back over to our common module you might recall that we've got a middleware that we put together
to help us validate incoming requests.
So it's something about the incoming request was not valid.
We would throw a error of request validation error.
Let's go take a look at what that it really looks like.
So inside my ears directory again inside the com module I will find request validation error and so
something is wrong with the incoming request we return a status code of 400 along with the actual error
messages and whatnot.
I don't want to sweat that your messages right now.
I kind of just want to make sure that we get back a status code of 400 so back inside of my test after
making this invalid request I will expect a status code of 400
if we want to be even a little bit more complete we could make that same request a second time and in
the second request we could say let's not even send along a title at all.
So if we send a title that is empty or if we don't send a title.
In both cases we should be marking that request as invalid while that looks good to me.
So I got to say the file and it looks like we've got our failed test now we could go and fix up our
root handler right away but let's just continue and write out the test for invalid price as well because
that's gonna be just about identical to what we did right here so I'm going to copy one these requests
blocks again and move it down to the price stuff so for price let's take these same kind of approach.
Let's first try to send in some data that feels like it should probably be invalid and we'll try to
send in another request that doesn't even have the property we're talking about at all so I'm going
to actually paste that thing in twice on the first one I will send in a title that is probably going
to be valid and the reason I'm saying probably here again is because we have not set up any validation
rules yet.
I'm just kind of taking a guess on what we probably want to have.
Now on the first one I'm gonna provide a price that is present but probably not a valid value.
So in this case I can put in negative 10 chances are we probably don't want a user listing stuff for
negative values so we're probably going to want to say that a price has to be greater than zero.
And so this right here should probably result in some kind of error.
Then on the second one we will once again put in a valid title but I won't put in a price at all that
looks good.
Say this again look back over and we now have both of our validation tests failing.
That's good.
So let's go over to our actual request handler.
Here it is right here.
I don't want to have this video running too long.
So let's take a quick pause right here.
We'll start to put in some logic to validate that income request in just a moment.