From 7dd01ae736e296882bc6074f4b6e4af071213ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Mon, 20 Apr 2026 16:44:29 +0200 Subject: [PATCH 1/4] feat(testCucumberDeleteUser): add tests cucumber delete user --- src/test/java/feature/SpringIntegrationTest.java | 6 ++++++ src/test/java/feature/StepDefinition.java | 11 +++++++++++ src/test/resources/features/delete_user.feature | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/test/resources/features/delete_user.feature diff --git a/src/test/java/feature/SpringIntegrationTest.java b/src/test/java/feature/SpringIntegrationTest.java index e5e365c..838fbce 100644 --- a/src/test/java/feature/SpringIntegrationTest.java +++ b/src/test/java/feature/SpringIntegrationTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; @@ -46,4 +47,9 @@ protected void executePost(String path, Object payload) { HttpEntity request = new HttpEntity<>(payload, headers); latestResponse = restTemplate.postForEntity(url, request, String.class); } + + protected void executeDelete(String path) { + String url = "http://localhost:" + port + path; + latestResponse = restTemplate.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class); + } } diff --git a/src/test/java/feature/StepDefinition.java b/src/test/java/feature/StepDefinition.java index 7d0a4cb..bb06169 100644 --- a/src/test/java/feature/StepDefinition.java +++ b/src/test/java/feature/StepDefinition.java @@ -89,6 +89,17 @@ public void theClientCallToGetRandomUsersWithPageAndSize(int page, int size) { executeGet("/random-users?page=" + page + "&size=" + size); } + @When("the client call to DELETE \/random-users\/{int}") + public void theClientCallToDeleteRandomUser(int id) { + executeDelete("/random-users/" + id); + } + + @When("the client call to DELETE the created user") + public void theClientCallToDeleteTheCreatedUser() { + assertNotNull(createdUserId, "No user was created before this step"); + executeDelete("/random-users/" + createdUserId); + } + @And("the response contains a list of users") public void theResponseContainsAListOfUsers() throws Exception { JsonNode body = objectMapper.readTree(latestResponse.getBody()); diff --git a/src/test/resources/features/delete_user.feature b/src/test/resources/features/delete_user.feature new file mode 100644 index 0000000..43435ec --- /dev/null +++ b/src/test/resources/features/delete_user.feature @@ -0,0 +1,16 @@ +Feature: Delete user endpoint + + Scenario: Delete a user by ID after creation + Given a valid user payload for creation + When the client call to POST /random-users + Then the response status should be 201 + And the user profile + | id | | + When the client call to DELETE the created user + Then the response status should be 204 + When the client call to GET the created user + Then the response status should be 404 + + Scenario: Delete a user that does not exist + When the client call to DELETE /random-users/999999 + Then the response status should be 404 From 1156b18c3b225b93f5b39008323c9197a1afe6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Mon, 20 Apr 2026 16:49:17 +0200 Subject: [PATCH 2/4] fix(StepDefinition): escape slashes in DELETE endpoint step definition --- src/test/java/feature/StepDefinition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/feature/StepDefinition.java b/src/test/java/feature/StepDefinition.java index bb06169..fbb2966 100644 --- a/src/test/java/feature/StepDefinition.java +++ b/src/test/java/feature/StepDefinition.java @@ -89,7 +89,7 @@ public void theClientCallToGetRandomUsersWithPageAndSize(int page, int size) { executeGet("/random-users?page=" + page + "&size=" + size); } - @When("the client call to DELETE \/random-users\/{int}") + @When("the client call to DELETE \\/random-users\\/{int}") public void theClientCallToDeleteRandomUser(int id) { executeDelete("/random-users/" + id); } From 41acb3256b8c94b79c79eb7bf911fac26884713c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Mon, 20 Apr 2026 16:53:30 +0200 Subject: [PATCH 3/4] feat(tests): rectify http error code --- src/test/resources/features/delete_user.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/resources/features/delete_user.feature b/src/test/resources/features/delete_user.feature index 43435ec..d5199e1 100644 --- a/src/test/resources/features/delete_user.feature +++ b/src/test/resources/features/delete_user.feature @@ -7,9 +7,9 @@ Feature: Delete user endpoint And the user profile | id | | When the client call to DELETE the created user - Then the response status should be 204 + Then the response status should be 200 When the client call to GET the created user - Then the response status should be 404 + Then the response status should be 400 Scenario: Delete a user that does not exist When the client call to DELETE /random-users/999999 From 789c26ed95b077de34aef091444b5bcd5d8c997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Mon, 20 Apr 2026 16:59:44 +0200 Subject: [PATCH 4/4] fix(delete_user): correct response status codes for delete user scenarios --- src/test/resources/features/delete_user.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/resources/features/delete_user.feature b/src/test/resources/features/delete_user.feature index d5199e1..cfdb000 100644 --- a/src/test/resources/features/delete_user.feature +++ b/src/test/resources/features/delete_user.feature @@ -9,8 +9,8 @@ Feature: Delete user endpoint When the client call to DELETE the created user Then the response status should be 200 When the client call to GET the created user - Then the response status should be 400 + Then the response status should be 404 Scenario: Delete a user that does not exist When the client call to DELETE /random-users/999999 - Then the response status should be 404 + Then the response status should be 200