refactor(组织管理): 增加组织列表的测试覆盖率

This commit is contained in:
guoyuqi 2023-09-05 15:01:44 +08:00 committed by 刘瑞斌
parent 2646bf82aa
commit 43394a1b28
2 changed files with 16 additions and 9 deletions

View File

@ -299,12 +299,10 @@ public class OrganizationService {
}
Set<String> userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId());
if (CollectionUtils.isNotEmpty(userRoleIds)){
List<UserRole> userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList();
List<IdNameStructureDTO> userRoleList = new ArrayList<>();
setUserRoleList(userRoleList, userRoleFilters);
orgUserExtend.setUserRoleIdNameMap(userRoleList);
}
List<UserRole> userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList();
List<IdNameStructureDTO> userRoleList = new ArrayList<>();
setUserRoleList(userRoleList, userRoleFilters);
orgUserExtend.setUserRoleIdNameMap(userRoleList);
}
return orgUserExtends;

View File

@ -224,6 +224,11 @@ public class OrganizationControllerTests extends BaseTest {
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user", "sys_default_user2"));
organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId2", "sys_org_projectId3"));
this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk());
organizationMemberRequest = new OrgMemberExtendProjectRequest();
organizationMemberRequest.setOrganizationId("sys_default_organization_3");
organizationMemberRequest.setMemberIds(Arrays.asList("sys_default_user"));
organizationMemberRequest.setProjectIds(Arrays.asList("sys_org_projectId2"));
this.requestPost(ORGANIZATION_PROJECT_ADD_MEMBER, organizationMemberRequest, status().isOk());
// 批量添加成员成功后, 验证是否添加成功
listByKeyWord("testUserOne", "sys_default_organization_3", false, InternalUserRole.PROJECT_MEMBER.getValue(), "sys_org_projectId2", false, null, null);
}
@ -250,6 +255,8 @@ public class OrganizationControllerTests extends BaseTest {
organizationMemberRequest.setUserRoleIds(Arrays.asList("sys_default_org_role_id_3"));
this.requestPost(ORGANIZATION_LIST_ADD_MEMBER, organizationMemberRequest, status().isOk());
listByKeyWord("testUserThree", "sys_default_organization_3", false, null, null, false, null, null);
listByKeyWord(null, "sys_default_organization_3", false, null, null, false, null, null);
}
@Test
@ -488,9 +495,11 @@ public class OrganizationControllerTests extends BaseTest {
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(pageData.getList())).size() <= organizationRequest.getPageSize());
// 返回值中取出第一条数据, 并判断是否包含关键字admin
OrgUserExtend orgUserExtend = JSON.parseArray(JSON.toJSONString(pageData.getList()), OrgUserExtend.class).get(0);
Assertions.assertTrue(StringUtils.contains(orgUserExtend.getName(), organizationRequest.getKeyword())
|| StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword())
|| StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword()));
if (StringUtils.isNotBlank(keyWord)) {
Assertions.assertTrue(StringUtils.contains(orgUserExtend.getName(), organizationRequest.getKeyword())
|| StringUtils.contains(orgUserExtend.getEmail(), organizationRequest.getKeyword())
|| StringUtils.contains(orgUserExtend.getPhone(), organizationRequest.getKeyword()));
}
if (compare) {
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap());
List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList();