1 00:00:00,170 --> 00:00:03,060 Hi and welcome to this video on testing 2 00:00:03,060 --> 00:00:05,370 DELETE calls. Now DELETE calls are pretty 3 00:00:05,370 --> 00:00:05,970 self-explanatory, 4 00:00:05,970 --> 00:00:08,580 they allow you to delete existing 5 00:00:08,580 --> 00:00:10,679 resources from your service. As you can 6 00:00:10,679 --> 00:00:12,090 imagine there's many things we want to 7 00:00:12,090 --> 00:00:14,250 carefully test when it comes to deleting 8 00:00:14,250 --> 00:00:16,410 things. You don't want to delete the 9 00:00:16,410 --> 00:00:18,690 wrong things, we want to make sure that 10 00:00:18,690 --> 00:00:20,550 we have all the right checks in place to 11 00:00:20,550 --> 00:00:22,199 prevent things from being deleted that 12 00:00:22,199 --> 00:00:24,600 should not be. This can take the form of 13 00:00:24,600 --> 00:00:26,369 authentication and authorization, in 14 00:00:26,369 --> 00:00:28,170 other words making sure you can't delete 15 00:00:28,170 --> 00:00:30,060 other users content for example, or 16 00:00:30,060 --> 00:00:32,159 making sure that only users with certain 17 00:00:32,159 --> 00:00:34,350 permission levels can delete things. It 18 00:00:34,350 --> 00:00:36,270 can also take the form of data types, 19 00:00:36,270 --> 00:00:38,489 perhaps only certain things in your 20 00:00:38,489 --> 00:00:40,590 service can be deleted, you might have 21 00:00:40,590 --> 00:00:42,329 shared resources that you don't want to 22 00:00:42,329 --> 00:00:44,730 allow people to delete, or you might not 23 00:00:44,730 --> 00:00:46,920 allow deleting of objects until child 24 00:00:46,920 --> 00:00:49,050 objects have been removed. Okay let's 25 00:00:49,050 --> 00:00:52,680 take a look at an example. So here I have 26 00:00:52,680 --> 00:00:54,660 a simple setup similar to the previous 27 00:00:54,660 --> 00:00:58,379 videos, where we have a user so it's our 28 00:00:58,379 --> 00:01:01,410 profile, and I've included the embed 29 00:01:01,410 --> 00:01:04,409 parameter to embed the blog posts. So 30 00:01:04,409 --> 00:01:06,269 we're doing a GET call here, so let's 31 00:01:06,269 --> 00:01:08,490 just send that and see what this gets 32 00:01:08,490 --> 00:01:11,790 back. So we get our user John Smith and 33 00:01:11,790 --> 00:01:14,130 we get the blog post that belonged to 34 00:01:14,130 --> 00:01:18,659 his ID. Now we can modify this as well so 35 00:01:18,659 --> 00:01:20,840 let's change this, and we can see 36 00:01:20,840 --> 00:01:26,040 comments that he has also contributed 37 00:01:26,040 --> 00:01:29,189 some comments as well. So this user has 38 00:01:29,189 --> 00:01:32,040 both blog posts and comments that are 39 00:01:32,040 --> 00:01:36,869 associated with his profile. Now let's go 40 00:01:36,869 --> 00:01:38,729 ahead and delete this user, and see what 41 00:01:38,729 --> 00:01:40,619 happens. So we'll get rid of the 42 00:01:40,619 --> 00:01:43,920 parameters here, so profile slash one and 43 00:01:43,920 --> 00:01:46,979 we're going to do a DELETE. So we'll 44 00:01:46,979 --> 00:01:49,500 delete this profile and we'll see what 45 00:01:49,500 --> 00:01:52,860 happens. So we'll send that and we get 46 00:01:52,860 --> 00:01:54,930 back an empty response, this profile no 47 00:01:54,930 --> 00:01:57,270 longer exists, that's what we expect. And 48 00:01:57,270 --> 00:02:01,200 now let's get on the blog posts and see 49 00:02:01,200 --> 00:02:05,700 what happens. So blog posts, and we'll do 50 00:02:05,700 --> 00:02:09,660 a GET and we'll send that, we can see 51 00:02:09,660 --> 00:02:11,220 there's no blog post here, so the blog 52 00:02:11,220 --> 00:02:13,199 post that were there before the blog 53 00:02:13,199 --> 00:02:13,949 posts that were 54 00:02:13,949 --> 00:02:17,459 associated with that user profile have 55 00:02:17,459 --> 00:02:21,209 been removed. Now this may or may not we 56 00:02:21,209 --> 00:02:23,220 want our application do, maybe we have a 57 00:02:23,220 --> 00:02:25,440 requirement that all associated data be 58 00:02:25,440 --> 00:02:28,620 removed when a users removed, or maybe we 59 00:02:28,620 --> 00:02:30,510 want to keep the data from deleted users 60 00:02:30,510 --> 00:02:32,569 so that common threads make more sense. 61 00:02:32,569 --> 00:02:35,099 Whatever the business use case here we 62 00:02:35,099 --> 00:02:37,560 can see the importance of checking what 63 00:02:37,560 --> 00:02:39,030 happens to objects that are linked 64 00:02:39,030 --> 00:02:40,530 together when deleting stuff in the 65 00:02:40,530 --> 00:02:42,810 system. You could imagine that this could 66 00:02:42,810 --> 00:02:46,019 be a bad thing, we might have deleted a 67 00:02:46,019 --> 00:02:47,430 whole bunch of data that we shouldn't 68 00:02:47,430 --> 00:02:49,620 have deleted with this call. And so we 69 00:02:49,620 --> 00:02:51,660 want to be careful and check associated 70 00:02:51,660 --> 00:02:53,610 data when we delete it, do we delete only 71 00:02:53,610 --> 00:02:56,340 what we expect? Do we delete everything 72 00:02:56,340 --> 00:02:59,099 that we expect to be deleted? We need to 73 00:02:59,099 --> 00:03:00,900 check these kinds of things when testing 74 00:03:00,900 --> 00:03:03,930 delete on an API. So at this point we've 75 00:03:03,930 --> 00:03:06,299 covered the major REST API actions, we've 76 00:03:06,299 --> 00:03:08,730 looked at GET, we looked at POST, we've 77 00:03:08,730 --> 00:03:10,950 looked at PUT, and we've looked at DELETE, 78 00:03:10,950 --> 00:03:12,930 and we've looked at ways that we can 79 00:03:12,930 --> 00:03:15,420 think about testing these, we've looked 80 00:03:15,420 --> 00:03:17,670 at a few simple examples to help get us 81 00:03:17,670 --> 00:03:20,100 on the right track towards testing these. 82 00:03:20,100 --> 00:03:22,260 And there of course other options that 83 00:03:22,260 --> 00:03:25,170 are available, you can see it in Postman 84 00:03:25,170 --> 00:03:26,760 here itself, when we do this drop down 85 00:03:26,760 --> 00:03:29,310 there's quite a large link of different 86 00:03:29,310 --> 00:03:31,410 options that are available. However if 87 00:03:31,410 --> 00:03:33,780 you know these four and you're able to 88 00:03:33,780 --> 00:03:35,700 use them and put them into practice, if 89 00:03:35,700 --> 00:03:37,620 you understand how to think about 90 00:03:37,620 --> 00:03:39,209 testing the four that we've covered, 91 00:03:39,209 --> 00:03:41,790 you're well on your way to be in an API 92 00:03:41,790 --> 00:03:45,299 testing professional. So at this point 93 00:03:45,299 --> 00:03:47,190 we're ready to put it all into practice, 94 00:03:47,190 --> 00:03:49,049 we're ready to take all that we've 95 00:03:49,049 --> 00:03:51,329 learned and kind of try it out on a real 96 00:03:51,329 --> 00:03:53,519 life challenge. And so I hope to see you 97 00:03:53,519 --> 00:03:55,170 in the next video, where we'll talk about 98 00:03:55,170 --> 00:04:00,170 the find the 500 testing challenge.