Skip to content

Commit

Permalink
fix: dataElementIdScheme should not filter events [DHIS2-14968] (#19267)
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo authored Nov 23, 2024
1 parent 36d913c commit 857b68b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ lateral jsonb_each(
) as eventdatavalue(dataelement_uid, value)
on true
left join dataelement de on de.uid = eventdatavalue.dataelement_uid
where eventdatavalue.dataelement_uid is not null
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public static void assertIsEmpty(Collection<?> actual) {
assertTrue(actual.isEmpty(), actual.toString());
}

/**
* Asserts that the given collection is not null and empty.
*
* @param actual the collection.
* @param message fails with this message
*/
public static void assertIsEmpty(Collection<?> actual, String message) {
assertNotNull(actual, message);
assertTrue(actual.isEmpty(), message);
}

/**
* Asserts that the given collection is not null and not empty.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static org.hisp.dhis.test.utils.Assertions.assertContains;
import static org.hisp.dhis.test.utils.Assertions.assertContainsOnly;
import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty;
import static org.hisp.dhis.test.utils.Assertions.assertNotEmpty;
import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage;
import static org.junit.jupiter.api.Assertions.assertAll;
Expand Down Expand Up @@ -75,6 +76,7 @@
import org.hisp.dhis.webapi.controller.tracker.JsonEvent;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -149,6 +151,7 @@ void setUpUser() {
@MethodSource(value = "shouldExportMetadataUsingGivenIdSchemeProvider")
void shouldExportMetadataUsingGivenIdScheme(TrackerIdSchemeParam idSchemeParam) {
Event event = get(Event.class, "QRYjLTiJTrA");
assertNotEmpty(event.getEventDataValues(), "test expects an event with data values");

// maps JSON fields to idScheme request parameters
Map<String, String> idSchemeRequestParams =
Expand Down Expand Up @@ -266,6 +269,19 @@ void shouldExportMetadataUsingGivenIdScheme(TrackerIdSchemeParam idSchemeParam)
assertMetadataIdScheme(metadata, actual, idSchemeParam, "event");
}

@Test
void shouldExportEventUsingNonUIDDataElementIdSchemeEvenIfItHasNoDataValues() {
Event event = get(Event.class, "jxgFyJEMUPf");
assertIsEmpty(event.getEventDataValues(), "test expects an event with no data values");

JsonEvent actual =
GET("/tracker/events/{id}?fields=event,dataValues&dataElementIdScheme=NAME", event.getUid())
.content(HttpStatus.OK)
.as(JsonEvent.class);

assertEquals("jxgFyJEMUPf", actual.getEvent());
}

@ParameterizedTest
@ValueSource(strings = {"/{id}?", "?events={id}&paging=true&", "?events={id}&paging=false&"})
void shouldReportMetadataWhichDoesNotHaveAnIdentifierForGivenIdScheme(String urlPortion) {
Expand Down

0 comments on commit 857b68b

Please sign in to comment.