1 00:00:01,040 --> 00:00:05,360 Let's start to wrap up this test right after we make our request we probably wanna make sure that we 2 00:00:05,360 --> 00:00:07,850 get a response with a very particular status code. 3 00:00:07,970 --> 00:00:12,650 In this case I don't expect that we get a status code back up to a one to indicate that a payment actually 4 00:00:12,650 --> 00:00:13,830 was created. 5 00:00:13,910 --> 00:00:18,440 Right now our root handler is definitely not returning it to a one it is returning a two hundred by 6 00:00:18,440 --> 00:00:19,270 default. 7 00:00:19,440 --> 00:00:23,180 Just to make sure that we pass that part I'll go back to the root handler really quickly. 8 00:00:23,330 --> 00:00:24,560 Here's the send statement. 9 00:00:24,560 --> 00:00:29,480 And again ascend defaults to using a two hundred going to chain on a dot status 10 00:00:32,180 --> 00:00:39,820 of to a one like so besides making sure that we get back to a one we might want to also make sure that 11 00:00:39,820 --> 00:00:46,030 we call that stripe API or the stripe library with the correct set of arguments to do so we need to 12 00:00:46,030 --> 00:00:51,700 somehow get access to that stripe Mark function or really the create mock function we put together and 13 00:00:51,700 --> 00:00:56,590 make sure that this thing was invoked and make sure it was invoked with the correct arguments to do 14 00:00:56,590 --> 00:00:58,750 so at the very top of my test file. 15 00:00:58,870 --> 00:01:00,340 I'm going to add in and import 16 00:01:03,180 --> 00:01:07,890 or straight from up to directories straight. 17 00:01:07,980 --> 00:01:12,530 Now remember because we are marking out the strike module right here when we write out this import for 18 00:01:12,540 --> 00:01:18,240 stripe just is going to make sure that we get the stripe t s file inside of our MOX directory not the 19 00:01:18,300 --> 00:01:26,840 real version of the stripe file it's now back down inside of our test we can write out some expectations 20 00:01:27,020 --> 00:01:31,820 around that mock function very similar to all the different expectations we've heard now before we can 21 00:01:31,820 --> 00:01:36,440 make sure that the MOC create function was called we can make sure that is called with the correct arguments 22 00:01:37,280 --> 00:01:41,180 to get access to the actual arguments that that thing was called with are going to create a variable 23 00:01:41,180 --> 00:01:48,980 right here called Charge options and this will come from stripe not charges dot creates not muck and 24 00:01:48,980 --> 00:01:54,610 then remember off of here we can take a look at all the times it was called the Dot calls that is gonna 25 00:01:54,610 --> 00:02:00,260 be an array of arrays so we can take a look at the first timers called and then we were that first time 26 00:02:00,260 --> 00:02:06,570 we could take a look at the first argument like so we are getting an error from typescript right here 27 00:02:06,630 --> 00:02:12,240 typescript is saying hey this great thing does not have a mock property tied to it remember we can teach 28 00:02:12,260 --> 00:02:17,070 typescript what's going on here if we take just stripe charges create a set of parentheses around it 29 00:02:17,730 --> 00:02:26,980 and then inside the parentheses right in as just dot mark like so now charge options is going to be 30 00:02:27,220 --> 00:02:32,680 back inside of a root handler this object right here so we can make sure this object has the correct 31 00:02:32,680 --> 00:02:37,690 properties we can make sure that it has the appropriate currency the correct amount and the correct 32 00:02:37,780 --> 00:02:43,760 token as well so we'll write out three expectations to make sure all those properties are set correctly 33 00:02:44,710 --> 00:02:54,010 I'll take a look at charge options dot source and I'll expect that to equal to OK. 34 00:02:54,070 --> 00:03:02,460 Visa I will expect charge options that amount to equal and the amount that we are charging should be 35 00:03:02,460 --> 00:03:07,920 at whatever amount or price we have listed on the order times 100 in this case my price was twenty so 36 00:03:07,920 --> 00:03:13,350 it'll be twenty times one hundred that's what I should have provided or amount but in twenty times one 37 00:03:13,350 --> 00:03:23,380 hundred and then finally I will expect that charge options that currency is equal to USD and that should 38 00:03:23,380 --> 00:03:30,910 be at let's now save this and see how this test is doing back over at my terminal Yep looks like it 39 00:03:30,910 --> 00:03:36,490 works as expected as usual let's try to make this test break really quickly so back inside the root 40 00:03:36,490 --> 00:03:44,190 handler I'll just comment out the stripe charges create call save it now if I look back over Republicans 41 00:03:44,200 --> 00:03:48,910 see some errors around those expectations that the thing was called with some specific arguments yep 42 00:03:49,210 --> 00:03:53,980 it looks like we get an error when we tried to pull off the calls property from that mosque because 43 00:03:54,130 --> 00:04:02,150 now the rebate function was probably never called not even once so it looks pretty good now this definitely 44 00:04:02,150 --> 00:04:07,140 it works but of course the downside to this approach is that we are not really testing reaching out 45 00:04:07,140 --> 00:04:12,030 to the stripe API itself and you might want to test and make sure hey we actually can reach out to the 46 00:04:12,030 --> 00:04:16,860 real stripe API and provide some correct values we'll take a pause right here and we'll take a look 47 00:04:16,860 --> 00:04:22,290 at an alternative way of testing this stuff totally optional but let's go through it anyhow in the next 48 00:04:22,290 --> 00:04:22,620 video.