fix(api): handle null AppSettingEntity value (#2698)
This commit is contained in:
@@ -203,6 +203,7 @@ public class AppSettingService {
|
||||
|
||||
Map<String, String> loadedSettings = appSettingsRepository.findAll()
|
||||
.stream()
|
||||
.filter(e -> e.getVal() != null)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
AppSettingEntity::getName,
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.booklore.model.enums.AuditAction;
|
||||
import org.booklore.repository.AppSettingsRepository;
|
||||
import org.booklore.service.audit.AuditService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -45,6 +46,8 @@ class AppSettingServiceTest {
|
||||
@InjectMocks
|
||||
private AppSettingService appSettingService;
|
||||
|
||||
@Nested
|
||||
class UpdateSetting {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
var permissions = new BookLoreUser.UserPermissions();
|
||||
@@ -167,3 +170,15 @@ class AppSettingServiceTest {
|
||||
verify(appSettingsRepository, never()).save(any());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAppSettings_handlesNullSettingValues() {
|
||||
when(appProperties.getRemoteAuth()).thenReturn(new AppProperties.RemoteAuth());
|
||||
|
||||
var setting = new AppSettingEntity();
|
||||
setting.setName("test");
|
||||
setting.setVal(null);
|
||||
when(appSettingsRepository.findAll()).thenReturn(List.of(setting));
|
||||
assertThat(appSettingService.getAppSettings()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user