mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:35:20 +00:00
refactor(plugin-workflow): change strict equal and not equal to unstrict (#2346)
This commit is contained in:
parent
620d1ff8df
commit
021ca950ab
@ -1,7 +1,7 @@
|
||||
import { Application } from '@nocobase/server';
|
||||
import Database from '@nocobase/database';
|
||||
import { Application } from '@nocobase/server';
|
||||
import { getApp, sleep } from '..';
|
||||
import { EXECUTION_STATUS, BRANCH_INDEX } from '../../constants';
|
||||
import { BRANCH_INDEX, EXECUTION_STATUS } from '../../constants';
|
||||
|
||||
describe('workflow > instructions > condition', () => {
|
||||
let app: Application;
|
||||
@ -243,6 +243,7 @@ describe('workflow > instructions > condition', () => {
|
||||
});
|
||||
|
||||
describe('engines', () => {
|
||||
describe('basic', () => {
|
||||
it('default as basic', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
@ -266,7 +267,56 @@ describe('workflow > instructions > condition', () => {
|
||||
expect(job.result).toEqual(true);
|
||||
});
|
||||
|
||||
it('basic engine', async () => {
|
||||
it('equal: 0 != null', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
type: 'condition',
|
||||
config: {
|
||||
engine: 'basic',
|
||||
calculation: {
|
||||
calculator: 'equal',
|
||||
operands: [0, '{{$context.data.title}}'],
|
||||
},
|
||||
rejectOnFalse: false,
|
||||
},
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: {} });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||
|
||||
const [job] = await execution.getJobs();
|
||||
expect(job.result).toEqual(false);
|
||||
});
|
||||
|
||||
it('equal: 0 == false', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
type: 'condition',
|
||||
config: {
|
||||
engine: 'basic',
|
||||
calculation: {
|
||||
calculator: 'equal',
|
||||
operands: [false, '{{$context.data.read}}'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: {} });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||
|
||||
const [job] = await execution.getJobs();
|
||||
expect(job.result).toEqual(true);
|
||||
});
|
||||
|
||||
it('equal: number == number', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
type: 'condition',
|
||||
@ -290,6 +340,55 @@ describe('workflow > instructions > condition', () => {
|
||||
expect(job.result).toEqual(true);
|
||||
});
|
||||
|
||||
it('equal: string == number', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
type: 'condition',
|
||||
config: {
|
||||
engine: 'basic',
|
||||
calculation: {
|
||||
calculator: 'equal',
|
||||
operands: ['1', '{{$context.data.read}}'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: { read: 1 } });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||
|
||||
const [job] = await execution.getJobs();
|
||||
expect(job.result).toEqual(true);
|
||||
});
|
||||
|
||||
it('equal: undefined == null', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
type: 'condition',
|
||||
config: {
|
||||
engine: 'basic',
|
||||
calculation: {
|
||||
calculator: 'equal',
|
||||
operands: ['{{$context.data.category.id}}', null],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const post = await PostRepo.create({ values: {} });
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const [execution] = await workflow.getExecutions();
|
||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||
|
||||
const [job] = await execution.getJobs();
|
||||
expect(job.result).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('math.js', async () => {
|
||||
const n1 = await workflow.createNode({
|
||||
title: 'condition',
|
||||
|
@ -11,11 +11,11 @@ export const calculators = new Registry<Comparer>();
|
||||
|
||||
// built-in functions
|
||||
function equal(a, b) {
|
||||
return a === b;
|
||||
return a == b;
|
||||
}
|
||||
|
||||
function notEqual(a, b) {
|
||||
return a !== b;
|
||||
return a != b;
|
||||
}
|
||||
|
||||
function gt(a, b) {
|
||||
@ -41,8 +41,8 @@ calculators.register('gte', gte);
|
||||
calculators.register('lt', lt);
|
||||
calculators.register('lte', lte);
|
||||
|
||||
calculators.register('===', equal);
|
||||
calculators.register('!==', notEqual);
|
||||
calculators.register('==', equal);
|
||||
calculators.register('!=', notEqual);
|
||||
calculators.register('>', gt);
|
||||
calculators.register('>=', gte);
|
||||
calculators.register('<', lt);
|
||||
|
Loading…
Reference in New Issue
Block a user