Skip to content

Conversation

@alexisszmundy
Copy link
Contributor

No description provided.

Comment on lines +247 to +277
VariablesMap variablesMap = new VariablesMap();
MetadataModel metadataModel = new MetadataModel();
metadataModel.setVariables(variablesMap);

List<RawResponse> rawResponses = new ArrayList<>();
RawResponse rawResponse = new RawResponse(
null,
TestConstants.DEFAULT_INTERROGATION_ID,
TestConstants.DEFAULT_COLLECTION_INSTRUMENT_ID,
Mode.WEB,
new HashMap<>(),
LocalDateTime.now(),
null
);
rawResponse.payload().put("validationDate", "not a validation date");
rawResponse.payload().put("questionnaireState", RawResponseDto.QuestionnaireStateEnum.FINISHED);
rawResponse.payload().put("usualSurveyUnitId", TestConstants.DEFAULT_SURVEY_UNIT_ID);
rawResponse.payload().put("majorModelVersion", 2);
Map<String, Map<String, Map<String, String>>> dataMap = new HashMap<>();
dataMap.put("COLLECTED", new HashMap<>());
dataMap.get("COLLECTED").put("VAR1", new HashMap<>());
dataMap.get("COLLECTED").get("VAR1").put("COLLECTED", "value");
rawResponse.payload().put("data", dataMap);
rawResponses.add(rawResponse);

//Mocks behaviour
doReturn(Collections.singletonList(Mode.WEB)).when(controllerUtils).getModesList(any(),any());
doReturn(Set.of(TestConstants.DEFAULT_INTERROGATION_ID))
.when(rawResponsePersistencePort).findUnprocessedInterrogationIdsByCollectionInstrumentId(any());
doReturn(metadataModel).when(metadataService).loadAndSaveIfNotExists(any(), any(), any(), any(), any());
doReturn(rawResponses).when(rawResponsePersistencePort).findRawResponses(any(), any(), any());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: the RawResponse setup and mocks are repeated in several given methods.
Extracting a small helper could simplify the tests and make the variations (questionnaireState, validationDate) clearer.
@alexisszmundy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants