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..b5dad31 --- /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 404