Files
flow-center-service/src/test/java/com/yunhai/flowcenter/service/FlowDefAdminServiceUpdateMetaTest.java
T
chenxing a06b610d9d
build / build-push (push) Successful in 54s
feat(dept): 科室管理——flw_dept/flw_dept_member 组+成员模型取代单用户映射行(议题3,拍板D1选B)
- deptKey=本地自增 id;source_group_id 幂等(一键拉取=初始化/刷新语义,不重复建组);不做存量迁移
- 四处读源全部切新表:AssigneeResolver(宽容口径:deptKey 不存在/停用返回空,图示/轨迹不炸)、
  enabledDeptKeys 发布校验白名单、DeptLabelSupport 唯一出口(图示科室视图+轨迹富化)、编辑器 deptList 聚合
- /admin/dept/* 全套端点(CRUD/成员/拉取预览导入);旧 /map/* 映射 CRUD 端点删除
  (保留 /map/lookupUser 选人检索与 /user/teacherTree);flw_assignee_map 实体/表保留不删
- IT 种子切源(FlowTestSupport tag→deptKey 注册表,用例主体零改动);全量 191 绿;E2E 22/22
  (local-debug/four-topics-e-e2e.py,含切源后果验证与生产盘点 SQL)
2026-10-10 19:47:58 +08:00

123 lines
4.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.yunhai.flowcenter.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yunhai.flowcenter.engine.FlowEngine;
import com.yunhai.flowcenter.entity.FlwDef;
import com.yunhai.flowcenter.repository.FlwAppRepository;
import com.yunhai.flowcenter.repository.FlwDefRepository;
import com.yunhai.flowcenter.repository.FlwRouterRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* updateMeta 原地编辑单测(2026-10-10 议题2,拍板 D4):
* 三不变(version/flowGuid/status;contentJson 仅顶层 name)、appKey 白名单校验、
* contentJson 无顶层 name 时补写、name 非空校验。
*/
class FlowDefAdminServiceUpdateMetaTest {
private static final Long SCH = 3L;
private FlwDefRepository defRepository;
private FlwAppRepository appRepository;
private FlowDefAdminService service;
@BeforeEach
void setUp() {
defRepository = mock(FlwDefRepository.class);
appRepository = mock(FlwAppRepository.class);
service = new FlowDefAdminService(defRepository,
mock(FlwRouterRepository.class),
mock(com.yunhai.flowcenter.repository.FlwCallbackRegRepository.class),
appRepository,
mock(com.yunhai.flowcenter.service.FlowDeptAdminService.class),
mock(FlowEngine.class),
new ObjectMapper());
when(defRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
when(appRepository.isEnabledApp(any(), any())).thenReturn(true);
}
private FlwDef published(String contentJson) {
FlwDef d = new FlwDef();
d.setId(9L);
d.setSchId(SCH);
d.setFlowGuid("guid123");
d.setCode("work-leave");
d.setName("旧名");
d.setAppKey("100002");
d.setVersion(4);
d.setStatus(1);
d.setContentJson(contentJson);
return d;
}
@Test
void 三不变_contentJson仅顶层name() throws Exception {
String json = "{\"code\":\"work-leave\",\"name\":\"旧名\",\"start\":\"start\","
+ "\"nodes\":[{\"id\":\"start\",\"type\":\"START\"}],"
+ "\"edges\":[{\"from\":\"start\",\"to\":\"end\"}]}";
FlwDef def = published(json);
when(defRepository.findById(9L)).thenReturn(Optional.of(def));
FlwDef saved = service.updateMeta(SCH, 9L, "新名称", "100008");
assertEquals(4, saved.getVersion());
assertEquals("guid123", saved.getFlowGuid());
assertEquals(1, saved.getStatus());
assertEquals("work-leave", saved.getCode());
assertEquals("新名称", saved.getName());
assertEquals("100008", saved.getAppKey());
assertEquals("新名称", new ObjectMapper().readTree(saved.getContentJson()).path("name").asText());
// 结构零改动:节点/边/其余顶层字段原样保留
assertEquals("work-leave", new ObjectMapper().readTree(saved.getContentJson()).path("code").asText());
assertTrue(saved.getContentJson().contains("\"type\":\"START\""));
}
@Test
void contentJson无顶层name_补写() throws Exception {
FlwDef def = published("{\"code\":\"c\",\"start\":\"start\",\"nodes\":[],\"edges\":[]}");
when(defRepository.findById(9L)).thenReturn(Optional.of(def));
FlwDef saved = service.updateMeta(SCH, 9L, "补写名", null);
assertEquals("补写名", new ObjectMapper().readTree(saved.getContentJson()).path("name").asText());
assertNull(saved.getAppKey());
}
@Test
void appKey白名单外_被拦() {
when(appRepository.isEnabledApp(SCH, "888888")).thenReturn(false);
when(defRepository.findById(9L)).thenReturn(Optional.of(published("{}")));
Exception e = assertThrows(com.yunhai.platform.apistd.BizException.class,
() -> service.updateMeta(SCH, 9L, "n", "888888"));
assertTrue(e.getMessage().contains("应用设置"));
}
@Test
void name空_被拦() {
when(defRepository.findById(9L)).thenReturn(Optional.of(published("{}")));
assertThrows(com.yunhai.platform.apistd.BizException.class,
() -> service.updateMeta(SCH, 9L, " ", null));
}
@Test
void 跨校_被拒() {
FlwDef other = published("{}");
other.setSchId(2L);
when(defRepository.findById(9L)).thenReturn(Optional.of(other));
assertThrows(com.yunhai.platform.apistd.BizException.class,
() -> service.updateMeta(SCH, 9L, "n", null));
}
}