Skip to content

Commit 4ef3177

Browse files
committed
feat(cucumberDeleteUser): implement delete user functionality and corresponding tests
1 parent 4b1e3e1 commit 4ef3177

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/test/java/feature/SpringIntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ protected void executePost(String path, Object payload) {
4646
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
4747
latestResponse = restTemplate.postForEntity(url, request, String.class);
4848
}
49+
50+
protected void executeDelete(String path) {
51+
String url = "http://localhost:" + port + path;
52+
restTemplate.delete(url);
53+
latestResponse = ResponseEntity.noContent().build();
54+
}
4955
}

src/test/java/feature/StepDefinition.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,21 @@ public void theClientCallToGetTheCreatedUser() {
7979
assertNotNull(createdUserId, "No user was created before this step");
8080
executeGet("/random-users/" + createdUserId);
8181
}
82+
83+
@When("the client call to DELETE the created user")
84+
public void theClientCallToDeleteTheCreatedUser() {
85+
assertNotNull(createdUserId, "No user was created before this step");
86+
executeDelete("/random-users/" + createdUserId);
87+
}
88+
89+
@When("the client call to DELETE /random-users/{int}")
90+
public void theClientCallToDeleteRandomUser(int id) {
91+
executeDelete("/random-users/" + id);
92+
}
93+
94+
@When("the client call to GET the deleted user")
95+
public void theClientCallToGetTheDeletedUser() {
96+
assertNotNull(createdUserId, "No user was created before this step");
97+
executeGet("/random-users/" + createdUserId);
98+
}
8299
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Delete user endpoint
2+
3+
Scenario: Delete a user successfully after creation
4+
Given a valid user payload for creation
5+
When the client call to POST /random-users
6+
Then the response status should be 201
7+
And the user profile
8+
| id | <generated_id> |
9+
| firstname | Emma |
10+
When the client call to DELETE the created user
11+
Then the response status should be 204
12+
When the client call to GET the deleted user
13+
Then the response status should be 404
14+
15+
Scenario: Delete a user that does not exist
16+
When the client call to DELETE /random-users/999
17+
Then the response status should be 204

0 commit comments

Comments
 (0)