From 912f8b24a049f1c9ae249aa60ef617f97cf162eb Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 30 Aug 2023 17:14:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE=E6=A0=B9=E6=8D=AE=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E5=90=8D=E7=A7=B0=E6=8E=92=E5=BA=8F=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/mapper/ExtSystemProjectMapper.xml | 2 +- .../OrganizationProjectControllerTests.java | 26 +++++++++++++++++ .../SystemProjectControllerTests.java | 29 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml index 01f6569fd7..b673f42ce9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtSystemProjectMapper.xml @@ -37,7 +37,7 @@ p.update_user, p.enable, count(distinct temp.id) as memberCount, - o.name as organizationName, + o.name as organization_name, p.module_setting FROM project p LEFT JOIN (SELECT ur.source_id, u.id from user_role_relation ur left join user u on u.id = ur.user_id where u.deleted = 0) temp on p.id = temp.source_id diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java index c3bc559ae3..6c777bb96b 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java @@ -353,6 +353,32 @@ public class OrganizationProjectControllerTests extends BaseTest { List createUsers = projectDTOS.stream().map(ProjectDTO::getCreateUser).toList(); User user = userMapper.selectByPrimaryKey("test"); Assertions.assertTrue(List.of(user.getName()).containsAll(createUsers)); + //排序 + projectRequest.setSort(new HashMap<>() {{ + put("organizationName", "asc"); + }}); + mvcResult = this.responsePost(getProjectList, projectRequest); + returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //第一个数据的organizationName是最小的 + assert returnPager != null; + projectDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ProjectDTO.class); + String firstOrganizationName = projectDTOS.get(0).getOrganizationName(); + for (ProjectDTO projectDTO : projectDTOS) { + Assertions.assertFalse(projectDTO.getOrganizationName().compareTo(firstOrganizationName) < 0); + } + + projectRequest.setSort(new HashMap<>() {{ + put("organizationName", "desc"); + }}); + mvcResult = this.responsePost(getProjectList, projectRequest); + returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //第一个数据的organizationName是最大的 + assert returnPager != null; + projectDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ProjectDTO.class); + firstOrganizationName = projectDTOS.get(0).getOrganizationName(); + for (ProjectDTO projectDTO : projectDTOS) { + Assertions.assertFalse(projectDTO.getOrganizationName().compareTo(firstOrganizationName) > 0); + } // @@校验权限 requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getProjectList, projectRequest); } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java index 972695b462..f2cad2bfcf 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java @@ -342,6 +342,35 @@ public class SystemProjectControllerTests extends BaseTest { List createUsers = projectDTOS.stream().map(ProjectDTO::getCreateUser).toList(); User user = userMapper.selectByPrimaryKey("test"); Assertions.assertTrue(List.of(user.getName()).containsAll(createUsers)); + + //排序 + projectRequest.setSort(new HashMap<>() {{ + put("organizationName", "asc"); + }}); + mvcResult = this.responsePost(getProjectList, projectRequest); + returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //第一个数据的organizationName是最小的 + assert returnPager != null; + projectDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ProjectDTO.class); + String firstOrganizationName = projectDTOS.get(0).getOrganizationName(); + for (ProjectDTO projectDTO : projectDTOS) { + Assertions.assertFalse(projectDTO.getOrganizationName().compareTo(firstOrganizationName) < 0); + } + + projectRequest.setSort(new HashMap<>() {{ + put("organizationName", "desc"); + }}); + mvcResult = this.responsePost(getProjectList, projectRequest); + returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //第一个数据的organizationName是最大的 + assert returnPager != null; + projectDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ProjectDTO.class); + firstOrganizationName = projectDTOS.get(0).getOrganizationName(); + for (ProjectDTO projectDTO : projectDTOS) { + Assertions.assertFalse(projectDTO.getOrganizationName().compareTo(firstOrganizationName) > 0); + } + + // @@校验权限 requestPostPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProjectList, projectRequest); }