From 5df86d6caa4a7ec849d1cfcb09ba5b1f4a810424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Thu, 2 Apr 2026 16:09:55 +0200 Subject: [PATCH 1/2] feat(cucumberDeleteUser): implement delete user functionality and corresponding tests --- .../java/feature/SpringIntegrationTest.java | 6 ++++++ src/test/java/feature/StepDefinition.java | 18 ++++++++++++++++++ .../resources/features/delete_user.feature | 17 +++++++++++++++++ 3 files changed, 41 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..d7ae978 100644 --- a/src/test/java/feature/SpringIntegrationTest.java +++ b/src/test/java/feature/SpringIntegrationTest.java @@ -46,4 +46,10 @@ 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; + restTemplate.delete(url); + latestResponse = ResponseEntity.noContent().build(); + } } diff --git a/src/test/java/feature/StepDefinition.java b/src/test/java/feature/StepDefinition.java index a4423fa..5451af4 100644 --- a/src/test/java/feature/StepDefinition.java +++ b/src/test/java/feature/StepDefinition.java @@ -79,4 +79,22 @@ public void theClientCallToGetTheCreatedUser() { assertNotNull(createdUserId, "No user was created before this step"); executeGet("/random-users/" + createdUserId); } + + @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); + } + + @When("the client call to DELETE /random-users/{int}") + public void theClientCallToDeleteRandomUser(int id) { + executeDelete("/random-users/" + id); + } + + @When("the client call to GET the deleted user") + public void theClientCallToGetTheDeletedUser() { + assertNotNull(createdUserId, "No user was created before this step"); + String deletedUserPath = String.format("/random-users/%s", createdUserId); + executeGet(deletedUserPath); + } } diff --git a/src/test/resources/features/delete_user.feature b/src/test/resources/features/delete_user.feature new file mode 100644 index 0000000..0e3395e --- /dev/null +++ b/src/test/resources/features/delete_user.feature @@ -0,0 +1,17 @@ +Feature: Delete user endpoint + + Scenario: Delete a user successfully 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 | | + | firstname | Emma | + When the client call to DELETE the created user + Then the response status should be 204 + When the client call to GET the deleted user + Then the response status should be 404 + + Scenario: Delete a user that does not exist + When the client call to DELETE /random-users/999 + Then the response status should be 204 From adaf5c0b3cf6d1b40b1a625ce1d0f01914e07916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Leb=C3=A8gue?= Date: Fri, 3 Apr 2026 15:03:56 +0200 Subject: [PATCH 2/2] fix(returnStatus): the return status should be 404 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/test/resources/features/delete_user.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/features/delete_user.feature b/src/test/resources/features/delete_user.feature index 0e3395e..b5dad31 100644 --- a/src/test/resources/features/delete_user.feature +++ b/src/test/resources/features/delete_user.feature @@ -14,4 +14,4 @@ Feature: Delete user endpoint Scenario: Delete a user that does not exist When the client call to DELETE /random-users/999 - Then the response status should be 204 + Then the response status should be 404