From 347926ce64a65b5f98e28fef1256d2bfffbd3329 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Mon, 1 Jul 2024 11:50:54 +0200 Subject: [PATCH] feat: add tests for posting and retrieving datasets display options --- .../DataSetMetadataControllerTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java index a63fa554c92e..30261e4de245 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java @@ -36,6 +36,7 @@ import org.hisp.dhis.web.WebClient; import org.hisp.dhis.webapi.DhisControllerIntegrationTest; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -70,6 +71,37 @@ void getDatasetMetadataDefaultCatComboTest( assertEquals(expectedDefaultCatComboCount, count, defaultCatComboCondition); } + @Test + @DisplayName("Dataset display options are correctly saved and retrieved") + void getDatasetMetadataDisplayOptionsTest() { + String expectedDisplayOptions = "{\"aDisplay\": \"option\"}"; + String dataSetsBody = + """ + { + "dataSets": [ + { + "name": "hellobrenda", + "shortName": "hellobrenda", + "periodType": "Daily", + "displayOptions": "{\\"aDisplay\\": \\"option\\"}" + } + ] + } + """; + + // given + POST("/metadata", WebClient.Body(dataSetsBody)).content(HttpStatus.OK); + + // when the data entry metadata is retrieves + JsonObject dataEntryMetadata = GET("/dataEntry/metadata").content(); + JsonArray dataSets = dataEntryMetadata.getArray("dataSets"); + String actualDisplayOptions = dataSets.getObject(0).getString("displayOptions").string(); + + // then + assertEquals(1, dataSets.size()); + assertEquals(expectedDisplayOptions, actualDisplayOptions); + } + private static Stream defaultCatComboData() { return Stream.of( Arguments.of(