|
15 | 15 | import org.mockito.Mock; |
16 | 16 | import org.mockito.junit.jupiter.MockitoExtension; |
17 | 17 |
|
| 18 | +import java.math.BigInteger; |
18 | 19 | import java.util.List; |
19 | 20 |
|
20 | 21 | import static fr.insee.pogues.utils.Utils.loadQuestionnaireFromResources; |
21 | 22 | import static fr.insee.pogues.utils.json.JSONFunctions.jsonStringtoJsonNode; |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
22 | 24 | import static org.junit.jupiter.api.Assertions.*; |
23 | 25 |
|
24 | 26 | @ExtendWith(MockitoExtension.class) |
@@ -57,6 +59,36 @@ void getQuestionnaireVariables_success() throws Exception { |
57 | 59 | assertEquals(expected.getId(), res.getFirst().getId()); |
58 | 60 | } |
59 | 61 |
|
| 62 | + @Test |
| 63 | + @DisplayName("Should fetch questionnaire variables and compute the scope name") |
| 64 | + void getQuestionnaireVariables_success_scopeName() throws Exception { |
| 65 | + // Given a questionnaire with 1 variable |
| 66 | + Questionnaire mockQuestionnaire = loadQuestionnaireFromResources("service/withScope.json"); |
| 67 | + String mockQuestionnaireString = PoguesSerializer.questionnaireJavaToString(mockQuestionnaire); |
| 68 | + JsonNode mockQuestionnaireJSON = jsonStringtoJsonNode(mockQuestionnaireString); |
| 69 | + questionnaireService.createQuestionnaire(mockQuestionnaireJSON); |
| 70 | + |
| 71 | + String questionnaireId = "ma0nzzmj"; |
| 72 | + String variableId = "mdy51s3x"; |
| 73 | + |
| 74 | + VariableType expected = new CollectedVariableType(); |
| 75 | + expected.setId(variableId); |
| 76 | + expected.setName("NOMDUPOKEM"); |
| 77 | + expected.setLabel("NOMDUPOKEM label"); |
| 78 | + expected.setScope("LOOP_TEST"); |
| 79 | + TextDatatypeType expectedDatatype = new TextDatatypeType(); |
| 80 | + expectedDatatype.setTypeName(DatatypeTypeEnum.TEXT); |
| 81 | + expectedDatatype.setMaxLength(BigInteger.valueOf(249)); |
| 82 | + expected.setDatatype(expectedDatatype); |
| 83 | + |
| 84 | + // When we get the questionnaire's variables |
| 85 | + List<VariableType> res = variableService.getQuestionnaireVariables(questionnaireId); |
| 86 | + |
| 87 | + // Then the variable is fetched |
| 88 | + VariableType variable = res.stream().filter(v -> variableId.equals(v.getId())).toList().getFirst(); |
| 89 | + assertThat(variable).usingRecursiveComparison().isEqualTo(expected); |
| 90 | + } |
| 91 | + |
60 | 92 | @Test |
61 | 93 | @DisplayName("Should trigger an error when we try to fetch variables from a questionnaire that does not exist") |
62 | 94 | void getQuestionnaireVariables_error_questionnaireNotFound() { |
|
0 commit comments