Skip to content

Commit 774bb7f

Browse files
committed
More delete request tests
1 parent 9fa3ac5 commit 774bb7f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/test/java/com/typicode/jsonplaceholder/features/Posts.feature

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,24 @@ Feature: Posts Endpoint
6565
And the response body matches the following
6666
| key | value |
6767
| id | 101 |
68-
68+
69+
Scenario: Delete post
70+
# If this was a real API supported by a working data source I would make a GET request to the Posts endpoint after
71+
# deleting the post to ensure that the total number of posts has decreased and that post 1 had been deleted
72+
When I make a DELETE request to the Posts endpoint with a path parameter of 1
73+
Then the response has a status code of 200
74+
And the response body is an empty JSON object
75+
76+
Scenario Outline: Delete post with invalid ID - post #<ID>
77+
# As this is a fake API without an underlying data source that updates based on the API requests, a delete request
78+
# returns a success response regardless of the post ID passed in via the path parameters. This should raise an error
79+
# for a real API
80+
When I make a DELETE request to the Posts endpoint with a path parameter of <ID>
81+
Then the response has a status code of 200
82+
And the response body is an empty JSON object
83+
Examples:
84+
| ID |
85+
| 0 |
86+
| 101 |
87+
| -1 |
88+

src/test/java/com/typicode/jsonplaceholder/steps/CommonSteps.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static void makeGetRequest(String endpoint) {
5555
response = RequestHelpers.sendGetRequestTo(endpoints.get(endpoint));
5656
responses.add(response);
5757
}
58+
5859
@When("^I make a GET request to the (Posts|Comments|Albums|Photos|ToDos|Users) endpoint with a path parameter of (-?\\d+)$")
5960
public static void makeGetRequestWithPathParameter(String endpoint, int pathParam) {
6061
response = RequestHelpers.sendGetRequestTo(endpoints.get(endpoint) + "/" + pathParam);
@@ -79,6 +80,13 @@ public static void makeDeleteRequest(String endpoint) {
7980
responses.add(response);
8081
}
8182

83+
@When("^I make a DELETE request to the (Posts|Comments|Albums|Photos|ToDos|Users) endpoint with a path parameter of (-?\\d+)$")
84+
public static void makeDeleteRequestWithPathParameter(String endpoint, int pathParam) {
85+
response = RequestHelpers.sendDeleteRequestTo(endpoints.get(endpoint) + "/" + pathParam);
86+
responses.add(response);
87+
}
88+
89+
8290
@Then("the response has a status code of {int}")
8391
public static void verifyResponseStatusCode(int code) {
8492
assertEquals(code, response.statusCode());

0 commit comments

Comments
 (0)