fix(plugin-workflow-aggregate): fix round on null result (#6473)

This commit is contained in:
Junyi 2025-03-15 22:27:31 +08:00 committed by GitHub
parent 2fd8cf44b7
commit e1f7e94e0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -49,7 +49,7 @@ export default class extends Instruction {
}); });
return { return {
result: round(options.dataType === DataTypes.DOUBLE ? Number(result) : result, 14), result: round((options.dataType === DataTypes.DOUBLE ? Number(result) : result) || 0, 14),
status: JOB_STATUS.RESOLVED, status: JOB_STATUS.RESOLVED,
}; };
} }

View File

@ -180,6 +180,27 @@ describe('workflow > instructions > aggregate', () => {
expect(j2.result).toBe(0.3); expect(j2.result).toBe(0.3);
}); });
it('sum null will be 0', async () => {
const n1 = await workflow.createNode({
type: 'aggregate',
config: {
aggregator: 'sum',
collection: 'posts',
params: {
field: 'read',
},
},
});
const p2 = await PostRepo.create({ values: { title: 't2' } });
await sleep(500);
const [e1] = await workflow.getExecutions();
const [j1] = await e1.getJobs();
expect(j1.result).toBe(0);
});
it('avg', async () => { it('avg', async () => {
const n1 = await workflow.createNode({ const n1 = await workflow.createNode({
type: 'aggregate', type: 'aggregate',