Skip to content

feat(cucumberDeleteUser): implement delete user functionality and cor…#65

Closed
Theo-lbg wants to merge 3 commits into
mainfrom
feat/cucumberDeleteUser
Closed

feat(cucumberDeleteUser): implement delete user functionality and cor…#65
Theo-lbg wants to merge 3 commits into
mainfrom
feat/cucumberDeleteUser

Conversation

@Theo-lbg
Copy link
Copy Markdown
Collaborator

@Theo-lbg Theo-lbg commented Apr 2, 2026

…responding tests

@Theo-lbg Theo-lbg force-pushed the feat/cucumberDeleteUser branch from 4ef3177 to 5df86d6 Compare April 2, 2026 14:13
@Theo-lbg Theo-lbg linked an issue Apr 2, 2026 that may be closed by this pull request
@Theo-lbg Theo-lbg marked this pull request as ready for review April 3, 2026 12:59
Copilot AI review requested due to automatic review settings April 3, 2026 12:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Cucumber coverage for the /random-users/{id} DELETE flow (delete after create, and delete non-existent user) in the existing Spring Boot integration test setup.

Changes:

  • Add a new Cucumber feature for deleting users.
  • Add step definitions for DELETE and “GET after delete”.
  • Add a SpringIntegrationTest helper for executing DELETE requests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/test/resources/features/delete_user.feature New feature scenarios for deleting an existing and a non-existing user
src/test/java/feature/StepDefinition.java New Cucumber steps to issue DELETE requests and verify behavior after deletion
src/test/java/feature/SpringIntegrationTest.java Adds executeDelete() helper used by step definitions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/java/feature/SpringIntegrationTest.java
Comment thread src/test/resources/features/delete_user.feature Outdated
Copilot AI review requested due to automatic review settings April 3, 2026 13:03
@sonarqube-xpeho
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/java/feature/SpringIntegrationTest.java
@Theo-lbg Theo-lbg force-pushed the feat/cucumberDeleteUser branch from adaf5c0 to dcbfc1c Compare April 15, 2026 08:28
Comment thread src/test/java/feature/StepDefinition.java Outdated
Copilot AI review requested due to automatic review settings April 15, 2026 08:43
@sonarqube-xpeho
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,17 @@
Feature: Delete user endpoint
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file starts with extra indentation before the Feature: keyword. Other feature files in this repo (e.g., get_user.feature) start Feature: at column 1; aligning to that keeps the Gherkin style consistent and avoids tooling/parser edge cases.

Copilot uses AI. Check for mistakes.
executeDelete("/random-users/" + createdUserId);
}

@When("^the client call to DELETE /random-users/(\\d+)$")
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step definition uses a raw regex (^...$ with \d+) while the rest of the file uses Cucumber expressions (e.g., {int} for GET). For consistency and easier maintenance, switch this to a Cucumber expression like the client call to DELETE /random-users/{int}.

Suggested change
@When("^the client call to DELETE /random-users/(\\d+)$")
@When("the client call to DELETE /random-users/{int}")

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 15, 2026 14:29
@MayuriXx MayuriXx force-pushed the feat/cucumberDeleteUser branch from 8e4e4bc to 93a13c0 Compare April 15, 2026 14:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 15 to 17
public void execute(long id) {
userService.getById(id).orElseThrow(() -> new UserNotFoundException(id));
userService.deleteById(id);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use case now calls userService.getById(id).orElseThrow(...) before deleting. Existing unit tests for DeleteUserByIdUseCase that don't stub getById will start failing with a NullPointerException (Mockito returns null by default for unstubbed calls returning Optional). Update the tests to stub getById and/or adjust interaction verifications accordingly.

Copilot uses AI. Check for mistakes.
@ApiResponse(responseCode = "404", description = "The requested user does not exist")
@ApiResponse(responseCode = "500", description = "Internal server error")
void deleteUserById(
ResponseEntity<Void> deleteUserById(
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteUserById method signature is indented differently than the other endpoints in this interface. Align its indentation with the surrounding methods to keep formatting consistent (and avoid potential style/lint failures if enforced).

Suggested change
ResponseEntity<Void> deleteUserById(
ResponseEntity<Void> deleteUserById(

Copilot uses AI. Check for mistakes.
@MayuriXx MayuriXx force-pushed the feat/cucumberDeleteUser branch from 93a13c0 to d0e9803 Compare April 16, 2026 08:12
Copilot AI review requested due to automatic review settings April 20, 2026 14:23
@Theo-lbg Theo-lbg force-pushed the feat/cucumberDeleteUser branch from d0e9803 to 16ff233 Compare April 20, 2026 14:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 162 to 171
@DisplayName("Should log warning when deleteUserById throws UserNotFoundException")
void shouldLogWarningWhenDeleteUserByIdFails() {
int userId = 123;
doThrow(new UserNotFoundException(userId)).when(deleteUserUseCase).execute(userId);

userHandler.deleteUserById(userId);
ResponseEntity<Void> response = userHandler.deleteUserById(userId);

assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
assertNull(response.getBody());
verify(deleteUserUseCase, times(1)).execute(userId);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name/DisplayName says it "Should log warning" but the assertions only check the returned HTTP status/body. Either verify that a warning log was emitted (using a log-capture utility) or rename the test to reflect what it actually asserts (e.g., returning 404).

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +12
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
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature introduces steps ("DELETE the created user" / "GET the deleted user") but there are no matching step definitions in src/test/java/feature/StepDefinition.java, so Cucumber will fail with undefined steps. Add corresponding @When bindings that use createdUserId and call executeDelete("/random-users/" + createdUserId) and executeGet("/random-users/" + createdUserId) (with an assertion that createdUserId is set).

Suggested change
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
When the client call to DELETE /random-users/<generated_id>
Then the response status should be 204
When the client call to GET /random-users/<generated_id>

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +17
Scenario: Delete a user that does not exist
When the client call to DELETE /random-users/999
Then the response status should be 404
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario uses the step text "When the client call to DELETE /random-users/999", but there is no matching step definition in StepDefinition.java. Add a parameterized @When step for DELETE /random-users/{int} that calls executeDelete("/random-users/" + id).

Copilot uses AI. Check for mistakes.
Comment on lines 15 to 17
public void execute(long id) {
userService.getById(id).orElseThrow(() -> new UserNotFoundException(id));
userService.deleteById(id);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute() does a separate getById() check followed by deleteById(). With JpaRepository.deleteById, there is still a race where the row can be deleted between those calls, causing EmptyResultDataAccessException and a 500 instead of 404. Consider wrapping userService.deleteById(id) in a try/catch that translates EmptyResultDataAccessException (or equivalent) into UserNotFoundException, or exposing a service-level delete that is idempotent / returns whether a row was deleted.

Copilot uses AI. Check for mistakes.
@Theo-lbg Theo-lbg closed this Apr 20, 2026
@Theo-lbg Theo-lbg deleted the feat/cucumberDeleteUser branch April 20, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants