We are all done with some initial setup on tickets.
So now it's time to actually go ahead and put some implementation together now just as a quick reminder
these are the different route handlers are gonna build up inside of this ticket service.
The first route handler we're going to work on is going to give us the ability to create a ticket.
So this is gonna be the first one that we focus on.
Now we definitely could just go ahead and run off and start to build out this road handler but maybe
a better way to approach the development of the service would be to kind of take a test driven development
sort of approach.
So I would like to first write out some tests around this braided ticket root handler and then try to
make those tests pass.
So let's give that a shot back and said to my editor I'm gonna find the s RC directory inside there
I'll make a new folder called routes inside that I'll make another new folder called underscore underscore
test underscore underscore and then inside there I'll create a file called new test.
Yes I'm calling his file new because we're going to eventually have a new root handler the new root
handler is recruiting a new ticket.
Then inside of here we'll put together some boilerplate very similar to what we did on our last application
for testing a root handler at the very top.
I'm going to import request from super test I'll then import app and that is the express application
from up to directories at then we can start to write out some tests.
So here comes a big question what do we want to test.
Well I think you could probably take a good guess of what we need to do.
We need to make sure that there is some root handler present at API slash tickets that will respond
to it post request.
We probably need to make sure that we write out a test that's going to make sure that we validate the
incoming request body.
So for example make sure there is a title and a price and that they are of the correct type.
We probably may need to make sure that request to this row handler are always authenticated.
So in other words a user must be signed into our application in order to access this row handler and
then maybe eventually some test to make sure that say we actually create a ticket or something like
that.
So let's just write out some it blocks or it statements for some the tests that we're probably going
to have to write instead the first one is going to be something like it's as a root handler listening
to flash API slash tickets or post requests
and I'll zoom out here in just a second so you can see this entire statement and there we go.
I'm going to copy paste this down a couple of times and I'll just update the description on each one
and will eventually go in and write out some implementation for each test.
So how about on the second one.
Let's change the description to something like it can only be accessed if the user is signed in so that
will be a check to make sure we've got some authentication related stuff about for the next one we'll
say it returns an air if an invalid title is provided for the next one we could do it returns an error
if an invalid price is provided and then maybe for the last one done here we'll test and make sure that
everything kind of works as expected.
So how about something like it reads a ticket with valid parameters or have a valid inputs so these
are gonna be the different tests we're going to write out and after we write out each test we'll try
to actually make each one pass.
Right now let's just save the file go back over to our terminal and remember how we actually run our
test suite.
So back at my terminal I'm going to make sure I'm inside my tickets project directory so I'm no longer
inside of ticketing I'm inside of tickets and once I'm inside there I'm going to start my test suite
by running NPM run test it found my test file I can run all the test inside there and right now they
are all passing because we don't actually have any test code inside of any of them yet.
So let's flip back over and let's start to focus on this first one.
First of reports and we'll tackle it in the next video.