Skip to content

Feat/user crud unit tests#46

Open
Aline-Pinotti wants to merge 17 commits into
mainfrom
feat/user-crud-unit-tests
Open

Feat/user crud unit tests#46
Aline-Pinotti wants to merge 17 commits into
mainfrom
feat/user-crud-unit-tests

Conversation

@Aline-Pinotti

Copy link
Copy Markdown
Collaborator

Summary

Implemented the complete User CRUD feature, including validation, exception handling, and unit tests.

Changes

  • Added UserEntity
  • Added UserController
  • Added UserRepository
  • Added UserDTO with Bean Validation
  • Implemented CRUD endpoints for user management
  • Added controller exception handling (ControllerHandleException)
  • Added custom exception support classes
  • Added unit tests for User components and validations

Impact

This PR introduces the User module and establishes a reusable exception handling structure for future features.

Notes

  • This PR establishes the foundation for user management and application-wide error handling.
  • Custom exception infrastructure can be reused by future modules.

@maxzdosreis maxzdosreis marked this pull request as draft June 9, 2026 22:34
@maxzdosreis maxzdosreis marked this pull request as ready for review June 9, 2026 22:34
@maxzdosreis maxzdosreis marked this pull request as draft June 9, 2026 22:34
@maxzdosreis maxzdosreis marked this pull request as ready for review June 9, 2026 22:34

@maxzdosreis maxzdosreis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Congratulations, I really liked the implementation. It just needs a few things aligned with the project standards, removing the comments, and some adjustments. It's also necessary to implement mappers (as mentioned in the comments) and implement the Swagger documentation for the controllers, always following the project standards. When submitting the PR for review, it's necessary to include evidence in the PR, such as approved tests, endpoint tests (e.g., the GET endpoint for /users in Postman), and a screenshot of the Swagger documentation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Remove the entire ControllerExceptionHandler, as exception handling is already present in the GlobalExceptionHandler of the project. Therefore, you should add the handlers and exceptions to the GlobalExceptionHandler.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ControllerExceptionHandler removed, Handlers moved to GlobalExceptionHandler.

@ControllerAdvice
public class ControllerExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • The handler for MethodArgumentNotValidException is duplicated; you should evaluate the other developer's implementation to see if it's feasible for your needs, and if necessary, make changes in a way that satisfies both your implementation and the other developer's.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Refactored MethodArgumentNotValidException handler in GlobalExceptionHandler to replace this.


return ResponseEntity.status(status).body(err);
}
@ExceptionHandler(DataIntegrityViolationException.class)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Implement in GlobalExceptionHandler.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return ResponseEntity.status(status).body(err);
}

@ExceptionHandler(DuplicateResourceValidationException.class)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Implement in GlobalExceptionHandler.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Move the FieldMessage to api/src/main/java/com/orderflow/ecommerce/dtos/.
    The record is an HTTP response template and should remain with the DTOS.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FieldMessage moved to api/src/main/java/com/orderflow/ecommerce/dtos/

}

@Test
void shouldUseSettersAndGetters() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Since the entity uses Lombok, I don't see the need to perform this test; it ends up being somewhat redundant, but it can be evaluated whether it should be removed or not.

}

@Test
void shouldHaveNullsWhenUsingNoArgsConstructor() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • It only checks id, name, and email for null values, but the no-args constructor leaves all fields as null. Either check all or check none—doing it halfway gives a false sense of coverage.

}

@Test
void equalsAndHashCodeShouldBeBasedOnlyOnId() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Missing the scenario of two objects with null IDs, something like:
    User d = new User();
    User e = new User();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Did all the tests pass? Review the tests according to the necessary changes that will occur.

@Test
void updateShouldThrowDuplicateResourceExceptionWhenEmailUsedByAnother() {

UserDto dto = new UserDto(existingId, "Bob New", "someoneelse@example.com", "pw",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • The password doesn't pass the regex, even though Bean Validation doesn't run in unit tests. Ideally, we should use a password that does pass the regex to simulate a real result.

@dbfcode

dbfcode commented Jun 13, 2026

Copy link
Copy Markdown
Owner

I reviewed the PR and followed the discussion. Nice work on the implementation, Aline, and great review points from Max as well.

Overall, I think this is moving in a good direction.

Since this is Aline’s first PR in this project and the conversation has grown a bit, I think it would be helpful to summarize the remaining required changes before merging.

@maxzdosreis, could you please add a short checklist in the main PR comment with the must-have items to close this PR? Ideally, only from the points already raised, without adding new items unless something is critical.

From my side, one point I would also adjust is the 0/1 handling to use a proper boolean type.

Other than that, I believe the remaining items are already being addressed. Let’s focus on closing this task, and we can continue polishing/refactoring afterward if needed.

Great work, everyone. Thanks for the commitment.

@dbfcode dbfcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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