Skip to content

Commit ba959a6

Browse files
committed
test: add iteration to lunatic raw IT
1 parent 1db3506 commit ba959a6

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

src/test/java/fr/insee/genesis/controller/rest/responses/RawResponseControllerIT.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,91 @@ void processLunaticJsonRawData_keep_null_test(boolean isNullSurveyUnitValues){
986986
Assertions.assertThat(variableDocument.getValue()).isNull();
987987
}
988988

989+
@ParameterizedTest
990+
@ValueSource(booleans = {false, true})
991+
@WithMockUser(roles = "SCHEDULER")
992+
@DisplayName("Old model raw data null values should be added if iterations already exists")
993+
@SneakyThrows
994+
void processLunaticJsonRawData_add_null_iterations_test(boolean isNullSurveyUnitValues){
995+
//GIVEN
996+
String questionnaireId = "TESTQUEST";
997+
Mode mode = Mode.WEB;
998+
999+
List<String> interrogationIds = List.of("INTERRO1");
1000+
1001+
String variableName = "VAR1";
1002+
String collectedValue = "value1";
1003+
Map<String, String> collectedVariablesAndValues = new HashMap<>();
1004+
collectedVariablesAndValues.put(variableName, collectedValue);
1005+
1006+
String externalVariableName = "EXTVAR1";
1007+
String externalValue = "externalvalue1";
1008+
Map<String, String> externalVariablesAndValues = new HashMap<>();
1009+
externalVariablesAndValues.put(externalVariableName, externalValue);
1010+
1011+
setOldModelTestMockBehaviour(
1012+
questionnaireId,
1013+
mode,
1014+
interrogationIds,
1015+
collectedVariablesAndValues,
1016+
externalVariablesAndValues,
1017+
true
1018+
);
1019+
1020+
//Survey unit that already exists for first interrogation
1021+
SurveyUnitDocument alreadyPresentSurveyUnitDocument = getSurveyUnitDocumentWithIterations(
1022+
questionnaireId,
1023+
interrogationIds.getFirst(),
1024+
variableName,
1025+
isNullSurveyUnitValues ? null : collectedValue,
1026+
externalVariableName,
1027+
isNullSurveyUnitValues ? null : externalValue
1028+
);
1029+
when(surveyUnitMongoDBRepository.findByCollectionInstrumentIdAndInterrogationIds(questionnaireId, interrogationIds))
1030+
.thenReturn(List.of(alreadyPresentSurveyUnitDocument));
1031+
1032+
// WHEN
1033+
mockMvc.perform(post("/responses/raw/lunatic-json/%s/process".formatted(questionnaireId))
1034+
.with(csrf())
1035+
.contentType(MediaType.APPLICATION_JSON))
1036+
.andExpect(status().isOk());
1037+
1038+
//THEN
1039+
@SuppressWarnings("unchecked")
1040+
ArgumentCaptor<List<SurveyUnitDocument>> listArgumentCaptor =
1041+
ArgumentCaptor.forClass(List.class);
1042+
verify(surveyUnitMongoDBRepository, times(1))
1043+
.insert(listArgumentCaptor.capture());
1044+
1045+
//Document must have null variables values
1046+
List<SurveyUnitDocument> savedDocuments = listArgumentCaptor.getValue();
1047+
Assertions.assertThat(savedDocuments).isNotNull().hasSize(interrogationIds.size());
1048+
SurveyUnitDocument savedDocument = savedDocuments.stream().filter(
1049+
surveyUnitDocument ->
1050+
surveyUnitDocument.getInterrogationId().equals(interrogationIds.getFirst()))
1051+
.toList().getFirst();
1052+
1053+
Assertions.assertThat(savedDocument.getCollectedVariables())
1054+
.isNotNull()
1055+
.hasSize(3)
1056+
.allSatisfy(v -> {
1057+
assertThat(v.getVarId()).isEqualTo(variableName);
1058+
assertThat(v.getValue()).isNull();
1059+
})
1060+
.extracting(VariableDocument::getIteration)
1061+
.containsExactlyInAnyOrder(1, 2, 3);
1062+
1063+
Assertions.assertThat(savedDocument.getExternalVariables())
1064+
.isNotNull()
1065+
.hasSize(3)
1066+
.allSatisfy(v -> {
1067+
assertThat(v.getVarId()).isEqualTo(externalVariableName);
1068+
assertThat(v.getValue()).isNull();
1069+
})
1070+
.extracting(VariableDocument::getIteration)
1071+
.containsExactlyInAnyOrder(1, 2, 3);
1072+
}
1073+
9891074
@Test
9901075
@WithMockUser(roles = "SCHEDULER")
9911076
@DisplayName("Old model raw data null values should be kept if non null value already exists")

0 commit comments

Comments
 (0)