Skip to content

Commit

Permalink
feat: add tests for posting and retrieving datasets display options
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaminia Cavallo authored and Flaminia Cavallo committed Jul 1, 2024
1 parent cf7e884 commit 0d6ded1
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.stream.Stream;

import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.jsontree.JsonArray;
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.jsontree.JsonString;
import org.hisp.dhis.web.HttpStatus;
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;
Expand Down Expand Up @@ -70,6 +74,42 @@ 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<Arguments> defaultCatComboData() {
return Stream.of(
Arguments.of(
Expand Down

0 comments on commit 0d6ded1

Please sign in to comment.