Skip to content

Commit 70b9df5

Browse files
committed
Skip command and event generation inside test-scenarios
1 parent 0cb3b8f commit 70b9df5

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/cody/src/lib/hooks/on-command.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "@proophboard/cody-utils";
1414
import {detectService} from "./utils/detect-service";
1515
import {findAggregateState} from "./utils/aggregate/find-aggregate-state";
16-
import {getNodeFromSyncedNodes} from "./utils/node-tree";
16+
import {findParentByType, getNodeFromSyncedNodes} from "./utils/node-tree";
1717
import {asyncWithErrorCheck, CodyResponseException, withErrorCheck} from "./utils/error-handling";
1818
import {getVoMetadata} from "./utils/value-object/get-vo-metadata";
1919
import {updateProophBoardInfo} from "./utils/prooph-board-info";
@@ -43,6 +43,18 @@ export interface CommandMeta {
4343

4444
export const onCommand: CodyHook<Context> = async (command: Node, ctx: Context) => {
4545
try {
46+
const feature = findParentByType(command, NodeType.feature);
47+
48+
if(feature) {
49+
const featureMeta = parseJsonMetadata<{mode?: string}>(feature);
50+
51+
if(!isCodyError(featureMeta) && featureMeta.mode === 'test-scenario') {
52+
return {
53+
cody: `Inside test feature, skipping generation of command "${command.getName()}".`,
54+
}
55+
}
56+
}
57+
4658
const cmdNames = names(command.getName());
4759
const aggregate = getSingleTarget(command, NodeType.aggregate);
4860
const service = withErrorCheck(detectService, [command, ctx]);

packages/cody/src/lib/hooks/on-event.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {CodyHook, Node, NodeType} from "@proophboard/cody-types";
22
import {Context} from "./context";
33
import {CodyResponseException, withErrorCheck} from "./utils/error-handling";
44
import {names} from "@event-engine/messaging/helpers";
5-
import {getSingleSource, isCodyError} from "@proophboard/cody-utils";
5+
import {getSingleSource, isCodyError, parseJsonMetadata} from "@proophboard/cody-utils";
66
import {detectService} from "./utils/detect-service";
7-
import {getNodeFromSyncedNodes} from "./utils/node-tree";
7+
import {findParentByType, getNodeFromSyncedNodes} from "./utils/node-tree";
88
import {findAggregateState} from "./utils/aggregate/find-aggregate-state";
99
import {getVoMetadata} from "./utils/value-object/get-vo-metadata";
1010
import {flushChanges} from "nx/src/generators/tree";
@@ -24,6 +24,19 @@ import {getOriginalEvent} from "@cody-engine/cody/hooks/utils/event/get-original
2424

2525
export const onEvent: CodyHook<Context> = async (event: Node, ctx: Context) => {
2626
try {
27+
28+
const feature = findParentByType(event, NodeType.feature);
29+
30+
if(feature) {
31+
const featureMeta = parseJsonMetadata<{mode?: string}>(feature);
32+
33+
if(!isCodyError(featureMeta) && featureMeta.mode === 'test-scenario') {
34+
return {
35+
cody: `Inside test feature, skipping generation of event "${event.getName()}".`,
36+
}
37+
}
38+
}
39+
2740
event = getOriginalEvent(event, ctx);
2841
const eventNames = names(event.getName());
2942
const aggregate = getSingleSource(event, NodeType.aggregate);

0 commit comments

Comments
 (0)