From c36b2dbcaeea5e257f7951dacb4f07301237817c Mon Sep 17 00:00:00 2001 From: clean-coder Date: Tue, 30 Jul 2024 06:45:46 +0200 Subject: [PATCH] #931: UserBusinessService test for delete user by id --- .../UserAuthorizationService.java | 2 +- .../service/business/UserBusinessService.java | 3 ++- .../business/UserBusinessServiceTest.java | 25 +++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/ch/puzzle/okr/service/authorization/UserAuthorizationService.java b/backend/src/main/java/ch/puzzle/okr/service/authorization/UserAuthorizationService.java index 80ba0d535c..fcad63ae78 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/authorization/UserAuthorizationService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/authorization/UserAuthorizationService.java @@ -68,7 +68,7 @@ public boolean isUserOwnerOfKeyResults(long id) { public void deleteEntityById(long id) { // TODO check Role - userBusinessService.deleteUser(id); + userBusinessService.deleteEntityById(id); } } diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/UserBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/UserBusinessService.java index 4173e18959..cfb7d3901e 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/business/UserBusinessService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/business/UserBusinessService.java @@ -71,7 +71,8 @@ public List createUsers(List userList) { } @Transactional - public void deleteUser(long id) { + public void deleteEntityById(long id) { + validationService.validateOnDelete(id); userPersistenceService.deleteById(id); } } diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/UserBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/UserBusinessServiceTest.java index 29eb1f74af..f3eacf4d08 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/UserBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/UserBusinessServiceTest.java @@ -38,11 +38,19 @@ class UserBusinessServiceTest { @BeforeEach void setUp() { - User userAlice = User.Builder.builder().withId(2L).withFirstname("Alice").withLastname("Wunderland") - .withEmail("wunderland@puzzle.ch").build(); - - User userBob = User.Builder.builder().withId(9L).withFirstname("Bob").withLastname("Baumeister") - .withEmail("baumeister@puzzle.ch").build(); + User userAlice = User.Builder.builder() // + .withId(2L) // + .withFirstname("Alice") // + .withLastname("Wunderland") // + .withEmail("wunderland@puzzle.ch") // + .build(); + + User userBob = User.Builder.builder() // + .withId(9L) // + .withFirstname("Bob") // + .withLastname("Baumeister") // + .withEmail("baumeister@puzzle.ch") // + .build(); userList = Arrays.asList(userAlice, userBob); } @@ -162,4 +170,11 @@ void setOkrChampion_shouldNotThrowExceptionIfSecondLastOkrChampIsRemoved() { verify(userPersistenceService, times(1)).save(user); assertFalse(user.isOkrChampion()); } + + @Test + void shouldDeleteUser() { + userBusinessService.deleteEntityById(23L); + + verify(userPersistenceService, times(1)).deleteById(23L); + } }