build-flow.api/tests/BuildFlow.Workflow.Tests/Form/FormRelationOptionsTests.cs
xiangning 2181f7dd49 feat(platform): 完善平台功能与权限管理
- 在菜单系统中新增 RenderType、FormDefinitionId 和 RuntimeViewMode 字段
- 实现自定义表单菜单类型的组件映射和验证逻辑
- 为分片上传相关端点添加 file:upload 权限控制
- 为桶和文件夹操作添加 bucket:write 和 file:write 权限控制
- 为文件共享功能添加 file-share:write 权限控制
- 为文件读取操作添加 file:read 权限控制
- 扩展 AI 模型提供商枚举,支持更多模型供应商
- 在 AI 模型创建和更新时添加枚举值验证
- 重构工作流按钮权限检查逻辑,使用统一的权限码查询方式
- 为 JSON 格式文档添加提取器支持
- 增强表单数据派生服务,支持自定义表单关联解析
- 为表单数据添加按表单定义 ID 的索引优化
- 添加聊天消息搜索和上下文获取的集成测试
- 修正删除菜单端点的 ID 类型从 Guid 改为 long
2026-07-04 19:38:43 +08:00

118 lines
3.8 KiB
C#

using FluentAssertions;
using BuildFlow.Workflow.Tests;
using Workflow.Application.Form.Derivation;
using Workflow.Application.Form.Relation.Handlers;
using Workflow.Application.Form.Relation.Queries;
using Workflow.Domain.Entities;
using Workflow.Domain.Enums;
using Xunit;
namespace BuildFlow.Workflow.Tests.Form;
public class FormRelationOptionsTests
{
[Fact]
public async Task GetFormRelationOptionsQuery_ShouldReturnOptionsFromPublishedCustomFormData()
{
await using var db = TestDbFactory.Create();
var supplierFormId = Guid.NewGuid();
db.FormDefinitions.Add(new FormDefinition
{
Id = supplierFormId,
Name = "供应商",
Code = "supplier",
Status = FormStatus.Published,
Version = 1,
SchemaJson = "{}",
});
db.FormData.AddRange(
new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-1","name":"上海供应商","code":"SH001"}""",
},
new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-2","name":"北京供应商","code":"BJ001"}""",
});
await db.SaveChangesAsync();
var handler = new GetFormRelationOptionsQueryHandler(db);
var result = await handler.Handle(
new GetFormRelationOptionsQuery(
"supplier",
"id",
"name",
"上海",
1,
20,
["code"]),
CancellationToken.None);
result.Total.Should().Be(1);
result.Items.Should().ContainSingle().Which.Should().BeEquivalentTo(new
{
Value = "supplier-1",
Label = "上海供应商",
Snapshot = new Dictionary<string, object?> { ["code"] = "SH001" },
});
}
[Fact]
public async Task FormValueDerivationService_ShouldResolveRelationSnapshotFromCustomFormData()
{
await using var db = TestDbFactory.Create();
var supplierFormId = Guid.NewGuid();
db.FormDefinitions.Add(new FormDefinition
{
Id = supplierFormId,
Name = "供应商",
Code = "supplier",
Status = FormStatus.Published,
Version = 1,
SchemaJson = "{}",
});
db.FormData.Add(new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-1","name":"上海供应商","code":"SH001"}""",
});
await db.SaveChangesAsync();
var service = new FormValueDerivationService([], [], db);
var result = await service.DeriveAsync(
"""
{
"type": "object",
"properties": {
"supplier": {
"type": "object",
"title": "供应商",
"x-component": "RelationPicker",
"x-field-kind": "relation",
"x-relation": {
"sourceCode": "supplier",
"idField": "id",
"labelField": "name",
"snapshotFields": ["code", "name"],
"updatePolicy": "snapshotOnly"
}
}
}
}
""",
"""{"supplier":"supplier-1"}""",
new FormDerivationContext(null, Guid.NewGuid(), null),
CancellationToken.None);
result.DataJson.Should().Contain("\"label\":\"上海供应商\"");
result.DataJson.Should().Contain("\"code\":\"SH001\"");
}
}