1 00:00:00,350 --> 00:00:02,790 Hi and welcome to this section where 2 00:00:02,790 --> 00:00:04,500 we're gonna talk about building quality 3 00:00:04,500 --> 00:00:08,010 APIs. In this video we're going to talk 4 00:00:08,010 --> 00:00:11,099 about debugging your API. So creating API 5 00:00:11,099 --> 00:00:12,929 test is an important skill, what do you 6 00:00:12,929 --> 00:00:15,509 do when a test fails? Being able to debug 7 00:00:15,509 --> 00:00:17,430 failures and figure out what to do is an 8 00:00:17,430 --> 00:00:20,189 important aspect of API testing. So let's 9 00:00:20,189 --> 00:00:22,410 take a look at a failing test and see if 10 00:00:22,410 --> 00:00:24,269 we can figure out what's going on. I have 11 00:00:24,269 --> 00:00:26,279 here tests that I've set up to fail, so 12 00:00:26,279 --> 00:00:27,529 when we click on it, 13 00:00:27,529 --> 00:00:31,140 send, can see the test results here have 14 00:00:31,140 --> 00:00:34,170 failed. It's saying that we expect 15 00:00:34,170 --> 00:00:36,899 undefined to deeply equal Europe / 16 00:00:36,899 --> 00:00:38,850 London. So what's going on here? What does 17 00:00:38,850 --> 00:00:41,370 this even mean? Well if we look at our 18 00:00:41,370 --> 00:00:43,860 test, so if we look at the actual assert 19 00:00:43,860 --> 00:00:45,870 that we're using up here, we can see that 20 00:00:45,870 --> 00:00:48,120 it's expecting the JSON data and the 21 00:00:48,120 --> 00:00:50,700 timezone key in that data to have a 22 00:00:50,700 --> 00:00:54,030 value of Europe slash London, but what 23 00:00:54,030 --> 00:00:56,789 this is saying down here is that this 24 00:00:56,789 --> 00:00:58,230 Europe London part that makes sense 25 00:00:58,230 --> 00:00:59,879 that's what we're looking for, but it's 26 00:00:59,879 --> 00:01:01,890 saying that Vout the key here the 27 00:01:01,890 --> 00:01:04,619 timezone is undefined. What that probably 28 00:01:04,619 --> 00:01:06,599 means is something has gone wrong with 29 00:01:06,599 --> 00:01:08,130 our response, we're not getting back the 30 00:01:08,130 --> 00:01:10,229 response that we expect. And if we look 31 00:01:10,229 --> 00:01:11,820 at the body we can see that is indeed 32 00:01:11,820 --> 00:01:13,439 the case. We would expect to have some 33 00:01:13,439 --> 00:01:16,380 kind of JSON here with information about 34 00:01:16,380 --> 00:01:19,290 the London timezone, but instead we seem 35 00:01:19,290 --> 00:01:22,619 to have some long list of locations, 36 00:01:22,619 --> 00:01:24,900 maybe locations as API takes I don't 37 00:01:24,900 --> 00:01:26,189 know, but it's some long list of 38 00:01:26,189 --> 00:01:28,590 locations. That seems really odd, so let's 39 00:01:28,590 --> 00:01:30,210 see if we can find out a little bit more 40 00:01:30,210 --> 00:01:32,610 about what actually got sent to the 41 00:01:32,610 --> 00:01:34,710 server. So let's click here on the 42 00:01:34,710 --> 00:01:37,020 console to open up the Postman console, 43 00:01:37,020 --> 00:01:39,509 and then let's send our request again. 44 00:01:39,509 --> 00:01:42,659 And if we look at the console you can 45 00:01:42,659 --> 00:01:45,079 see that we have some information here 46 00:01:45,079 --> 00:01:48,479 about what got sent to the server. So we 47 00:01:48,479 --> 00:01:50,850 can see the headers that were sent along 48 00:01:50,850 --> 00:01:53,520 with the API location that we sent, and 49 00:01:53,520 --> 00:01:55,049 then we can see a little more detail 50 00:01:55,049 --> 00:01:57,090 about what came back. Now everything 51 00:01:57,090 --> 00:02:01,259 seems to be fine here, so let's look at 52 00:02:01,259 --> 00:02:03,329 something else. Let's close that and 53 00:02:03,329 --> 00:02:04,950 let's try something here, let's just 54 00:02:04,950 --> 00:02:07,740 change this to Bob, so we'll change it to 55 00:02:07,740 --> 00:02:08,699 something that doesn't make any sense 56 00:02:08,699 --> 00:02:11,580 and send this request, and see what 57 00:02:11,580 --> 00:02:13,990 happens. Now interestingly we get this 58 00:02:13,990 --> 00:02:16,030 same error, and if we look at the body we 59 00:02:16,030 --> 00:02:18,190 got the same response back. So it seems 60 00:02:18,190 --> 00:02:19,780 like it doesn't care what we're putting 61 00:02:19,780 --> 00:02:22,360 in here. So there must be something else 62 00:02:22,360 --> 00:02:24,400 going on, it seems like it's not a 63 00:02:24,400 --> 00:02:26,470 problem that's happening here at the end 64 00:02:26,470 --> 00:02:28,930 of the URL. But maybe let's go look at 65 00:02:28,930 --> 00:02:31,450 the documentation and see what it says. 66 00:02:31,450 --> 00:02:34,180 So we look here in the documentation, we 67 00:02:34,180 --> 00:02:36,340 can see that we should have world time 68 00:02:36,340 --> 00:02:39,490 API org, look at that we have world time 69 00:02:39,490 --> 00:02:41,680 API that org that looks good, and then we 70 00:02:41,680 --> 00:02:44,440 have slash API slash time zone followed 71 00:02:44,440 --> 00:02:47,680 by the area and location. So here we have 72 00:02:47,680 --> 00:02:51,280 slash API slash time zones, okay so we 73 00:02:51,280 --> 00:02:54,250 have an extra s in there. So let's remove 74 00:02:54,250 --> 00:02:57,160 that and send this request, and see what 75 00:02:57,160 --> 00:02:59,980 happens. Now we got something back, error 76 00:02:59,980 --> 00:03:03,940 unknown location. Okay so this is a very 77 00:03:03,940 --> 00:03:05,020 different thing that we were seeing 78 00:03:05,020 --> 00:03:07,570 before. It still gives us this undefined 79 00:03:07,570 --> 00:03:10,780 because the test here, there's no time 80 00:03:10,780 --> 00:03:14,020 zone key in this response,, but we're 81 00:03:14,020 --> 00:03:15,520 getting an unknown location so we're 82 00:03:15,520 --> 00:03:16,420 getting somewhere we're getting a 83 00:03:16,420 --> 00:03:18,640 different error message. In this case if 84 00:03:18,640 --> 00:03:20,710 remember we changed this to say Bob, so 85 00:03:20,710 --> 00:03:23,890 let's change that back to London so that 86 00:03:23,890 --> 00:03:26,770 it's a valid location, and send that. And 87 00:03:26,770 --> 00:03:28,660 now you can see we've gotten back a 88 00:03:28,660 --> 00:03:31,330 response that has data about the London 89 00:03:31,330 --> 00:03:33,430 time zone, and if we look at the test 90 00:03:33,430 --> 00:03:35,710 results here everything has passed and 91 00:03:35,710 --> 00:03:38,320 is as we expected. So when debugging 92 00:03:38,320 --> 00:03:39,880 tests you can see there's a number of 93 00:03:39,880 --> 00:03:41,530 things that we can do. Wwe can experiment 94 00:03:41,530 --> 00:03:43,180 with different things in the response to 95 00:03:43,180 --> 00:03:44,710 try and help us understand what's going 96 00:03:44,710 --> 00:03:45,100 on, 97 00:03:45,100 --> 00:03:46,870 we can look at the actual data being 98 00:03:46,870 --> 00:03:48,550 sent to the server to dig in and get 99 00:03:48,550 --> 00:03:50,710 more details in the console, and of 100 00:03:50,710 --> 00:03:52,060 course another important source of 101 00:03:52,060 --> 00:03:54,310 information is the documentation. By 102 00:03:54,310 --> 00:03:55,540 digging through these sources of 103 00:03:55,540 --> 00:03:57,490 information, and by trying and 104 00:03:57,490 --> 00:03:59,080 experimenting with things we can figure 105 00:03:59,080 --> 00:04:01,060 out what's going wrong in our test. In 106 00:04:01,060 --> 00:04:03,040 the next video we're going to look at 107 00:04:03,040 --> 00:04:05,740 how we can improve our API documentation, 108 00:04:05,740 --> 00:04:07,510 so that we can keep things well 109 00:04:07,510 --> 00:04:12,510 documented with Postman.