Public Access
feat(settings): store a favorite platform
This commit is contained in:
1 parent
315e22c220
commit
ea4ae089ff
14 files changed
+103
-3
No files matched your search
@@ -36,6 +36,7 @@ import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -355,7 +356,7 @@ class UserControllerTest extends AbstractWebMvcTest {
|
||||
String email = "test@example.com";
|
||||
UserSettings settings = UserSettings.builder().language("en").theme("dark")
|
||||
.dashboardTiles(List.of(new Tile("STATS_TREND", "L")))
|
||||
.profileTiles(List.of(new Tile("PLAYING", "S"))).build();
|
||||
.profileTiles(List.of(new Tile("PLAYING", "S"))).favoritePlatform("PS5").build();
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken(new UserPrincipal("1", email, null), null, Collections.emptyList())
|
||||
);
|
||||
@@ -366,7 +367,8 @@ class UserControllerTest extends AbstractWebMvcTest {
|
||||
.andExpect(jsonPath("$.settings.dashboardTiles[0].id").value("STATS_TREND"))
|
||||
.andExpect(jsonPath("$.settings.dashboardTiles[0].size").value("L"))
|
||||
.andExpect(jsonPath("$.settings.profileTiles[0].id").value("PLAYING"))
|
||||
.andExpect(jsonPath("$.settings.profileTiles[0].size").value("S"));
|
||||
.andExpect(jsonPath("$.settings.profileTiles[0].size").value("S"))
|
||||
.andExpect(jsonPath("$.settings.favoritePlatform").value("PS5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -410,6 +412,38 @@ class UserControllerTest extends AbstractWebMvcTest {
|
||||
verify(userService).updateDashboardTiles(1L, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFavoritePlatform_StoresOrClearsIt() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(
|
||||
new UserPrincipal("1", "test@example.com", null), null, Collections.emptyList()));
|
||||
|
||||
mockMvc.perform(put("/api/users/settings/favorite-platform")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"platform\":\"PS5\"}"))
|
||||
.andExpect(status().isNoContent());
|
||||
mockMvc.perform(put("/api/users/settings/favorite-platform")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"platform\":null}"))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
verify(userService).updateFavoritePlatform(1L, "PS5");
|
||||
verify(userService).updateFavoritePlatform(1L, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFavoritePlatform_BlankOrTooLong_Is400() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(
|
||||
new UserPrincipal("1", "test@example.com", null), null, Collections.emptyList()));
|
||||
|
||||
for (String platform : List.of(" ", "x".repeat(33))) {
|
||||
mockMvc.perform(put("/api/users/settings/favorite-platform")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"platform\":\"" + platform + "\"}"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
verify(userService, never()).updateFavoritePlatform(anyLong(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProfileTiles_StoresTheTiles() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(
|
||||
|
||||
@@ -330,6 +330,28 @@ class UserRepositoryTest extends AbstractPersistenceTest {
|
||||
assertEquals(profile, saved.getProfileTiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFavoritePlatform_StoresAndClears() {
|
||||
UserEntity userEntity = entityManager.persist(UserEntity.builder()
|
||||
.email("favorite@example.com")
|
||||
.password("password")
|
||||
.enabled(true)
|
||||
.registrationDate(LocalDateTime.now())
|
||||
.build());
|
||||
assertNull(userRepository.findByEmail("favorite@example.com").orElseThrow().getSettings().getFavoritePlatform());
|
||||
|
||||
userRepository.updateFavoritePlatform(userEntity.getId(), "Switch");
|
||||
entityManager.flush();
|
||||
entityManager.clear();
|
||||
assertEquals("Switch", userRepository.findByEmail("favorite@example.com").orElseThrow().getSettings()
|
||||
.getFavoritePlatform());
|
||||
|
||||
userRepository.updateFavoritePlatform(userEntity.getId(), null);
|
||||
entityManager.flush();
|
||||
entityManager.clear();
|
||||
assertNull(userRepository.findByEmail("favorite@example.com").orElseThrow().getSettings().getFavoritePlatform());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateDashboardTiles_NullResetsToTheDefault() {
|
||||
UserEntity userEntity = entityManager.persist(UserEntity.builder()
|
||||
|
||||
Reference in new issue
Block a user