Skip to content

Test: Add unit tests for VetService (business logic and error handling)Β #168

Description

@lindaeskilsson

🎯 Goal

Add unit tests for VetService to ensure business logic, validation rules, and error handling work correctly.


πŸ“¦ Scope

πŸ”Ή createVet()

Test the following scenarios:

  • βœ… Should create vet successfully when valid input
  • ❌ Should throw ResourceNotFoundException when user does not exist
  • ❌ Should throw BusinessRuleException when licenseId already exists
  • ❌ Should throw BusinessRuleException when user is already registered as vet
  • βœ… Should update user role to VET if not already set
  • ❌ Should handle DataIntegrityViolationException and convert to BusinessRuleException

πŸ”Ή getAllVets()

  • βœ… Should return list of all vets
  • βœ… Should map Vet entities to VetResponse

πŸ”Ή getVetById(UUID id)

  • βœ… Should return vet when found
  • ❌ Should throw ResourceNotFoundException when vet does not exist

πŸ§ͺ Technical Notes

  • Use Mockito for mocking dependencies (VetRepository, UserRepository)
  • Use @ExtendWith(MockitoExtension.class)
  • Do NOT use Spring context (pure unit tests)
  • Verify interactions with repositories where relevant

βœ… Definition of Done

  • All scenarios covered with unit tests
  • Tests are isolated (no DB, no SpringBootTest)
  • All tests pass locally and in CI
  • Code follows project test conventions

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions