Skip to content

Commit

Permalink
Get toHaveCompletedExecutionWithStatus() assertion working.
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhamiltondev committed Jan 21, 2022
1 parent 0fbdd80 commit 6371edf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/assertions/toHaveCompletedExecutionWithStatus/index.js
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
);
},
};

0 comments on commit 6371edf

Please sign in to comment.