-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugin-workflow): add date range options to system variables #4728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还需要增加相关的单元测试,例如:
it('params.filter on date range: yesterday', async () => {
const n1 = await workflow.createNode({
type: 'query',
config: {
collection: 'posts',
params: {
filter: {
createdAt: {
$dateOn: '{{$system.dateRange.yesterday}}',
},
},
},
},
});
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
const post = await PostRepo.create({
values: {
title: 't1',
createdAt: yesterday
},
});
await sleep(500);
const [execution] = await workflow.getExecutions();
const [job] = await execution.getJobs();
expect(job.result.title).toBe(post.title);
});
不一定套在 query 节点里,只要能测试 Processor.getParsedValue
或者 Processor.getScope
的解析结果正确,且可以作为 filter 参数交给 repository.find
方法查询出正确的结果即可(时间边界范围需要覆盖)。
可以考虑单独针对 functions 开一个单测文件。
packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx
Outdated
Show resolved
Hide resolved
packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts
Outdated
Show resolved
Hide resolved
packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts
Outdated
Show resolved
Hide resolved
packages/plugins/@nocobase/plugin-workflow/src/server/functions/index.ts
Outdated
Show resolved
Hide resolved
packages/plugins/@nocobase/plugin-workflow/src/server/functions/index.ts
Outdated
Show resolved
Hide resolved
packages/plugins/@nocobase/plugin-workflow/src/server/functions/index.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
核心问题是测试用例的写法需要简化,可以参考这条评论:
可以直接使用 parse 后的内容对某个 repository 的 findAll 进行测试,会简化很多。
时间值的设置需要考虑临界点,更有针对性。
Description
Add date range options to system variables in workflow context.
Motivation
Date range variables in data block filter is convenient to use. It will also be useful in workflow nodes.
Key changes
Test plan
Suggestions
Through test cases.
Underlying risk
Date range variables can not be used for operators other than "is".
Showcase