-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46d38bf
commit 8df7e94
Showing
4 changed files
with
227 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { testSingleState, testFunction } from "@chrisdobby/step-by-step" | ||
|
||
describe("parallel tests", () => { | ||
it("should test a parallel state", async () => { | ||
const result = await testSingleState({ | ||
stateDefinition: { | ||
Type: "Parallel", | ||
End: true, | ||
Branches: [ | ||
{ | ||
StartAt: "State1", | ||
States: { | ||
State1: { | ||
QueryLanguage: "JSONata", | ||
Type: "Pass", | ||
Output: { branch: 1 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
StartAt: "State2", | ||
States: { | ||
State2: { | ||
QueryLanguage: "JSONata", | ||
Type: "Pass", | ||
Output: { branch: 2 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect(result.status).toBe("SUCCEEDED") | ||
expect(result.output).toEqual([{ branch: 1 }, { branch: 2 }]) | ||
expect(result.stack).toHaveLength(2) | ||
}) | ||
|
||
it("should test nested parallel states", async () => { | ||
const result = await testSingleState({ | ||
stateDefinition: { | ||
Type: "Parallel", | ||
End: true, | ||
Branches: [ | ||
{ | ||
StartAt: "State1", | ||
States: { | ||
State1: { | ||
QueryLanguage: "JSONata", | ||
Type: "Pass", | ||
Output: { branch: 1 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
StartAt: "State2", | ||
States: { | ||
State2: { | ||
Type: "Parallel", | ||
End: true, | ||
Branches: [ | ||
{ | ||
StartAt: "State2-1", | ||
States: { | ||
"State2-1": { | ||
QueryLanguage: "JSONata", | ||
Type: "Pass", | ||
Output: { branch: 2, subBranch: 1 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
StartAt: "State2-2", | ||
States: { | ||
"State2-2": { | ||
QueryLanguage: "JSONata", | ||
Type: "Pass", | ||
Output: { branch: 2, subBranch: 2 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect(result.status).toBe("SUCCEEDED") | ||
expect(result.output).toEqual([ | ||
{ branch: 1 }, | ||
[ | ||
{ branch: 2, subBranch: 1 }, | ||
{ branch: 2, subBranch: 2 }, | ||
], | ||
]) | ||
expect(result.stack).toHaveLength(4) | ||
}) | ||
|
||
it("should test a parallel state as part of a function", async () => { | ||
const result = await testFunction({ | ||
functionDefinition: { | ||
QueryLanguage: "JSONata", | ||
StartAt: "ParallelState", | ||
States: { | ||
ParallelState: { | ||
Type: "Parallel", | ||
Next: "CombineResults", | ||
Branches: [ | ||
{ | ||
StartAt: "State1", | ||
States: { | ||
State1: { | ||
Type: "Pass", | ||
Output: { branch: 1 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
StartAt: "State2", | ||
States: { | ||
State2: { | ||
Type: "Pass", | ||
Output: { branch: 2 }, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
CombineResults: { | ||
Type: "Pass", | ||
End: true, | ||
QueryLanguage: "JSONPath", | ||
Parameters: { | ||
"output1.$": "$[0]", | ||
"output2.$": "$[1]", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
expect(result.status).toBe("SUCCEEDED") | ||
expect(result.stack).toHaveLength(4) | ||
expect(result.output).toEqual({ output1: { branch: 1 }, output2: { branch: 2 } }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters