From 06816a3434d470ec4c2d9c8e7c287c7a20e7e532 Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo <113031535+flaminiaScarciofolo@users.noreply.github.com> Date: Fri, 31 May 2024 11:46:26 +0200 Subject: [PATCH] [SELC-4846] Feat: Refactor retrievedIds method (#449) --- .../connector/api/UserApiConnector.java | 2 + .../connector/rest/UserConnectorImpl.java | 16 ++++ .../connector/rest/UserConnectorImplTest.java | 55 ++++++++++-- .../core/UserGroupV2ServiceImpl.java | 3 +- .../core/UserGroupV2ServiceImplTest.java | 88 ++++++++----------- 5 files changed, 105 insertions(+), 59 deletions(-) diff --git a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/api/UserApiConnector.java b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/api/UserApiConnector.java index e8d94a39..a8e799fa 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/api/UserApiConnector.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/api/UserApiConnector.java @@ -33,6 +33,8 @@ public interface UserApiConnector { Collection getUsers(String institutionId, UserInfo.UserInfoFilter userInfoFilter, String loggedUserId); + List retrieveFilteredUserInstitution(String institutionId, UserInfo.UserInfoFilter userInfoFilter, String loggedUserId); + List retrieveFilteredUser(String userId, String institutionId, String productId); String createOrUpdateUserByFiscalCode(Institution institution, String productId, UserToCreate userDto, List role); diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImpl.java index b8369190..80d2dc7c 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImpl.java @@ -179,6 +179,22 @@ public Collection getUsers(String institutionId, UserInfo.UserInfoFilt .orElse(Collections.emptyList()); } + @Override + public List retrieveFilteredUserInstitution(String institutionId, UserInfo.UserInfoFilter userInfoFilter, String loggedUserId) { + + return Optional.ofNullable(userInstitutionApiRestClient._institutionsInstitutionIdUserInstitutionsGet(institutionId, + null, + List.of(userInfoFilter.getProductId()), + null, + Optional.ofNullable(userInfoFilter.getAllowedStates()) + .map(relationshipStates -> relationshipStates.stream().map(Enum::name).toList()) + .orElse(null), + loggedUserId) + .getBody()).map(userInstitutionResponses -> userInstitutionResponses.stream() + .map(UserInstitutionResponse::getUserId).toList()) + .orElse(Collections.emptyList()); + } + @Override @Retry(name = "retryTimeout") public List retrieveFilteredUser(String userId, String institutionId, String productId) { diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java index 96551aff..69fcc057 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java @@ -113,8 +113,7 @@ private static UserInfoResponse getUserProductsResponse() { institutionProducts3.setRole(PartyRole.MANAGER); - - userProductsResponse.setInstitutions(List.of(institutionProducts, institutionProducts2,institutionProducts4, institutionProducts3)); + userProductsResponse.setInstitutions(List.of(institutionProducts, institutionProducts2, institutionProducts4, institutionProducts3)); return userProductsResponse; } @@ -183,6 +182,7 @@ void getUserById() { assertNotNull(user); verify(userApiRestClient, times(1))._usersIdDetailsGet(userId, fields.get(0), institutionId); } + @Test void verifyUserExist_UserExists() { String userId = "userId"; @@ -190,8 +190,8 @@ void verifyUserExist_UserExists() { String productId = "productId"; when(userInstitutionApiRestClient._institutionsInstitutionIdUserInstitutionsGet(eq(institutionId), eq(null), eq(List.of(productId)), eq(null), anyList(), eq(userId))).thenReturn(ResponseEntity.ok(List.of(new UserInstitutionResponse()))); - List response = userConnector.retrieveFilteredUser(userId, institutionId, productId); - assertEquals(1, response.size()); + List response = userConnector.retrieveFilteredUser(userId, institutionId, productId); + assertEquals(1, response.size()); verify(userInstitutionApiRestClient, times(1))._institutionsInstitutionIdUserInstitutionsGet(eq(institutionId), eq(null), eq(List.of(productId)), eq(null), anyList(), eq(userId)); } @@ -265,7 +265,7 @@ void update() { userConnector.updateUser(userId, institutionId, user); // then verify(userApiRestClient, times(1)) - ._usersIdUserRegistryPut(userId, institutionId,new UpdateUserRequest()); + ._usersIdUserRegistryPut(userId, institutionId, new UpdateUserRequest()); verifyNoMoreInteractions(userApiRestClient); } @@ -279,7 +279,7 @@ void getUsers_emptyList() { userInfoFilter.setAllowedStates(List.of(ACTIVE, SUSPENDED)); userInfoFilter.setRole(SelfCareAuthority.ADMIN); - when(userApiRestClient._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED")))) + when(userApiRestClient._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null), eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED")))) .thenReturn(ResponseEntity.ok(Collections.emptyList())); // when @@ -287,7 +287,7 @@ void getUsers_emptyList() { // then assertTrue(result.isEmpty()); - verify(userApiRestClient, times(1))._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED"))); + verify(userApiRestClient, times(1))._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null), eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED"))); verifyNoMoreInteractions(userApiRestClient); } @@ -385,7 +385,7 @@ void testCreateOrUpdateUserByFiscalCode() { institution.setDescription("description"); institution.setRootParent(response); // Act - userConnector.createOrUpdateUserByFiscalCode(institution, "productId", userDto, List.of(role, role2)); + userConnector.createOrUpdateUserByFiscalCode(institution, "productId", userDto, List.of(role, role2)); // Assert that nothing has changed verify(userApiRestClient)._usersPost(Mockito.any()); @@ -419,4 +419,43 @@ void testCreateOrUpdateUserByUserId() { verify(userApiRestClient)._usersUserIdPost(eq("userId"), any()); } + @Test + public void retrieveFilteredUserInstitutionReturnsUserInstitutions() { + // Given + String institutionId = "institutionId"; + UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter(); + userInfoFilter.setAllowedStates(List.of(ACTIVE, SUSPENDED)); + userInfoFilter.setProductId("productId"); + String loggedUserId = "loggedUserId"; + List userInstitutionResponses = List.of(new UserInstitutionResponse(), new UserInstitutionResponse()); + when(userInstitutionApiRestClient._institutionsInstitutionIdUserInstitutionsGet(institutionId, null, List.of(userInfoFilter.getProductId()), null, + userInfoFilter.getAllowedStates().stream().map(Enum::name).toList(), loggedUserId)) + .thenReturn(ResponseEntity.ok(userInstitutionResponses)); + + // When + List result = userConnector.retrieveFilteredUserInstitution(institutionId, userInfoFilter, loggedUserId); + + // Then + assertEquals(userInstitutionResponses.size(), result.size()); + } + + @Test + public void retrieveFilteredUserInstitutionReturnsEmptyListWhenNoUserInstitutions() { + // Given + String institutionId = "institutionId"; + UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter(); + userInfoFilter.setProductId("productId"); + userInfoFilter.setAllowedStates(List.of(ACTIVE, SUSPENDED)); + String loggedUserId = "loggedUserId"; + when(userInstitutionApiRestClient._institutionsInstitutionIdUserInstitutionsGet(institutionId, null, List.of(userInfoFilter.getProductId()), null, + userInfoFilter.getAllowedStates().stream().map(Enum::name).toList(), loggedUserId)) + .thenReturn(ResponseEntity.ok(List.of())); + + // When + List result = userConnector.retrieveFilteredUserInstitution(institutionId, userInfoFilter, loggedUserId); + + // Then + assertEquals(0, result.size()); + } + } diff --git a/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImpl.java index 454b0634..40e658d9 100644 --- a/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImpl.java @@ -85,11 +85,10 @@ public void activate(String groupId) { private List retrievedIds(String institutionId, UserInfo.UserInfoFilter userInfoFilter) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String loggedUserId = ((SelfCareUser) authentication.getPrincipal()).getId(); - Collection retrievedUsers = userApiConnector.getUsers( + List retrievedUsers = userApiConnector.retrieveFilteredUserInstitution( institutionId, userInfoFilter, loggedUserId); return retrievedUsers.stream() - .map(UserInfo::getId) .sorted() .toList(); } diff --git a/core/src/test/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImplTest.java index 6d7f9587..13fcbd67 100644 --- a/core/src/test/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/dashboard/core/UserGroupV2ServiceImplTest.java @@ -56,7 +56,7 @@ class UserGroupV2ServiceImplTest { @Test void createGroup() { Authentication authentication = mock(Authentication.class); - when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("loggedUserId").build()); + when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("setId").build()); SecurityContextHolder.getContext().setAuthentication(authentication); //given CreateUserGroup userGroup = mockInstance(new CreateUserGroup()); @@ -79,9 +79,8 @@ void createGroup() { when(userGroupConnector.createUserGroup(any())) .thenReturn(groupIdMock); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); - //when + when(userApiConnector.retrieveFilteredUserInstitution(anyString(), any(), any())) + .thenReturn(List.of(id1, id2, id3, id4)); //when String groupId = userV2GroupServiceImpl.createUserGroup(userGroup); //then assertEquals(groupIdMock, groupId); @@ -89,7 +88,7 @@ void createGroup() { .createUserGroup(any()); ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(userGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(userGroup.getInstitutionId()), filterCaptor.capture(), eq("setId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -122,16 +121,15 @@ void createGroup_invalidList() { userInfoMock3.setId(id3); userInfoMock4.setId(id4); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); - //when + when(userApiConnector.retrieveFilteredUserInstitution(eq(userGroup.getInstitutionId()), any(), eq("loggedUserId"))) + .thenReturn(List.of("setId", "setId", "setId", "setId")); //when Executable executable = () -> userV2GroupServiceImpl.createUserGroup(userGroup); //then InvalidMemberListException e = assertThrows(InvalidMemberListException.class, executable); assertEquals("Some members in the list aren't allowed for this institution", e.getMessage()); ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(userGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(userGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -229,24 +227,23 @@ void updateUserGroup() { List userIds = List.of(id1, id2, id3, id4); userGroup.setMembers(userIds); - UserGroupInfo foundGroup = mockInstance(new UserGroupInfo(), "setId"); + UserGroupInfo foundGroup = mockInstance(new UserGroupInfo(), "loggedUserId"); foundGroup.setId(groupId); when(userGroupConnector.getUserGroupById(anyString())) .thenReturn(foundGroup); - UserInfo userInfoMock1 = mockInstance(new UserInfo(), 1, "setId"); - UserInfo userInfoMock2 = mockInstance(new UserInfo(), 2, "setId"); - UserInfo userInfoMock3 = mockInstance(new UserInfo(), 3, "setId"); - UserInfo userInfoMock4 = mockInstance(new UserInfo(), 4, "setId"); + UserInfo userInfoMock1 = mockInstance(new UserInfo(), 1, "loggedUserId"); + UserInfo userInfoMock2 = mockInstance(new UserInfo(), 2, "loggedUserId"); + UserInfo userInfoMock3 = mockInstance(new UserInfo(), 3, "loggedUserId"); + UserInfo userInfoMock4 = mockInstance(new UserInfo(), 4, "loggedUserId"); userInfoMock1.setId(id1); userInfoMock2.setId(id2); userInfoMock3.setId(id3); userInfoMock4.setId(id4); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); - //when + when(userApiConnector.retrieveFilteredUserInstitution(anyString(), any(), any())) + .thenReturn(List.of(id1, id2, id3, id4)); //when Executable executable = () -> userV2GroupServiceImpl.updateUserGroup(groupId, userGroup); //then assertDoesNotThrow(executable); @@ -255,7 +252,7 @@ void updateUserGroup() { ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(foundGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(foundGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -297,9 +294,8 @@ void updateUserGroup_invalidMembersList() { userInfoMock3.setId(id3); userInfoMock4.setId(id4); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); - //when + when(userApiConnector.retrieveFilteredUserInstitution(eq(foundGroup.getInstitutionId()), any(), eq("loggedUserId"))) + .thenReturn(List.of("setId", "setId", "setId", "setId")); //when Executable executable = () -> userV2GroupServiceImpl.updateUserGroup(groupId, userGroup); //then InvalidMemberListException e = assertThrows(InvalidMemberListException.class, executable); @@ -307,7 +303,7 @@ void updateUserGroup_invalidMembersList() { ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(foundGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(foundGroup.getInstitutionId()), filterCaptor.capture(), eq("loggedUserId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -346,8 +342,10 @@ void testDeleteMembersByUserIdUserFound() { @Test void addMemberToUserGroup() { + UUID userId = randomUUID(); + Authentication authentication = mock(Authentication.class); - when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("loggedUserId").build()); + when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder(userId.toString()).build()); SecurityContextHolder.getContext().setAuthentication(authentication); //given String groupId = "groupId"; @@ -355,7 +353,6 @@ void addMemberToUserGroup() { String productId = "productId"; UserGroupInfo foundGroup = mockInstance(new UserGroupInfo(), "setId", "setInstitutionId"); foundGroup.setId(groupId); - UUID userId = randomUUID(); String id2 = randomUUID().toString(); String id3 = randomUUID().toString(); String id4 = randomUUID().toString(); @@ -369,8 +366,6 @@ void addMemberToUserGroup() { userInfoMock3.setId(id3); userInfoMock4.setId(id4); - List members = List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4); - foundGroup.setMembers(List.of(userInfoMock2, userInfoMock3, userInfoMock4)); foundGroup.setCreatedAt(Instant.now()); foundGroup.setModifiedAt(Instant.now()); @@ -380,9 +375,8 @@ void addMemberToUserGroup() { when(userGroupConnector.getUserGroupById(anyString())) .thenReturn(foundGroup); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(members); - //when + when(userApiConnector.retrieveFilteredUserInstitution(eq(institutionId), any(), eq(userId.toString()))) + .thenReturn(List.of(userId.toString(), "setId", "setId", "setId")); //when Executable executable = () -> userV2GroupServiceImpl.addMemberToUserGroup(groupId, userId); //then assertDoesNotThrow(executable); @@ -392,7 +386,7 @@ void addMemberToUserGroup() { .getUserGroupById(groupId); ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(institutionId), filterCaptor.capture(), eq(userId.toString())); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -429,8 +423,6 @@ void addMemberToUserGroup_invalidMember() { userInfoMock3.setId(id3); userInfoMock4.setId(id4); - List members = List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4); - foundGroup.setMembers(List.of(userInfoMock2, userInfoMock3, userInfoMock4)); foundGroup.setCreatedAt(Instant.now()); foundGroup.setModifiedAt(Instant.now()); @@ -440,9 +432,9 @@ void addMemberToUserGroup_invalidMember() { when(userGroupConnector.getUserGroupById(anyString())) .thenReturn(foundGroup); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(members); - //when + when(userApiConnector.retrieveFilteredUserInstitution(eq(institutionId), any(), eq("loggedUserId"))) + .thenReturn(List.of("setId", "setId", "setId", "setId")); + Executable executable = () -> userV2GroupServiceImpl.addMemberToUserGroup(groupId, userId); //then InvalidMemberListException e = assertThrows(InvalidMemberListException.class, executable); @@ -451,7 +443,7 @@ void addMemberToUserGroup_invalidMember() { .getUserGroupById(groupId); ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -551,7 +543,7 @@ void getUserGroups() { @Test void getUserGroupById() { Authentication authentication = mock(Authentication.class); - when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("loggedUserId").build()); + when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("setId").build()); SecurityContextHolder.getContext().setAuthentication(authentication); //given String groupId = "groupId"; @@ -574,10 +566,8 @@ void getUserGroupById() { List members = List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); - - foundGroup.setMembers(members); + when(userApiConnector.retrieveFilteredUserInstitution(anyString(), any(), any())) + .thenReturn(List.of("setId", "setId", "setId", "setId")); foundGroup.setMembers(members); foundGroup.setCreatedAt(Instant.now()); foundGroup.setModifiedAt(Instant.now()); foundGroup.setInstitutionId(institutionId); @@ -625,12 +615,12 @@ void getUserGroupById() { assertEquals(modifiedByMock.getId(), groupInfo.getModifiedBy().getId()); verify(userGroupConnector, times(1)) .getUserGroupById(anyString()); - verify(userApiConnector, times(6)) + verify(userApiConnector, times(2)) .getUserById(any(), any(),anyList()); ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(institutionId), filterCaptor.capture(), eq("setId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles()); @@ -666,8 +656,8 @@ void getUserGroupById_nullModifiedBy() { List members = List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4); - when(userApiConnector.getUsers(anyString(), any(), any())) - .thenReturn(List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4)); + when(userApiConnector.retrieveFilteredUserInstitution(anyString(), any(), any())) + .thenReturn(List.of("setId", "setId", "setId", "setId")); foundGroup.setMembers(members); foundGroup.setCreatedAt(Instant.now()); @@ -737,8 +727,8 @@ void getUserGroupById_noRelationshipMember() { List members = List.of(userInfoMock1, userInfoMock2, userInfoMock3, userInfoMock4); - when(userApiConnector.getUsers(any(), any(), any())) - .thenReturn(List.of(userInfoMock4)); + when(userApiConnector.retrieveFilteredUserInstitution(anyString(), any(), any())) + .thenReturn(List.of(id1, id2, id3, id4)); when(userApiConnector.getUserById(anyString(), any(), any())) .thenAnswer(invocation -> { User userMock = new User(); @@ -779,7 +769,7 @@ void getUserGroupById_noRelationshipMember() { assertEquals(foundGroup.getStatus(), groupInfo.getStatus()); assertEquals(foundGroup.getDescription(), groupInfo.getDescription()); assertEquals(foundGroup.getName(), groupInfo.getName()); - assertEquals(1, groupInfo.getMembers().size()); + assertEquals(4, groupInfo.getMembers().size()); assertEquals(foundGroup.getCreatedAt(), groupInfo.getCreatedAt()); assertEquals(createdByMock.getId(), groupInfo.getCreatedBy().getId()); assertEquals(foundGroup.getModifiedAt(), groupInfo.getModifiedAt()); @@ -789,7 +779,7 @@ void getUserGroupById_noRelationshipMember() { ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(UserInfo.UserInfoFilter.class); verify(userApiConnector, times(1)) - .getUsers(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); + .retrieveFilteredUserInstitution(eq(institutionId), filterCaptor.capture(), eq("loggedUserId")); UserInfo.UserInfoFilter capturedFilter = filterCaptor.getValue(); assertNull(capturedFilter.getUserId()); assertNull(capturedFilter.getProductRoles());