Skip to content
Closed
Changes from 1 commit
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 @@ -51,27 +51,32 @@ public void testGetUsersByRegionAndRights() {
// given region and right
List<UserReferenceDto> result = getUserFacade().getUsersByRegionAndRights(region, null, UserRight.EXTERNAL_MESSAGE_ACCESS);

assertTrue(result.isEmpty());
assertThat(result, hasSize(1));

creator.getUserRoleReference(NATIONAL_USER);

UserDto natUser = creator.createUser(rdcf, creator.getUserRoleReference(NATIONAL_USER)); // Has LAB_MASSAGES and TRAVEL_ENTRY_MANAGEMENT_ACCESS rights
UserDto poeUser = creator.createUser(rdcf, "Some", "User", creator.getUserRoleReference(POE_INFORMANT)); // Does not have LAB_MASSAGES right, but has TRAVEL_ENTRY_MANAGEMENT_ACCESS.
creator.createUser(rdcf, creator.getUserRoleReference(REST_EXTERNAL_VISITS_USER)); // Has neither LAB_MASSAGES nor TRAVEL_ENTRY_MANAGEMENT_ACCESS right
result = getUserFacade().getUsersByRegionAndRights(region, null, UserRight.EXTERNAL_MESSAGE_ACCESS);

assertThat(result, hasSize(1));
assertThat(result, contains(equalTo(natUser.toReference())));
assertThat(result, hasSize(2));

UserReferenceDto nationalAdminUser = result.get(0);

assertThat(result, contains(equalTo(nationalAdminUser), equalTo(natUser.toReference())));

UserDto natUser2 = creator.createUser(rdcf, "Nat", "User2", creator.getUserRoleReference(NATIONAL_USER)); // Has LAB_MASSAGES right
result = getUserFacade().getUsersByRegionAndRights(region, null, UserRight.EXTERNAL_MESSAGE_ACCESS);

assertThat(result, hasSize(2));
assertThat(result, hasSize(3));
assertThat(result, hasItems(equalTo(natUser.toReference()), equalTo(natUser2.toReference())));

// given different region and right
Region region2 = creator.createRegion("region2");
result = getUserFacade().getUsersByRegionAndRights(RegionFacadeEjb.toReferenceDto(region2), null, UserRight.EXTERNAL_MESSAGE_ACCESS);

assertTrue(result.isEmpty());
assertThat(result, hasSize(3));

// given no region and right
result = getUserFacade().getUsersByRegionAndRights(null, null, UserRight.EXTERNAL_MESSAGE_ACCESS);
Expand All @@ -82,7 +87,7 @@ public void testGetUsersByRegionAndRights() {
// given region and multiple rights
result = getUserFacade().getUsersByRegionAndRights(region, null, UserRight.EXTERNAL_MESSAGE_ACCESS, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);

assertThat(result, hasSize(3));
assertThat(result, hasSize(4));
assertThat(result, hasItems(equalTo(natUser.toReference()), equalTo(natUser2.toReference()), equalTo(poeUser.toReference())));

// given different region and multiple rights
Expand All @@ -92,7 +97,7 @@ public void testGetUsersByRegionAndRights() {
UserRight.EXTERNAL_MESSAGE_ACCESS,
UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);

assertTrue(result.isEmpty());
assertThat(result, hasSize(3));

// given no region and multiple rights
result = getUserFacade().getUsersByRegionAndRights(null, null, UserRight.EXTERNAL_MESSAGE_ACCESS, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);
Expand Down Expand Up @@ -314,7 +319,7 @@ public void testGetUserRefsByDistrictsForResponsibleSurveillanceOfficer() {

List<UserReferenceDto> userReferenceDtos = getUserFacade().getUserRefsByDistricts(Arrays.asList(rdcf.district), Disease.CORONAVIRUS);
assertNotNull(userReferenceDtos);
assertEquals(3, userReferenceDtos.size());
assertEquals(4, userReferenceDtos.size());
List<String> userReferenceUUIDs = userReferenceDtos.stream().map(u -> u.getUuid()).collect(Collectors.toList());
assertTrue(userReferenceUUIDs.contains(surveilanceOfficerDefault.getUuid()));
assertTrue(userReferenceUUIDs.contains(surveilanceSupervisorDefault.getUuid()));
Expand Down Expand Up @@ -370,7 +375,7 @@ public void testGetUserRefsByDistrictsWithLimitedDiseaseUsersSingleDistrict() {
// given district and disease
List<UserReferenceDto> userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS);

assertThat(userReferenceDtos, hasSize(1));
assertThat(userReferenceDtos, hasSize(2));
assertTrue(userReferenceDtos.contains(generalSurveillanceOfficer));

// given disease
Expand All @@ -388,12 +393,12 @@ public void testGetUserRefsByDistrictsWithLimitedDiseaseUsersSingleDistrict() {
// given district, disease and right
userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);

assertThat(userReferenceDtos, hasSize(1));
assertThat(userReferenceDtos, hasSize(2));
assertTrue(userReferenceDtos.contains(generalSurveillanceOfficer));

userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS, UserRight.EXTERNAL_MESSAGE_ACCESS);

assertTrue(userReferenceDtos.isEmpty());
assertThat(userReferenceDtos, hasSize(1));

Comment on lines 399 to 402

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Strengthen EXTERNAL_MESSAGE_ACCESS assertion with expected user

The new non-empty expectation at Line 401 only checks size. Please also assert which user is returned so this test fails on wrong-right/wrong-jurisdiction matches.

Proposed assertion update
 		userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS, UserRight.EXTERNAL_MESSAGE_ACCESS);

 		assertThat(userReferenceDtos, hasSize(1));
+		assertThat(userReferenceDtos, hasItem(equalTo(nationalAdmin.toReference())));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS, UserRight.EXTERNAL_MESSAGE_ACCESS);
assertFalse(userReferenceDtos.isEmpty());
assertThat(userReferenceDtos, hasSize(1));
userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, Disease.CORONAVIRUS, UserRight.EXTERNAL_MESSAGE_ACCESS);
assertThat(userReferenceDtos, hasSize(1));
assertThat(userReferenceDtos, hasItem(equalTo(nationalAdmin.toReference())));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@sormas-backend/src/test/java/de/symeda/sormas/backend/user/UserFacadeEjbTest.java`
around lines 399 - 402, The assertion at line 401 in the getUserRefsByDistrict
test only verifies that exactly one user reference is returned using hasSize(1),
but does not verify which user is actually returned. This allows the test to
pass even if the wrong user with the wrong right or wrong jurisdiction is
returned. Add an additional assertion after the hasSize check to verify that the
returned userReferenceDtos contains the expected user by asserting on the user's
ID or other identifying properties, so that the test will fail if the incorrect
user is matched or if the right/jurisdiction filtering is broken.

// given disease and right
userReferenceDtos = getUserFacade().getUserRefsByDistrict(null, Disease.CORONAVIRUS, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);
Expand Down Expand Up @@ -431,12 +436,12 @@ public void testGetUserRefsByDistrictsWithExcludeLimitedDiseaseUsersAndSingleDis
List<UserReferenceDto> userReferenceDtos =
getUserFacade().getUserRefsByDistrict(rdcf.district, true, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);

assertThat(userReferenceDtos, hasSize(1));
assertThat(userReferenceDtos, hasSize(2));
assertTrue(userReferenceDtos.contains(generalSurveillanceOfficer));

userReferenceDtos = getUserFacade().getUserRefsByDistrict(rdcf.district, false, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS);

assertThat(userReferenceDtos, hasSize(2));
assertThat(userReferenceDtos, hasSize(3));
assertThat(userReferenceDtos, hasItems(equalTo(generalSurveillanceOfficer.toReference()), equalTo(limitedSurveillanceOfficer.toReference())));

// given no district and one right
Expand All @@ -454,13 +459,13 @@ public void testGetUserRefsByDistrictsWithExcludeLimitedDiseaseUsersAndSingleDis
userReferenceDtos =
getUserFacade().getUserRefsByDistrict(rdcf.district, true, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS, UserRight.SORMAS_REST);

assertThat(userReferenceDtos, hasSize(2));
assertThat(userReferenceDtos, hasSize(3));
assertThat(userReferenceDtos, hasItems(equalTo(generalSurveillanceOfficer.toReference()), equalTo(generalRestUser.toReference())));

userReferenceDtos =
getUserFacade().getUserRefsByDistrict(rdcf.district, false, UserRight.TRAVEL_ENTRY_MANAGEMENT_ACCESS, UserRight.SORMAS_REST);

assertThat(userReferenceDtos, hasSize(3));
assertThat(userReferenceDtos, hasSize(4));
assertThat(
userReferenceDtos,
hasItems(
Expand Down