-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc9a232
commit 756dd72
Showing
12 changed files
with
229 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/ch/puzzle/okr/dto/userOkrData/UserKeyResultDataDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ch.puzzle.okr.dto.userOkrData; | ||
|
||
public record UserKeyResultDataDto(Long keyResultId, String keyResultName, Long objectiveId, String objectiveName) { | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/ch/puzzle/okr/dto/userOkrData/UserOkrDataDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ch.puzzle.okr.dto.userOkrData; | ||
|
||
import java.util.List; | ||
|
||
public record UserOkrDataDto(List<UserKeyResultDataDto> keyResults) { | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/ch/puzzle/okr/mapper/UserOkrDataMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ch.puzzle.okr.mapper; | ||
|
||
import ch.puzzle.okr.dto.userOkrData.UserKeyResultDataDto; | ||
import ch.puzzle.okr.dto.userOkrData.UserOkrDataDto; | ||
import ch.puzzle.okr.models.keyresult.KeyResult; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class UserOkrDataMapper { | ||
|
||
public UserOkrDataDto toDto(List<KeyResult> keyResults) { | ||
return new UserOkrDataDto(toUserKeyResultDataDtos(keyResults)); | ||
} | ||
|
||
private List<UserKeyResultDataDto> toUserKeyResultDataDtos(List<KeyResult> keyResults) { | ||
return keyResults.stream() // | ||
.map(keyResult -> new UserKeyResultDataDto( // | ||
keyResult.getId(), keyResult.getTitle(), // | ||
keyResult.getObjective().getId(), keyResult.getObjective().getTitle() // | ||
)) // | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,19 @@ class UserBusinessServiceTest { | |
|
||
@BeforeEach | ||
void setUp() { | ||
User userAlice = User.Builder.builder().withId(2L).withFirstname("Alice").withLastname("Wunderland") | ||
.withEmail("[email protected]").build(); | ||
|
||
User userBob = User.Builder.builder().withId(9L).withFirstname("Bob").withLastname("Baumeister") | ||
.withEmail("[email protected]").build(); | ||
User userAlice = User.Builder.builder() // | ||
.withId(2L) // | ||
.withFirstname("Alice") // | ||
.withLastname("Wunderland") // | ||
.withEmail("[email protected]") // | ||
.build(); | ||
|
||
User userBob = User.Builder.builder() // | ||
.withId(9L) // | ||
.withFirstname("Bob") // | ||
.withLastname("Baumeister") // | ||
.withEmail("[email protected]") // | ||
.build(); | ||
|
||
userList = Arrays.asList(userAlice, userBob); | ||
} | ||
|
@@ -120,9 +128,8 @@ void getOrCreateUserShouldThrowResponseStatusExceptionWhenInvalidUser() { | |
Mockito.doThrow(new ResponseStatusException(HttpStatus.BAD_REQUEST, "Not allowed to give an id")) | ||
.when(validationService).validateOnGetOrCreate(newUser); | ||
|
||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> { | ||
userBusinessService.getOrCreateUser(newUser); | ||
}); | ||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, | ||
() -> userBusinessService.getOrCreateUser(newUser)); | ||
|
||
assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode()); | ||
assertEquals("Not allowed to give an id", exception.getReason()); | ||
|
@@ -162,4 +169,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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package ch.puzzle.okr.service.persistence; | ||
|
||
import ch.puzzle.okr.exception.OkrResponseStatusException; | ||
import ch.puzzle.okr.models.User; | ||
import ch.puzzle.okr.multitenancy.TenantContext; | ||
import ch.puzzle.okr.test.SpringIntegrationTest; | ||
|
@@ -8,6 +9,9 @@ | |
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.dao.InvalidDataAccessApiUsageException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
@@ -178,4 +182,42 @@ private void assertUser(String firstName, String lastName, String email, User cu | |
assertEquals(lastName, currentUser.getLastname()); | ||
assertEquals(email, currentUser.getEmail()); | ||
} | ||
|
||
@DisplayName("deleteById() should delete user when user found") | ||
@Test | ||
void deleteByIdShouldDeleteUserWhenUserFound() { | ||
// arrange | ||
User user = createUser(); | ||
|
||
// act | ||
userPersistenceService.deleteById(user.getId()); | ||
|
||
// assert | ||
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, // | ||
() -> userPersistenceService.findById(createdUser.getId())); | ||
|
||
assertEquals(HttpStatus.NOT_FOUND, exception.getStatusCode()); | ||
} | ||
|
||
private User createUser() { | ||
User newUser = User.Builder.builder() // | ||
.withId(null) // | ||
.withFirstname("firstname") // | ||
.withLastname("lastname") // | ||
.withEmail("[email protected]") // | ||
.build(); | ||
createdUser = userPersistenceService.getOrCreateUser(newUser); | ||
assertNotNull(createdUser.getId()); | ||
return createdUser; | ||
} | ||
|
||
@DisplayName("deleteById() should throw exception when Id is null") | ||
@Test | ||
void deleteByIdShouldThrowExceptionWhenIdIsNull() { | ||
InvalidDataAccessApiUsageException exception = assertThrows(InvalidDataAccessApiUsageException.class, // | ||
() -> userPersistenceService.deleteById(null)); | ||
|
||
assertEquals("The given id must not be null", exception.getMessage()); | ||
} | ||
|
||
} |