Skip to content

Commit

Permalink
fix: allow empty data when saving diff data/state data (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras authored May 27, 2024
1 parent fc4962f commit 9765e0d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>Modules for queen back-office</description>

<properties>
<revision>4.3.1</revision>
<revision>4.3.2</revision>
<changelist></changelist>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

@Schema(name = "SurveyUnitDataStateDataUpdate")
public record SurveyUnitDataStateDataUpdateInput(
@NotNull
@Schema(ref = SchemaType.Names.COLLECTED_DATA)
@JsonValid(SchemaType.COLLECTED_DATA)
ObjectNode data,
Expand Down
1 change: 0 additions & 1 deletion queen-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<configuration>
<rules>
<bannedDependencies>
<!-- will only display a warning but does not fail the build. -->
<level>ERROR</level>
<excludes>
<exclude>fr.insee.queen:*</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ public void updateSurveyUnit(SurveyUnit surveyUnit) {
@Transactional
@Override
public void updateSurveyUnit(String surveyUnitId, ObjectNode collectedDataToUpdate, StateData stateData) {
dataService.updateCollectedData(surveyUnitId, collectedDataToUpdate);
if(collectedDataToUpdate != null && ! collectedDataToUpdate.isEmpty()) {
dataService.updateCollectedData(surveyUnitId, collectedDataToUpdate);
}

try {
stateDataService.saveStateData(surveyUnitId, stateData);
} catch (StateDataInvalidDateException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;

import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -159,12 +163,24 @@ void testUpdate04() {
assertThat(surveyUnitFakeDao.getSurveyUnitUpdated()).isEqualTo(surveyUnit);
assertThat(stateDataFakeService.getStateDataSaved()).isNull();
}
@ParameterizedTest
@MethodSource("nullOrEmpTyData")
@DisplayName("On updating survey unit, when data is null or empty, don't update data")
void testUpdateDataStateData02(ObjectNode data) {
StateData stateData = new StateData(StateDataType.VALIDATED, 800000L, "5");
String surveyUnitId = "11";
surveyUnitApiService.updateSurveyUnit(surveyUnitId, data, stateData);
assertThat(stateDataFakeService.getStateDataSaved()).isEqualTo(stateData);
assertThat(dataFakeService.getDataSaved()).isNull();
}


@Test
@DisplayName("On updating survey unit, when state data is not null, save it")
void testUpdateDataStateData02() {
void testUpdateDataStateData03() {
StateData stateData = new StateData(StateDataType.VALIDATED, 800000L, "5");
ObjectNode data = JsonNodeFactory.instance.objectNode();
data.put("field1", 5);
String surveyUnitId = "11";
surveyUnitApiService.updateSurveyUnit(surveyUnitId, data, stateData);
assertThat(stateDataFakeService.getStateDataSaved()).isEqualTo(stateData);
Expand All @@ -173,12 +189,17 @@ void testUpdateDataStateData02() {

@Test
@DisplayName("On updating survey unit, when state data update throws an invalid date exception, check data is saved ")
void testUpdateDataStateData03() {
void testUpdateDataStateData04() {
StateData stateData = new StateData(StateDataType.VALIDATED, 800000L, "5");
ObjectNode data = JsonNodeFactory.instance.objectNode();
data.put("field1", 5);
String surveyUnitId = "11";
stateDataFakeService.setDateInvalid(true);
surveyUnitApiService.updateSurveyUnit(surveyUnitId, data, stateData);
assertThat(dataFakeService.getDataSaved()).isEqualTo(data);
}

static Stream<ObjectNode> nullOrEmpTyData() {
return Stream.of(null, JsonNodeFactory.instance.objectNode());
}
}

0 comments on commit 9765e0d

Please sign in to comment.