Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dataElementIdScheme should not filter events DHIS2-14968 #19267

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -127,6 +127,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
Loading