Skip to content

Commit 65800bf

Browse files
authored
feat(testCucumberDeleteUser): add tests cucumber delete user (#76)
* feat(testCucumberDeleteUser): add tests cucumber delete user * fix(StepDefinition): escape slashes in DELETE endpoint step definition * feat(tests): rectify http error code * fix(delete_user): correct response status codes for delete user scenarios
1 parent 9119522 commit 65800bf

3 files changed

Lines changed: 33 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
@@ -9,6 +9,7 @@
99
import org.springframework.boot.test.web.server.LocalServerPort;
1010
import org.springframework.http.HttpEntity;
1111
import org.springframework.http.HttpHeaders;
12+
import org.springframework.http.HttpMethod;
1213
import org.springframework.http.MediaType;
1314
import org.springframework.http.ResponseEntity;
1415
import org.springframework.test.context.ActiveProfiles;
@@ -46,4 +47,9 @@ protected void executePost(String path, Object payload) {
4647
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
4748
latestResponse = restTemplate.postForEntity(url, request, String.class);
4849
}
50+
51+
protected void executeDelete(String path) {
52+
String url = "http://localhost:" + port + path;
53+
latestResponse = restTemplate.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);
54+
}
4955
}

src/test/java/feature/StepDefinition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ public void theClientCallToGetRandomUsersWithPageAndSize(int page, int size) {
8989
executeGet("/random-users?page=" + page + "&size=" + size);
9090
}
9191

92+
@When("the client call to DELETE \\/random-users\\/{int}")
93+
public void theClientCallToDeleteRandomUser(int id) {
94+
executeDelete("/random-users/" + id);
95+
}
96+
97+
@When("the client call to DELETE the created user")
98+
public void theClientCallToDeleteTheCreatedUser() {
99+
assertNotNull(createdUserId, "No user was created before this step");
100+
executeDelete("/random-users/" + createdUserId);
101+
}
102+
92103
@And("the response contains a list of users")
93104
public void theResponseContainsAListOfUsers() throws Exception {
94105
JsonNode body = objectMapper.readTree(latestResponse.getBody());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: Delete user endpoint
2+
3+
Scenario: Delete a user by ID 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+
When the client call to DELETE the created user
10+
Then the response status should be 200
11+
When the client call to GET the created user
12+
Then the response status should be 404
13+
14+
Scenario: Delete a user that does not exist
15+
When the client call to DELETE /random-users/999999
16+
Then the response status should be 200

0 commit comments

Comments
 (0)