Skip to content

Commit 1961238

Browse files
committed
add readme and LICENSE
1 parent 905b121 commit 1961238

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Ken Fukuyama
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# stepfunctions-testing
1+
# Step Functions Testing Library
22

3+
## Features
4+
5+
- Create a [MockConfigFile](https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-test-sm-exec.html) with JavaScript
6+
7+
8+
### Install
9+
10+
```sh
11+
npm i stepfunctions-testing
12+
```
13+
## Usage
14+
15+
### Creating a mocked response
16+
17+
#### `Return` a response
18+
19+
```js
20+
const checkIdentityLambdaMockedSuccess = new MockedResponse(
21+
'CheckIdentityLambdaMockedSuccess'
22+
).return<any>({
23+
StatusCode: 200,
24+
Payload: {
25+
statusCode: 200,
26+
body: JSON.stringify({
27+
approved: true,
28+
message: 'identity validation passed',
29+
}),
30+
},
31+
});
32+
```
33+
34+
#### `Throw` a response
35+
36+
```js
37+
const checkIdentityLambdaMockedThrowError = new MockedResponse(
38+
'CheckIdentityLambdaMockedThrowError'
39+
).throw('CustomValidationError', 'Check Identity Validation Failed');
40+
```
41+
42+
#### Repeating responses
43+
44+
```js
45+
const checkIdentityLambdaMockedThrowError = new MockedResponse(
46+
'CheckIdentityLambdaMockedThrowError'
47+
).throw('CustomValidationError', 'Check Identity Validation Failed', /* repeat the response 3 times. total becomes 4 */ 3);
48+
```
49+
50+
### Full example
51+
52+
```js
53+
// Create mocked responses
54+
const checkIdentityLambdaMockedSuccess = new MockedResponse(
55+
'CheckIdentityLambdaMockedSuccess'
56+
).return<any>({
57+
StatusCode: 200,
58+
Payload: {
59+
statusCode: 200,
60+
body: JSON.stringify({
61+
approved: true,
62+
message: 'identity validation passed',
63+
}),
64+
},
65+
});
66+
67+
const checkAddressLambdaMockedSuccess = new MockedResponse(
68+
'CheckAddressLambdaMockedSuccess'
69+
).return<any>({
70+
StatusCode: 200,
71+
Payload: {
72+
statusCode: 200,
73+
body: JSON.stringify({
74+
approved: true,
75+
message: 'address validation passed',
76+
}),
77+
},
78+
});
79+
80+
// Create a state machine test definition
81+
const stateMachineTestDefinition = new StateMachineTestDefinition('SomeStateMachineName')
82+
.addTestCase(
83+
new StateMachineTestCase('HappyPathTest')
84+
.withInput(input)
85+
.addMockedState(
86+
'CheckIdentity',
87+
checkIdentityLambdaMockedSuccess
88+
)
89+
.addMockedState(
90+
'CheckAddress',
91+
checkAddressLambdaMockedSuccess
92+
)
93+
);
94+
95+
// Create a config
96+
const config = new StepFunctionsMockConfig()
97+
.addTestDefinition(stateMachineTestDefinition);
98+
99+
// Convert the config object to JSON
100+
// You can write this down to a file to be used by step functions local
101+
config.toJSON();
102+
```
103+
104+
## License
105+
106+
stepfunctions-testing is available under the terms of [MIT License](./LICENSE)

0 commit comments

Comments
 (0)