Skip to content

Commit

Permalink
Make not possible to have EventDefinitionOn.NONE and event definition…
Browse files Browse the repository at this point in the history
… kind in the same time
  • Loading branch information
csouchet committed Sep 28, 2023
1 parent c64ca00 commit fe34537
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 50 deletions.
120 changes: 70 additions & 50 deletions test/unit/helpers/JsonBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ describe('build json', () => {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: { id: '9' } },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: { id: '9' } },
},
],
},
Expand All @@ -1920,7 +1920,12 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: { id: 'event_id_0_0' },
[bpmnKind]: {
id: 'event_id_0_0',
messageEventDefinition: {
id: '9',
},
},
},
BPMNDiagram: {
name: 'process 0',
Expand All @@ -1936,6 +1941,21 @@ describe('build json', () => {
});
});

it(`not possible to have eventDefinitionOn=NONE with defined eventDefinitionKind`, () => {
expect(() => {
buildDefinitions({
process: {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE },
},
],
},
});
}).toThrow("Must use another value than NONE for 'eventDefinitionOn' when 'eventDefinitionKind' is set !!");
});

it(`build json of definitions containing one process with ${bpmnKind} (with one messageEventDefinition, name & id)`, () => {
const json = buildDefinitions({
process: {
Expand Down Expand Up @@ -2402,14 +2422,58 @@ describe('build json', () => {
});
});

it(`incoming and outgoing for ${bpmnKind}`, () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
],
},
});

expect(json).toEqual({
definitions: {
targetNamespace: '',
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: {
id: 'another_id',
messageEventDefinition: '',
name: 'name',
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: { x: 362, y: 232, width: 36, height: 45 },
},
},
},
},
});
});

if (bpmnKind === 'startEvent') {
it('build json of definitions containing one process with interrupting startEvent', () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: {} },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: {} },
isInterrupting: true,
},
],
Expand All @@ -2422,7 +2486,7 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
startEvent: { id: 'event_id_0_0', cancelActivity: true },
startEvent: { id: 'event_id_0_0', messageEventDefinition: {}, cancelActivity: true },
},
BPMNDiagram: {
name: 'process 0',
Expand All @@ -2444,7 +2508,7 @@ describe('build json', () => {
event: [
{
bpmnKind,
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.NONE, eventDefinition: {} },
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT, eventDefinition: {} },
isInterrupting: false,
},
],
Expand All @@ -2457,7 +2521,7 @@ describe('build json', () => {
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
startEvent: { id: 'event_id_0_0', cancelActivity: false },
startEvent: { id: 'event_id_0_0', cancelActivity: false, messageEventDefinition: {} },
},
BPMNDiagram: {
name: 'process 0',
Expand All @@ -2473,50 +2537,6 @@ describe('build json', () => {
});
});
}

it(`incoming and outgoing for ${bpmnKind}`, () => {
const json = buildDefinitions({
process: {
event: [
{
bpmnKind,
name: 'name',
id: 'another_id',
eventDefinitionParameter: { eventDefinitionKind: 'message', eventDefinitionOn: EventDefinitionOn.EVENT },
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
],
},
});

expect(json).toEqual({
definitions: {
targetNamespace: '',
collaboration: { id: 'collaboration_id_0' },
process: {
id: '0',
[bpmnKind]: {
id: 'another_id',
messageEventDefinition: '',
name: 'name',
incoming: ['incoming_id'],
outgoing: ['outgoing_id'],
},
},
BPMNDiagram: {
name: 'process 0',
BPMNPlane: {
BPMNShape: {
id: 'shape_another_id',
bpmnElement: 'another_id',
Bounds: { x: 362, y: 232, width: 36, height: 45 },
},
},
},
},
});
});
},
);

Expand Down
3 changes: 3 additions & 0 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ function addEvent(
break;
}
case EventDefinitionOn.NONE: {
if (eventDefinitionParameter.eventDefinitionKind) {
throw new Error("Must use another value than NONE for 'eventDefinitionOn' when 'eventDefinitionKind' is set !!");
}
break;
}
}
Expand Down

0 comments on commit fe34537

Please sign in to comment.