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()
|
Map<String, String> loadedSettings = appSettingsRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
|
.filter(e -> e.getVal() != null)
|
||||||
.collect(
|
.collect(
|
||||||
Collectors.toMap(
|
Collectors.toMap(
|
||||||
AppSettingEntity::getName,
|
AppSettingEntity::getName,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.booklore.model.enums.AuditAction;
|
|||||||
import org.booklore.repository.AppSettingsRepository;
|
import org.booklore.repository.AppSettingsRepository;
|
||||||
import org.booklore.service.audit.AuditService;
|
import org.booklore.service.audit.AuditService;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -45,6 +46,8 @@ class AppSettingServiceTest {
|
|||||||
@InjectMocks
|
@InjectMocks
|
||||||
private AppSettingService appSettingService;
|
private AppSettingService appSettingService;
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class UpdateSetting {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
var permissions = new BookLoreUser.UserPermissions();
|
var permissions = new BookLoreUser.UserPermissions();
|
||||||
@@ -166,4 +169,16 @@ class AppSettingServiceTest {
|
|||||||
|
|
||||||
verify(appSettingsRepository, never()).save(any());
|
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