Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-stepfunctions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.30",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0"
},
"dependencies": {
Expand All @@ -87,6 +85,14 @@
"@aws-cdk/core": "0.0.0",
"constructs": "^2.0.0"
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 75,
"statements": 80
}
}
},
"engines": {
"node": ">= 10.12.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { expect, haveResource } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as stepfunctions from '../lib';

export = {
'instantiate Activity'(test: Test) {
describe('Activity', () => {
test('instantiate Activity', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new stepfunctions.Activity(stack, 'Activity');

// THEN
expect(stack).to(haveResource('AWS::StepFunctions::Activity', {
expect(stack).toHaveResource('AWS::StepFunctions::Activity', {
Name: 'Activity'
}));

test.done();
},
});
});

'Activity exposes metrics'(test: Test) {
test('Activity exposes metrics', () => {
// GIVEN
const stack = new cdk.Stack();

Expand All @@ -32,18 +29,16 @@ export = {
namespace: 'AWS/States',
dimensions: { ActivityArn: { Ref: 'Activity04690B0A' }},
};
test.deepEqual(stack.resolve(activity.metricRunTime()), {
expect((stack.resolve(activity.metricRunTime()))).toEqual({
...sharedMetric,
metricName: 'ActivityRunTime',
statistic: 'Average'
});

test.deepEqual(stack.resolve(activity.metricFailed()), {
expect(stack.resolve(activity.metricFailed())).toEqual({
...sharedMetric,
metricName: 'ActivitiesFailed',
statistic: 'Sum'
});

test.done();
}
};
});
});
45 changes: 45 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/condition.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import '@aws-cdk/assert/jest';
import * as stepfunctions from '../lib';

describe('Condition Variables', () => {
test('Condition variables must start with $. or $[', () => {
expect(() => stepfunctions.Condition.stringEquals('a', 'b')).toThrow();
}),
test('Condition variables can start with $.', () => {
expect(() => stepfunctions.Condition.stringEquals('$.a', 'b')).not.toThrow();
}),
test('Condition variables can start with $[', () => {
expect(() => stepfunctions.Condition.stringEquals('$[0]', 'a')).not.toThrow();
}),
test('NotConditon must render properly', () => {
assertRendersTo(stepfunctions.Condition.not(stepfunctions.Condition.stringEquals('$.a', 'b')), { Not: { Variable: '$.a', StringEquals: 'b' } });
}),
test('CompoundCondition must render properly', () => {
assertRendersTo(
stepfunctions.Condition.and(stepfunctions.Condition.booleanEquals('$.a', true), stepfunctions.Condition.numberGreaterThan('$.b', 3)),
{
And: [
{ Variable: '$.a', BooleanEquals: true },
{ Variable: '$.b', NumericGreaterThan: 3 },
],
}
);
}),
test('Exercise a number of other conditions', () => {
const cases: Array<[stepfunctions.Condition, object]> = [
[stepfunctions.Condition.stringLessThan('$.a', 'foo'), { Variable: '$.a', StringLessThan: 'foo' }],
[stepfunctions.Condition.stringLessThanEquals('$.a', 'foo'), { Variable: '$.a', StringLessThanEquals: 'foo' }],
[stepfunctions.Condition.stringGreaterThan('$.a', 'foo'), { Variable: '$.a', StringGreaterThan: 'foo' }],
[stepfunctions.Condition.stringGreaterThanEquals('$.a', 'foo'), { Variable: '$.a', StringGreaterThanEquals: 'foo' }],
[stepfunctions.Condition.numberEquals('$.a', 5), { Variable: '$.a', NumericEquals: 5 }],
];

for (const [cond, expected] of cases) {
assertRendersTo(cond, expected);
}
});
});

function assertRendersTo(cond: stepfunctions.Condition, expected: any) {
expect(cond.renderCondition()).toStrictEqual(expected);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import '@aws-cdk/assert/jest';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as stepfunctions from '../lib';

export = {
'Props are optional'(test: Test) {
describe('Fail State', () => {
test('Props are optional', () => {
const stack = new cdk.Stack();

new stepfunctions.Fail(stack, 'Fail');

test.done();
}
};
});
});
129 changes: 129 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/fields.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import '@aws-cdk/assert/jest';
import { Context, Data, FieldUtils } from '../lib';

describe('Fields', () => {
test('deep replace correctly handles fields in arrays', () => {
expect(
FieldUtils.renderObject({
unknown: undefined,
bool: true,
literal: 'literal',
field: Data.stringAt('$.stringField'),
listField: Data.listAt('$.listField'),
deep: [
'literal',
{
deepField: Data.numberAt('$.numField'),
},
],
})
).toStrictEqual({
'bool': true,
'literal': 'literal',
'field.$': '$.stringField',
'listField.$': '$.listField',
'deep': [
'literal',
{
'deepField.$': '$.numField',
},
],
});
}),
test('exercise contextpaths', () => {
expect(
FieldUtils.renderObject({
str: Context.stringAt('$$.Execution.StartTime'),
count: Context.numberAt('$$.State.RetryCount'),
token: Context.taskToken,
entire: Context.entireContext,
})
).toStrictEqual({
'str.$': '$$.Execution.StartTime',
'count.$': '$$.State.RetryCount',
'token.$': '$$.Task.Token',
'entire.$': '$$',
});
}),
test('find all referenced paths', () => {
expect(
FieldUtils.findReferencedPaths({
bool: false,
literal: 'literal',
field: Data.stringAt('$.stringField'),
listField: Data.listAt('$.listField'),
deep: [
'literal',
{
field: Data.stringAt('$.stringField'),
deepField: Data.numberAt('$.numField'),
},
],
})
).toStrictEqual(['$.listField', '$.numField', '$.stringField']);
}),
test('cannot have JsonPath fields in arrays', () => {
expect(() => FieldUtils.renderObject({
deep: [Data.stringAt('$.hello')],
})).toThrowError(/Cannot use JsonPath fields in an array/);
}),
test('datafield path must be correct', () => {
expect(Data.stringAt('$')).toBeDefined();

expect(() => Data.stringAt('$hello')).toThrowError(/exactly equal to '\$' or start with '\$.'/);

expect(() => Data.stringAt('hello')).toThrowError(/exactly equal to '\$' or start with '\$.'/);
}),
test('context path must be correct', () => {
expect(Context.stringAt('$$')).toBeDefined();

expect(() => Context.stringAt('$$hello')).toThrowError(/exactly equal to '\$\$' or start with '\$\$.'/);

expect(() => Context.stringAt('hello')).toThrowError(/exactly equal to '\$\$' or start with '\$\$.'/);
}),
test('test contains task token', () => {
expect(true).toEqual(
FieldUtils.containsTaskToken({
field: Context.taskToken,
})
);

expect(true).toEqual(
FieldUtils.containsTaskToken({
field: Context.stringAt('$$.Task'),
})
);

expect(true).toEqual(
FieldUtils.containsTaskToken({
field: Context.entireContext,
})
);

expect(false).toEqual(
FieldUtils.containsTaskToken({
oops: 'not here',
})
);

expect(false).toEqual(
FieldUtils.containsTaskToken({
oops: Context.stringAt('$$.Execution.StartTime'),
})
);
}),
test('arbitrary JSONPath fields are not replaced', () => {
expect(
FieldUtils.renderObject({
field: '$.content',
})
).toStrictEqual({
field: '$.content',
});
}),
test('fields cannot be used somewhere in a string interpolation', () => {
expect(() => FieldUtils.renderObject({
field: `contains ${Data.stringAt('$.hello')}`,
})).toThrowError(/Field references must be the entire string/);
});
});
Loading