Skip to content

Test: UserServiceTest – CRUD-logik och affärsregler #148

Description

@lindaeskilsson

Mocka: UserRepository, ClinicRepository, PetRepository, MedicalRecordRepository

createUser:

  • Skapar OWNER utan clinicId → sparas, lösenord hashas (inte sparas i klartext)
  • Skapar VET med giltigt clinicId → klinik kopplas
  • Skapar VET utan clinicId → BusinessRuleException
  • Skapar OWNER med clinicId → BusinessRuleException
  • Email redan registrerad → BusinessRuleException

getById:

  • Hittar användare → returnerar UserResponse
  • Finns inte → ResourceNotFoundException

getByEmail:

  • Hittar användare → returnerar User
  • Finns inte → ResourceNotFoundException

getAllUsers:

  • Returnerar mappade UserResponse-objekt för alla användare

updateUser:

  • Uppdaterar namn → namn ändras
  • Uppdaterar email till ledig adress → email ändras
  • Uppdaterar email till redan tagen adress (annan user) → BusinessRuleException
  • Uppdaterar clinicId på VET → klinik byts
  • Uppdaterar clinicId på OWNER → BusinessRuleException
  • Användare finns inte → ResourceNotFoundException

deleteUser:

  • Användare utan kopplingar → userRepository.delete() anropas
  • Har kopplade djur (petRepository.existsByOwner_Id) → BusinessRuleException
  • Är ägare på journalposter → BusinessRuleException
  • Är tilldelad veterinär på journalposter → BusinessRuleException
  • Har skapat journalposter → BusinessRuleException
  • Har uppdaterat journalposter → BusinessRuleException
  • Finns inte → ResourceNotFoundException

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions