Skip to content

Commit

Permalink
Merge pull request #24 from aleios-cloud/feat/stateMachine-arn-helper
Browse files Browse the repository at this point in the history
Feat/state machine arn helper
  • Loading branch information
Alexander White authored Jan 27, 2022
2 parents 588921c + 319438a commit f175ab0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
15 changes: 5 additions & 10 deletions src/assertions/toHaveCompletedExecutionWithStatus/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { testResult, TestResultOutput } from "../../utils/testResult";
import StepFunctions from "../../helpers/stepFunctions";

import * as AWS from "aws-sdk";

Expand All @@ -8,16 +9,10 @@ export default {
expectedStatus: string
): Promise<TestResultOutput> {
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: any) => stateMachine.name === stateMachineName
);
const smArn = smList[0].stateMachineArn;

const stepFunctionsObject = await StepFunctions.build();
const smArn = await stepFunctionsObject.obtainStateMachineArn(stateMachineName);

const listExecutionsParams = { stateMachineArn: smArn };
// Get all executions of specified state machine
const smExecutions = await stepFunctions
Expand Down
14 changes: 5 additions & 9 deletions src/assertions/toMatchStateMachineOutput/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { testResult, TestResultOutput } from "utils/testResult";
import { testResult, TestResultOutput } from "../../utils/testResult";
import { StepFunctions as AWSStepFunctions } from "aws-sdk";
import StepFunctions from "../../helpers/stepFunctions";

export default {
async toMatchStateMachineOutput(
stateMachineName: string,
expectedOutput: any
): Promise<TestResultOutput> {
const stepFunctions = new AWSStepFunctions();
const allStateMachines = await stepFunctions.listStateMachines().promise();

const smList = allStateMachines.stateMachines.filter(
(stateMachine: any) => stateMachine.name === stateMachineName
);

const stateMachineArn = smList[0].stateMachineArn;
const listExecParams = { stateMachineArn: stateMachineArn };
const stepFunctionsObject = await StepFunctions.build();
const smArn = await stepFunctionsObject.obtainStateMachineArn(stateMachineName);
const listExecParams = { stateMachineArn: smArn };
const executionList = await stepFunctions
.listExecutions(listExecParams)
.promise();
Expand Down
23 changes: 23 additions & 0 deletions src/helpers/stepFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,27 @@ export default class StepFunctions {
.describeExecution({ executionArn: execution.executionArn })
.promise();
}

async obtainStateMachineArn(stateMachineName: string): Promise<string> {

const listStateMachineParams = {};
// Get all state machines
if (this.stepFunctions === undefined) {
throw new Error(
"The Step Functions client is undefined. You might have forgotten to run build()."
);
}
const allStateMachines = await this.stepFunctions
.listStateMachines(listStateMachineParams)
.promise();
// Find state machine with specified name and get its arn
const smList = allStateMachines.stateMachines.find(
(stateMachine: any) => stateMachine.name === stateMachineName
);
if (smList == null)
throw new Error(
"No matching state machine. "
);
return smList.stateMachineArn;
}
}

0 comments on commit f175ab0

Please sign in to comment.