-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get toHaveCompletedExecutionWithStatus() assertion working.
- Loading branch information
1 parent
0fbdd80
commit 6371edf
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/assertions/toHaveCompletedExecutionWithStatus/index.js
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,36 @@ | ||
import { testResult } from "../../utils/testResult"; | ||
|
||
const AWS = require("aws-sdk"); | ||
|
||
export default { | ||
async toHaveCompletedExecutionWithStatus(stateMachineName, expectedStatus) { | ||
const stepFunctions = new AWS.StepFunctions(); | ||
const listStateMachineParams = {}; | ||
// Get all state machines | ||
const allStateMachines = await stepFunctions | ||
.listStateMachines(listStateMachineParams) | ||
.promise(); | ||
// Find state machine with specified name and get its arn | ||
const smList = allStateMachines.stateMachines.filter( | ||
(stateMachine) => stateMachine.name === stateMachineName | ||
); | ||
const smArn = smList[0].stateMachineArn; | ||
const listExecutionsParams = { stateMachineArn: smArn }; | ||
// Get all executions of specified state machine | ||
const smExecutions = await stepFunctions | ||
.listExecutions(listExecutionsParams) | ||
.promise(); | ||
// Get the latest execution (list ordered in reverse chronological) | ||
const latestExecution = smExecutions.executions[0]; | ||
if (latestExecution.status === expectedStatus) { | ||
return testResult( | ||
`Execution status is ${expectedStatus}, as expected.`, | ||
true | ||
); | ||
} | ||
return testResult( | ||
`Execution status was ${latestExecution.status}, where it was expected to be ${expectedStatus}`, | ||
false | ||
); | ||
}, | ||
}; |