Skip to content

Commit

Permalink
test(JsonBuilder): enforce the type of `BuildEventDefinitionParameter…
Browse files Browse the repository at this point in the history
…` `eventDefinitionKind` property in JsonBuilder (#2897)
  • Loading branch information
csouchet authored Sep 29, 2023
1 parent ebffc93 commit 68ff296
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { BuildDefinitionParameter } from '../../../helpers/JsonBuilder';
import type { BuildDefinitionParameter, BuildEventDefinition } from '../../../helpers/JsonBuilder';

import { buildDefinitions, EventDefinitionOn } from '../../../helpers/JsonBuilder';
import { expectAsWarning, parseJsonAndExpectOnlyFlowNodes, parsingMessageCollector } from '../../../helpers/JsonTestUtils';
Expand Down Expand Up @@ -42,7 +42,7 @@ function testMustNotConvertBoundaryEvent(definitionParameter: BuildDefinitionPar
}

describe('for boundaryEvents', () => {
describe.each(eventDefinitionsParameters)(`for %s boundaryEvent`, (eventDefinitionKind: string, expectedEventDefinitionKind: ShapeBpmnEventDefinitionKind) => {
describe.each(eventDefinitionsParameters)(`for %s boundaryEvent`, (eventDefinitionKind: BuildEventDefinition, expectedEventDefinitionKind: ShapeBpmnEventDefinitionKind) => {
if (
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.NONE ||
expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.LINK ||
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('for boundaryEvents', () => {
bpmnElementKind: ShapeBpmnElementKind.EVENT_BOUNDARY,
bpmnElementName: undefined,
eventDefinitionKind: expectedEventDefinitionKind,
isInterrupting: true,
isInterrupting,
},
);
});
Expand All @@ -127,7 +127,7 @@ describe('for boundaryEvents', () => {
});
});

it(`should NOT convert, when 'boundaryEvent' is ${isInterruptingTitle} & attached to no existing activity, ${titleForEventDefinitionIsAttributeOf}`, () => {
it(`should NOT convert, when 'boundaryEvent' is ${isInterruptingTitle} & attached to unexisting activity, ${titleForEventDefinitionIsAttributeOf}`, () => {
testMustNotConvertBoundaryEvent(
{
process: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { OtherBuildEventKind } from '../../../helpers/JsonBuilder';
import type { BuildEventDefinition, OtherBuildEventKind } from '../../../helpers/JsonBuilder';

import { verifyShape } from '../../../helpers/bpmn-model-expect';
import { buildDefinitions, EventDefinitionOn } from '../../../helpers/JsonBuilder';
Expand All @@ -25,14 +25,14 @@ import { ShapeBpmnElementKind, ShapeBpmnEventDefinitionKind } from '@lib/model/b

// None intermediateCatchEvent not supported in BPMN specification
describe.each([
[ShapeBpmnElementKind.EVENT_START, ['message', 'timer', 'conditional', 'signal']],
[ShapeBpmnElementKind.EVENT_END, ['message', 'error', 'escalation', 'cancel', 'compensate', 'signal', 'terminate']],
[ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW, ['message', 'escalation', 'compensate', 'link', 'signal']],
])('for none %s', (expectedShapeBpmnElementKind: ShapeBpmnElementKind, allDefinitionKinds: string[]) => {
[ShapeBpmnElementKind.EVENT_START, ['message', 'timer', 'conditional', 'signal'] as BuildEventDefinition[]],
[ShapeBpmnElementKind.EVENT_END, ['message', 'error', 'escalation', 'cancel', 'compensate', 'signal', 'terminate'] as BuildEventDefinition[]],
[ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW, ['message', 'escalation', 'compensate', 'link', 'signal'] as BuildEventDefinition[]],
])('for none %s', (expectedShapeBpmnElementKind: ShapeBpmnElementKind, allDefinitionKinds: BuildEventDefinition[]) => {
executeEventCommonTests(
{
bpmnKind: expectedShapeBpmnElementKind as OtherBuildEventKind | 'startEvent',
eventDefinitionParameter: { eventDefinitionKind: 'none', eventDefinitionOn: EventDefinitionOn.NONE },
eventDefinitionParameter: { eventDefinitionOn: EventDefinitionOn.NONE },
},
{
bpmnElementKind: expectedShapeBpmnElementKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { OtherBuildEventKind } from '../../../helpers/JsonBuilder';
import type { BuildEventDefinition, OtherBuildEventKind } from '../../../helpers/JsonBuilder';
import type { TEventDefinition } from '@lib/model/bpmn/json/baseElement/rootElement/eventDefinition';

import { EventDefinitionOn } from '../../../helpers/JsonBuilder';
Expand All @@ -27,7 +27,7 @@ describe.each([ShapeBpmnElementKind.EVENT_START, ShapeBpmnElementKind.EVENT_END,
(expectedShapeBpmnElementKind: ShapeBpmnElementKind) => {
describe.each(eventDefinitionsParameters)(
`for %s ${expectedShapeBpmnElementKind}`,
(eventDefinitionKind: string, expectedEventDefinitionKind: ShapeBpmnEventDefinitionKind) => {
(eventDefinitionKind: BuildEventDefinition, expectedEventDefinitionKind: ShapeBpmnEventDefinitionKind) => {
if (
(expectedShapeBpmnElementKind === ShapeBpmnElementKind.EVENT_START &&
(expectedEventDefinitionKind === ShapeBpmnEventDefinitionKind.ERROR ||
Expand Down
8 changes: 4 additions & 4 deletions test/unit/helpers/JsonBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ type BuildBoundaryEventParameter = {
attachedToRef: string;
} & BuildInterruptingEventParameter;

export type BuildEventDefinition = 'message' | 'signal' | 'timer' | 'error' | 'escalation' | 'cancel' | 'compensate' | 'conditional' | 'link' | 'terminate';
export type BuildEventDefinitionParameter = {
eventDefinitionKind?: string;
eventDefinitionKind?: BuildEventDefinition;
eventDefinitionOn: EventDefinitionOn;
eventDefinition?: BPMNEventDefinition;
withDifferentDefinition?: boolean;
Expand Down Expand Up @@ -486,9 +487,8 @@ function addEventDefinitions(
{ eventDefinitionKind, eventDefinition = '', withDifferentDefinition = false }: BuildEventDefinitionParameter,
differentEventDefinition: TEventDefinition | string = '',
): void {
if (eventDefinitionKind !== 'none') {
event[`${eventDefinitionKind}EventDefinition`] = eventDefinition;
}
event[`${eventDefinitionKind}EventDefinition` as keyof BPMNTEvent] = eventDefinition;

if (withDifferentDefinition) {
const otherEventDefinition = eventDefinitionKind === 'signal' ? 'message' : 'signal';
event[`${otherEventDefinition}EventDefinition`] = differentEventDefinition;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/helpers/TestUtils.BpmnJsonParser.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import type { ExpectedBoundaryEventShape, ExpectedEventShape, ExpectedShape } from './bpmn-model-expect';
import type { BuildEventsParameter } from './JsonBuilder';
import type { BuildEventDefinition, BuildEventsParameter } from './JsonBuilder';

import { verifyShape } from './bpmn-model-expect';
import { buildDefinitions, EventDefinitionOn } from './JsonBuilder';
Expand Down Expand Up @@ -214,7 +214,7 @@ export function executeEventCommonTests(buildEventParameter: BuildEventsParamete
}
}

export const eventDefinitionsParameters: [string, ShapeBpmnEventDefinitionKind][] = [
export const eventDefinitionsParameters: [BuildEventDefinition, ShapeBpmnEventDefinitionKind][] = [
['message', ShapeBpmnEventDefinitionKind.MESSAGE],
['timer', ShapeBpmnEventDefinitionKind.TIMER],
['terminate', ShapeBpmnEventDefinitionKind.TERMINATE],
Expand Down

0 comments on commit 68ff296

Please sign in to comment.