Let's start to wrap up this test right after we make our request we probably wanna make sure that we
get a response with a very particular status code.
In this case I don't expect that we get a status code back up to a one to indicate that a payment actually
was created.
Right now our root handler is definitely not returning it to a one it is returning a two hundred by
default.
Just to make sure that we pass that part I'll go back to the root handler really quickly.
Here's the send statement.
And again ascend defaults to using a two hundred going to chain on a dot status
of to a one like so besides making sure that we get back to a one we might want to also make sure that
we call that stripe API or the stripe library with the correct set of arguments to do so we need to
somehow get access to that stripe Mark function or really the create mock function we put together and
make sure that this thing was invoked and make sure it was invoked with the correct arguments to do
so at the very top of my test file.
I'm going to add in and import
or straight from up to directories straight.
Now remember because we are marking out the strike module right here when we write out this import for
stripe just is going to make sure that we get the stripe t s file inside of our MOX directory not the
real version of the stripe file it's now back down inside of our test we can write out some expectations
around that mock function very similar to all the different expectations we've heard now before we can
make sure that the MOC create function was called we can make sure that is called with the correct arguments
to get access to the actual arguments that that thing was called with are going to create a variable
right here called Charge options and this will come from stripe not charges dot creates not muck and
then remember off of here we can take a look at all the times it was called the Dot calls that is gonna
be an array of arrays so we can take a look at the first timers called and then we were that first time
we could take a look at the first argument like so we are getting an error from typescript right here
typescript is saying hey this great thing does not have a mock property tied to it remember we can teach
typescript what's going on here if we take just stripe charges create a set of parentheses around it
and then inside the parentheses right in as just dot mark like so now charge options is going to be
back inside of a root handler this object right here so we can make sure this object has the correct
properties we can make sure that it has the appropriate currency the correct amount and the correct
token as well so we'll write out three expectations to make sure all those properties are set correctly
I'll take a look at charge options dot source and I'll expect that to equal to OK.
Visa I will expect charge options that amount to equal and the amount that we are charging should be
at whatever amount or price we have listed on the order times 100 in this case my price was twenty so
it'll be twenty times one hundred that's what I should have provided or amount but in twenty times one
hundred and then finally I will expect that charge options that currency is equal to USD and that should
be at let's now save this and see how this test is doing back over at my terminal Yep looks like it
works as expected as usual let's try to make this test break really quickly so back inside the root
handler I'll just comment out the stripe charges create call save it now if I look back over Republicans
see some errors around those expectations that the thing was called with some specific arguments yep
it looks like we get an error when we tried to pull off the calls property from that mosque because
now the rebate function was probably never called not even once so it looks pretty good now this definitely
it works but of course the downside to this approach is that we are not really testing reaching out
to the stripe API itself and you might want to test and make sure hey we actually can reach out to the
real stripe API and provide some correct values we'll take a pause right here and we'll take a look
at an alternative way of testing this stuff totally optional but let's go through it anyhow in the next
video.