fix(项目设置): 获取字段列表,模板字段必选参数设置有误

This commit is contained in:
AgAngle 2024-03-15 15:33:05 +08:00 committed by Craftsman
parent db9ce01770
commit f1545c72da
3 changed files with 13 additions and 16 deletions

View File

@ -5,7 +5,7 @@ package io.metersphere.system.constants;
* @CreateTime: 2024-03-14 16:33 * @CreateTime: 2024-03-14 16:33
*/ */
public enum TemplateRequiredCustomField { public enum TemplateRequiredCustomField {
BUG_DEGREE("bug_degree"); BUG_DEGREE("functional_priority");
private String name; private String name;

View File

@ -68,9 +68,6 @@ public class BaseCustomFieldService {
Map<String, List<CustomFieldOption>> optionMap = customFieldOptions.stream().collect(Collectors.groupingBy(CustomFieldOption::getFieldId)); Map<String, List<CustomFieldOption>> optionMap = customFieldOptions.stream().collect(Collectors.groupingBy(CustomFieldOption::getFieldId));
return customFields.stream().map(item -> { return customFields.stream().map(item -> {
item.setCreateUser(userNameMap.get(item.getCreateUser())); item.setCreateUser(userNameMap.get(item.getCreateUser()));
if (item.getInternal()) {
item.setName(translateInternalField(item.getName()));
}
CustomFieldDTO customFieldDTO = new CustomFieldDTO(); CustomFieldDTO customFieldDTO = new CustomFieldDTO();
BeanUtils.copyBean(customFieldDTO, item); BeanUtils.copyBean(customFieldDTO, item);
//判断有没有用到 //判断有没有用到
@ -96,6 +93,8 @@ public class BaseCustomFieldService {
.map(TemplateRequiredCustomField::getName) .map(TemplateRequiredCustomField::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
customFieldDTO.setTemplateRequired(templateRequiredCustomFieldSet.contains(item.getName())); customFieldDTO.setTemplateRequired(templateRequiredCustomFieldSet.contains(item.getName()));
// 翻译内置字段名称
customFieldDTO.setName(translateInternalField(item.getName()));
} }
return customFieldDTO; return customFieldDTO;
}).toList(); }).toList();

View File

@ -4,7 +4,6 @@ import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.domain.ProjectExample;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
import io.metersphere.system.constants.TemplateRequiredCustomField;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.sdk.CustomFieldDTO; import io.metersphere.system.dto.sdk.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest; import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
@ -237,7 +236,13 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
List<String> userIds = customFields.stream().map(CustomField::getCreateUser).toList(); List<String> userIds = customFields.stream().map(CustomField::getCreateUser).toList();
Map<String, String> userNameMap = userLoginService.getUserNameMap(userIds); Map<String, String> userNameMap = userLoginService.getUserNameMap(userIds);
for (int i = 0; i < resultList.size(); i++) { for (int i = 0; i < resultList.size(); i++) {
CustomField resultItem = BeanUtils.copyBean(new CustomField(), resultList.get(i)); CustomFieldDTO customFieldDTO = resultList.get(i);
if (StringUtils.equals(customFieldDTO.getName(), "用例等级")) {
Assertions.assertTrue(customFieldDTO.getTemplateRequired());
} else {
Assertions.assertFalse(customFieldDTO.getTemplateRequired());
}
CustomField resultItem = BeanUtils.copyBean(new CustomField(), customFieldDTO);
CustomField customField = customFields.get(i); CustomField customField = customFields.get(i);
customField.setCreateUser(userNameMap.get(customField.getCreateUser())); customField.setCreateUser(userNameMap.get(customField.getCreateUser()));
if (customField.getInternal()) { if (customField.getInternal()) {
@ -248,7 +253,7 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
Assertions.assertEquals(resultItem.getScene(), scene); Assertions.assertEquals(resultItem.getScene(), scene);
if (StringUtils.equalsAny(resultItem.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) { if (StringUtils.equalsAny(resultItem.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
List<CustomFieldOption> options = resultList.get(i).getOptions(); List<CustomFieldOption> options = customFieldDTO.getOptions();
Assertions.assertEquals(options.size(), 1); Assertions.assertEquals(options.size(), 1);
Assertions.assertEquals(options.get(0).getValue(), "CREATE_USER"); Assertions.assertEquals(options.get(0).getValue(), "CREATE_USER");
Assertions.assertEquals(options.get(0).getText(), "创建人"); Assertions.assertEquals(options.get(0).getText(), "创建人");
@ -257,20 +262,13 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
Assertions.assertEquals(resultList.get(i).getOptions().stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList(), Assertions.assertEquals(resultList.get(i).getOptions().stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList(),
baseCustomFieldOptionService.getByFieldId(customField.getId()).stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList()); baseCustomFieldOptionService.getByFieldId(customField.getId()).stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList());
} }
Assertions.assertFalse(resultList.get(i).getTemplateRequired());
} }
mvcResult = this.requestGetWithOk(LIST, DEFAULT_ORGANIZATION_ID, TemplateScene.BUG.name()) mvcResult = this.requestGetWithOk(LIST, DEFAULT_ORGANIZATION_ID, TemplateScene.BUG.name())
.andReturn(); .andReturn();
// 校验数据是否正确 // 校验数据是否正确
resultList = getResultDataArray(mvcResult, CustomFieldDTO.class); resultList = getResultDataArray(mvcResult, CustomFieldDTO.class);
resultList.forEach(item -> { resultList.forEach(item -> Assertions.assertFalse(item.getTemplateRequired()));
if (StringUtils.equals(item.getName(), "bug_degree")) {
Assertions.assertTrue(item.getTemplateRequired());
} else {
Assertions.assertFalse(item.getTemplateRequired());
}
});
// @@校验组织是否存在 // @@校验组织是否存在
assertErrorCode(this.requestGet(LIST, "1111", scene), NOT_FOUND); assertErrorCode(this.requestGet(LIST, "1111", scene), NOT_FOUND);