@justworkflowit/cdk-constructs 0.0.189 → 0.0.191

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.
@@ -199,4 +199,244 @@ describe('Workflow Engine Integration Tests', () => {
199
199
  expect(stateAfterStep1.executionHistory[0].stepName).toBe(step1Name);
200
200
  expect(stateAfterStep1.executionHistory[0]?.output?.status).toBe('success');
201
201
  });
202
+ test('should reject invalid workflow definition with malformed JSON', () => {
203
+ const invalidJson = '{ "workflowName": "invalid", "steps": [';
204
+ expect(() => {
205
+ new engine_1.JustWorkflowItEngine({
206
+ workflowDefinition: invalidJson,
207
+ stepExecutors,
208
+ });
209
+ }).toThrow();
210
+ });
211
+ test('should reject workflow definition with missing required fields', () => {
212
+ const workflowMissingSteps = {
213
+ workflowName: 'missingSteps',
214
+ // steps field is missing
215
+ };
216
+ expect(() => {
217
+ new engine_1.JustWorkflowItEngine({
218
+ workflowDefinition: JSON.stringify(workflowMissingSteps),
219
+ stepExecutors,
220
+ });
221
+ }).toThrow();
222
+ });
223
+ test('should reject workflow definition with invalid step structure', () => {
224
+ const workflowWithInvalidStep = {
225
+ workflowName: 'invalidStep',
226
+ steps: [
227
+ {
228
+ // Missing required 'name' field
229
+ retries: 2,
230
+ timeoutSeconds: 1000,
231
+ transitionToStep: null,
232
+ integrationDetails: {
233
+ type: simpleIntegration,
234
+ },
235
+ },
236
+ ],
237
+ definitions: {},
238
+ };
239
+ expect(() => {
240
+ new engine_1.JustWorkflowItEngine({
241
+ workflowDefinition: JSON.stringify(workflowWithInvalidStep),
242
+ stepExecutors,
243
+ });
244
+ }).toThrow();
245
+ });
246
+ test('should reject workflow definition with non-existent step executor type', () => {
247
+ const workflowWithBadExecutorType = {
248
+ workflowName: 'badExecutorType',
249
+ steps: [
250
+ {
251
+ name: 'testStep',
252
+ retries: 2,
253
+ timeoutSeconds: 1000,
254
+ transitionToStep: null,
255
+ integrationDetails: {
256
+ type: 'nonExistentExecutorType',
257
+ inputDefinition: {
258
+ $ref: '#/definitions/testInput',
259
+ },
260
+ outputDefinition: {
261
+ $ref: '#/definitions/testOutput',
262
+ },
263
+ },
264
+ },
265
+ ],
266
+ definitions: {
267
+ testInput: {
268
+ type: 'object',
269
+ properties: {},
270
+ additionalProperties: false,
271
+ },
272
+ testOutput: {
273
+ type: 'object',
274
+ properties: {},
275
+ additionalProperties: false,
276
+ },
277
+ },
278
+ };
279
+ expect(() => {
280
+ new engine_1.JustWorkflowItEngine({
281
+ workflowDefinition: JSON.stringify(workflowWithBadExecutorType),
282
+ stepExecutors,
283
+ });
284
+ }).toThrow();
285
+ });
286
+ test('should reject workflow definition with invalid reference in input transformer', () => {
287
+ const workflowWithInvalidTransformer = {
288
+ workflowName: 'invalidTransformer',
289
+ steps: [
290
+ {
291
+ name: 'testStep',
292
+ retries: 2,
293
+ timeoutSeconds: 1000,
294
+ transitionToStep: null,
295
+ integrationDetails: {
296
+ type: simpleIntegration,
297
+ inputDefinition: {
298
+ $ref: '#/definitions/testInput',
299
+ },
300
+ outputDefinition: {
301
+ $ref: '#/definitions/testOutput',
302
+ },
303
+ inputTransformer: {
304
+ fieldset: [
305
+ {
306
+ from: 'nonExistentStep.someProperty',
307
+ to: 'outputProperty',
308
+ },
309
+ ],
310
+ },
311
+ },
312
+ },
313
+ ],
314
+ definitions: {
315
+ testInput: {
316
+ type: 'object',
317
+ properties: {
318
+ outputProperty: {
319
+ type: 'string',
320
+ },
321
+ },
322
+ required: ['outputProperty'],
323
+ additionalProperties: false,
324
+ },
325
+ testOutput: {
326
+ type: 'object',
327
+ properties: {},
328
+ additionalProperties: false,
329
+ },
330
+ },
331
+ };
332
+ expect(() => {
333
+ new engine_1.JustWorkflowItEngine({
334
+ workflowDefinition: JSON.stringify(workflowWithInvalidTransformer),
335
+ stepExecutors,
336
+ });
337
+ }).toThrow();
338
+ });
339
+ test('should reject workflow with array index reference that may not exist', () => {
340
+ const emptyArrayExecutor = {
341
+ type: 'emptyArrayExecutor',
342
+ execute: (_args) => Promise.resolve({
343
+ status: 'success',
344
+ payload: { items: [] },
345
+ }),
346
+ };
347
+ const secondStepExecutor = {
348
+ type: 'secondStepExecutor',
349
+ execute: (_args) => Promise.resolve({
350
+ status: 'success',
351
+ payload: {},
352
+ }),
353
+ };
354
+ const workflowWithArrayReference = {
355
+ workflowName: 'arrayReferenceWorkflow',
356
+ steps: [
357
+ {
358
+ name: 'getItems',
359
+ retries: 2,
360
+ timeoutSeconds: 1000,
361
+ transitionToStep: 'processItem',
362
+ integrationDetails: {
363
+ type: 'emptyArrayExecutor',
364
+ inputDefinition: {
365
+ $ref: '#/definitions/getItemsInput',
366
+ },
367
+ outputDefinition: {
368
+ $ref: '#/definitions/getItemsOutput',
369
+ },
370
+ },
371
+ },
372
+ {
373
+ name: 'processItem',
374
+ retries: 2,
375
+ timeoutSeconds: 1000,
376
+ transitionToStep: null,
377
+ integrationDetails: {
378
+ type: 'secondStepExecutor',
379
+ inputDefinition: {
380
+ $ref: '#/definitions/processItemInput',
381
+ },
382
+ outputDefinition: {
383
+ $ref: '#/definitions/processItemOutput',
384
+ },
385
+ inputTransformer: {
386
+ fieldset: [
387
+ {
388
+ // This references an array element that may not exist
389
+ from: 'getItemsOutput.items[0].id',
390
+ to: 'itemId',
391
+ },
392
+ ],
393
+ },
394
+ },
395
+ },
396
+ ],
397
+ definitions: {
398
+ getItemsInput: {
399
+ type: 'object',
400
+ properties: {},
401
+ additionalProperties: false,
402
+ },
403
+ getItemsOutput: {
404
+ type: 'object',
405
+ properties: {
406
+ items: {
407
+ type: 'array',
408
+ items: {
409
+ type: 'object',
410
+ properties: {
411
+ id: { type: 'string' },
412
+ },
413
+ },
414
+ },
415
+ },
416
+ required: ['items'],
417
+ additionalProperties: false,
418
+ },
419
+ processItemInput: {
420
+ type: 'object',
421
+ properties: {
422
+ itemId: { type: 'string' },
423
+ },
424
+ required: ['itemId'],
425
+ additionalProperties: false,
426
+ },
427
+ processItemOutput: {
428
+ type: 'object',
429
+ properties: {},
430
+ additionalProperties: false,
431
+ },
432
+ },
433
+ };
434
+ // Engine performs static type analysis and catches this at definition time
435
+ expect(() => {
436
+ new engine_1.JustWorkflowItEngine({
437
+ workflowDefinition: JSON.stringify(workflowWithArrayReference),
438
+ stepExecutors: [emptyArrayExecutor, secondStepExecutor],
439
+ });
440
+ }).toThrow(/Missing expected field.*items\[0\]/);
441
+ });
202
442
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justworkflowit/cdk-constructs",
3
3
  "description": "",
4
- "version": "0.0.189",
4
+ "version": "0.0.191",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {