@justworkflowit/cdk-constructs 0.0.187 → 0.0.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const engine_1 = require("@justworkflowit/engine");
4
+ describe('Workflow Engine Integration Tests', () => {
5
+ const simpleIntegration = 'simpleIntegration';
6
+ const outputAPropertyKey = 'outputPropertyA';
7
+ const outputA = {
8
+ [outputAPropertyKey]: 'anOutputPropertyValue',
9
+ };
10
+ const stepExecutorA = {
11
+ type: simpleIntegration,
12
+ execute: (_args) => Promise.resolve({
13
+ status: 'success',
14
+ payload: outputA,
15
+ }),
16
+ };
17
+ const stepExecutorB = {
18
+ type: 'noopIntegration',
19
+ execute: (_args) => Promise.resolve({
20
+ status: 'success',
21
+ payload: {},
22
+ }),
23
+ };
24
+ const stepExecutors = [stepExecutorA, stepExecutorB];
25
+ const step1Name = 'firstStep';
26
+ const step2Name = 'secondStep';
27
+ const step1InputName = `${step1Name}Input`;
28
+ const step1OutputName = `${step1Name}Output`;
29
+ const step2InputName = `${step2Name}Input`;
30
+ const step2OutputName = `${step2Name}Output`;
31
+ const validWorkflowDefinition = {
32
+ workflowName: 'validWorkflowDefinition',
33
+ steps: [
34
+ {
35
+ name: step1Name,
36
+ retries: 2,
37
+ timeoutSeconds: 1000,
38
+ transitionToStep: step2Name,
39
+ integrationDetails: {
40
+ type: simpleIntegration,
41
+ inputDefinition: {
42
+ $ref: `#/definitions/${step1InputName}`,
43
+ },
44
+ outputDefinition: {
45
+ $ref: `#/definitions/${step1OutputName}`,
46
+ },
47
+ inputTransformer: {
48
+ fieldset: [
49
+ {
50
+ to: 'inputPropertyA',
51
+ withTemplate: 'a brand new field',
52
+ },
53
+ ],
54
+ },
55
+ },
56
+ },
57
+ {
58
+ name: step2Name,
59
+ retries: 2,
60
+ timeoutSeconds: 1000,
61
+ transitionToStep: null,
62
+ integrationDetails: {
63
+ type: simpleIntegration,
64
+ inputDefinition: {
65
+ $ref: `#/definitions/${step2InputName}`,
66
+ },
67
+ outputDefinition: {
68
+ $ref: `#/definitions/${step2OutputName}`,
69
+ },
70
+ inputTransformer: {
71
+ fieldset: [
72
+ {
73
+ from: `${step1Name}Output.${outputAPropertyKey}`,
74
+ to: 'inputPropertyB',
75
+ },
76
+ ],
77
+ },
78
+ },
79
+ },
80
+ ],
81
+ definitions: {
82
+ [step1InputName]: {
83
+ type: 'object',
84
+ properties: {
85
+ inputPropertyA: {
86
+ type: 'string',
87
+ },
88
+ },
89
+ required: ['inputPropertyA'],
90
+ additionalProperties: false,
91
+ },
92
+ [step1OutputName]: {
93
+ type: 'object',
94
+ properties: {
95
+ outputPropertyA: {
96
+ type: 'string',
97
+ },
98
+ },
99
+ required: ['outputPropertyA'],
100
+ additionalProperties: false,
101
+ },
102
+ [step2InputName]: {
103
+ type: 'object',
104
+ properties: {
105
+ inputPropertyB: {
106
+ type: 'string',
107
+ },
108
+ },
109
+ required: ['inputPropertyB'],
110
+ additionalProperties: false,
111
+ },
112
+ [step2OutputName]: {
113
+ type: 'object',
114
+ properties: {
115
+ outputPropertyB: {
116
+ type: 'string',
117
+ },
118
+ },
119
+ required: ['outputPropertyB'],
120
+ additionalProperties: false,
121
+ },
122
+ },
123
+ };
124
+ test('should initialize engine with valid workflow definition', () => {
125
+ expect(() => {
126
+ new engine_1.JustWorkflowItEngine({
127
+ workflowDefinition: JSON.stringify(validWorkflowDefinition),
128
+ stepExecutors,
129
+ });
130
+ }).not.toThrow();
131
+ });
132
+ test('should execute a valid workflow', async () => {
133
+ const engine = new engine_1.JustWorkflowItEngine({
134
+ workflowDefinition: JSON.stringify(validWorkflowDefinition),
135
+ stepExecutors,
136
+ });
137
+ const initialState = {
138
+ nextStepName: step1Name,
139
+ executionData: {},
140
+ executionHistory: [],
141
+ };
142
+ const runner = new engine_1.SampleEngineRunner(engine, initialState);
143
+ await runner.runUntilTerminalStep();
144
+ const finalState = runner.getCurrentWorkflowState();
145
+ expect(finalState).toBeDefined();
146
+ expect(finalState.nextStepName).toBeNull();
147
+ expect(finalState.executionHistory.length).toBeGreaterThan(0);
148
+ });
149
+ test('should validate workflow definition structure', () => {
150
+ const engine = new engine_1.JustWorkflowItEngine({
151
+ workflowDefinition: JSON.stringify(validWorkflowDefinition),
152
+ stepExecutors,
153
+ });
154
+ expect(engine).toBeInstanceOf(engine_1.JustWorkflowItEngine);
155
+ });
156
+ test('should handle workflow with multiple steps', async () => {
157
+ const engine = new engine_1.JustWorkflowItEngine({
158
+ workflowDefinition: JSON.stringify(validWorkflowDefinition),
159
+ stepExecutors,
160
+ });
161
+ const initialState = {
162
+ nextStepName: step1Name,
163
+ executionData: {},
164
+ executionHistory: [],
165
+ };
166
+ const runner = new engine_1.SampleEngineRunner(engine, initialState);
167
+ await runner.runUntilTerminalStep();
168
+ const finalState = runner.getCurrentWorkflowState();
169
+ // Verify that the workflow executed both steps
170
+ expect(finalState.executionHistory.length).toBe(2);
171
+ expect(finalState.executionHistory[0].stepName).toBe(step1Name);
172
+ expect(finalState.executionHistory[1].stepName).toBe(step2Name);
173
+ });
174
+ test('should validate step definitions exist', () => {
175
+ const workflowWithMissingDefinition = {
176
+ ...validWorkflowDefinition,
177
+ definitions: {},
178
+ };
179
+ expect(() => {
180
+ new engine_1.JustWorkflowItEngine({
181
+ workflowDefinition: JSON.stringify(workflowWithMissingDefinition),
182
+ stepExecutors,
183
+ });
184
+ }).toThrow();
185
+ });
186
+ test('should execute step and transition to next step', async () => {
187
+ const engine = new engine_1.JustWorkflowItEngine({
188
+ workflowDefinition: JSON.stringify(validWorkflowDefinition),
189
+ stepExecutors,
190
+ });
191
+ const initialState = {
192
+ nextStepName: step1Name,
193
+ executionData: {},
194
+ executionHistory: [],
195
+ };
196
+ const stateAfterStep1 = await engine.executeNextStep(initialState);
197
+ expect(stateAfterStep1.nextStepName).toBe(step2Name);
198
+ expect(stateAfterStep1.executionHistory.length).toBe(1);
199
+ expect(stateAfterStep1.executionHistory[0].stepName).toBe(step1Name);
200
+ expect(stateAfterStep1.executionHistory[0]?.output?.status).toBe('success');
201
+ });
202
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justworkflowit/cdk-constructs",
3
3
  "description": "",
4
- "version": "0.0.187",
4
+ "version": "0.0.189",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
@@ -10,7 +10,8 @@
10
10
  "scripts": {
11
11
  "build": "tsc && node esbuild-lambdas.js",
12
12
  "lint": "eslint . --ext .ts",
13
- "lint:fix": "eslint --fix . --ext .ts"
13
+ "lint:fix": "eslint --fix . --ext .ts",
14
+ "test": "jest"
14
15
  },
15
16
  "files": [
16
17
  "dist",
@@ -23,10 +24,13 @@
23
24
  "dependencies": {
24
25
  "@aws-sdk/client-s3": "^3.842.0",
25
26
  "@justworkflowit/api-client": "*",
27
+ "@justworkflowit/engine": "^0.0.72",
26
28
  "aws-cdk-lib": "^2.0.0",
27
29
  "constructs": "^10.0.0"
28
30
  },
29
31
  "devDependencies": {
32
+ "@types/jest": "^29.5.12",
33
+ "@types/node": "^20.12.5",
30
34
  "cdk-cli": "^1.1.0",
31
35
  "eslint": "^9.29.0",
32
36
  "eslint-config-prettier": "^9.1.0",
@@ -35,7 +39,9 @@
35
39
  "eslint-plugin-promise": "^7.2.1",
36
40
  "eslint-plugin-testing-library": "^7.1.1",
37
41
  "eslint-plugin-unused-imports": "^4.1.4",
42
+ "jest": "^29.7.0",
38
43
  "prettier": "^3.6.2",
44
+ "ts-jest": "^29.1.2",
39
45
  "ts-node": "^10.9.2",
40
46
  "typescript": "^5.8.3",
41
47
  "typescript-eslint": "^8.24.1"