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..fbb2966 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..cfdb000 --- /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 200 + 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 200