Skip to content

Commit

Permalink
Merge pull request #66 from nibble-4bits/refactor-13
Browse files Browse the repository at this point in the history
Refactor 13
  • Loading branch information
nibble-4bits authored Sep 11, 2023
2 parents f5f79a7 + 125b850 commit dcce1dc
Show file tree
Hide file tree
Showing 14 changed files with 4,606 additions and 4,202 deletions.
48 changes: 42 additions & 6 deletions __tests__/stateActions/MapStateAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ describe('Map State', () => {
],
};
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const { stateResult } = await mapStateAction.execute(input, context);
const { stateResult } = await mapStateAction.execute(input, context, options);

expect(stateResult).toHaveLength(3);
expect(stateResult).toEqual([
Expand Down Expand Up @@ -64,9 +70,15 @@ describe('Map State', () => {
{ num1: 7, num2: 4 },
];
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const { stateResult } = await mapStateAction.execute(input, context);
const { stateResult } = await mapStateAction.execute(input, context, options);

expect(stateResult).toHaveLength(3);
expect(stateResult).toEqual([
Expand Down Expand Up @@ -103,9 +115,15 @@ describe('Map State', () => {
],
};
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const { stateResult } = await mapStateAction.execute(input, context);
const { stateResult } = await mapStateAction.execute(input, context, options);

expect(stateResult).toHaveLength(3);
expect(stateResult).toEqual([
Expand Down Expand Up @@ -140,9 +158,15 @@ describe('Map State', () => {
const stateName = 'MapState';
const input = 'not an array';
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const mapStateResult = mapStateAction.execute(input, context);
const mapStateResult = mapStateAction.execute(input, context, options);

await expect(mapStateResult).rejects.toThrow(StatesRuntimeError);
await expect(mapStateResult).rejects.toThrow(
Expand All @@ -167,9 +191,15 @@ describe('Map State', () => {
const stateName = 'MapState';
const input = { items: 'not an array' };
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const mapStateResult = mapStateAction.execute(input, context);
const mapStateResult = mapStateAction.execute(input, context, options);

await expect(mapStateResult).rejects.toThrow(StatesRuntimeError);
await expect(mapStateResult).rejects.toThrow(
Expand All @@ -193,9 +223,15 @@ describe('Map State', () => {
const stateName = 'MapState';
const input = [1, 2, 3];
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const mapStateAction = new MapStateAction(definition, stateName);
const mapStateResult = mapStateAction.execute(input, context);
const mapStateResult = mapStateAction.execute(input, context, options);

await expect(mapStateResult).rejects.toThrow();
});
Expand Down
24 changes: 21 additions & 3 deletions __tests__/stateActions/ParallelStateAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ describe('Parallel State', () => {
const stateName = 'ParallelState';
const input = { value: 50 };
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const parallelStateAction = new ParallelStateAction(definition, stateName);
const { stateResult } = await parallelStateAction.execute(input, context);
const { stateResult } = await parallelStateAction.execute(input, context, options);

expect(Array.isArray(stateResult)).toBe(true);
});
Expand Down Expand Up @@ -93,9 +99,15 @@ describe('Parallel State', () => {
const stateName = 'ParallelState';
const input = { value: 50 };
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const parallelStateAction = new ParallelStateAction(definition, stateName);
const { stateResult } = await parallelStateAction.execute(input, context);
const { stateResult } = await parallelStateAction.execute(input, context, options);

expect(stateResult).toEqual([
{
Expand Down Expand Up @@ -135,9 +147,15 @@ describe('Parallel State', () => {
const stateName = 'ParallelState';
const input = { value: 50 };
const context = {};
const options = {
stateMachineOptions: undefined,
runOptions: undefined,
eventLogger: new EventLogger(),
rawInput: {},
};

const parallelStateAction = new ParallelStateAction(definition, stateName);
const parallelStateResult = parallelStateAction.execute(input, context);
const parallelStateResult = parallelStateAction.execute(input, context, options);

await expect(parallelStateResult).rejects.toThrow();
});
Expand Down
6 changes: 4 additions & 2 deletions __tests__/stateActions/TaskStateAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ describe('Task State', () => {
const stateName = 'TaskState';
const input = { input1: 'input string', input2: 10 };
const context = {};
const options = { overrideFn: undefined, awsConfig: undefined };

const taskStateAction = new TaskStateAction(definition, stateName);
await taskStateAction.execute(input, context);
await taskStateAction.execute(input, context, options);

expect(mockInvokeFunction).toHaveBeenCalledWith('mock-arn', { input1: 'input string', input2: 10 });
});
Expand All @@ -38,11 +39,12 @@ describe('Task State', () => {
const stateName = 'TaskState';
const input = { num1: 5, num2: 3 };
const context = {};
const options = { overrideFn: undefined, awsConfig: undefined };

mockInvokeFunction.mockReturnValue(input.num1 + input.num2);

const taskStateAction = new TaskStateAction(definition, stateName);
const { stateResult } = await taskStateAction.execute(input, context);
const { stateResult } = await taskStateAction.execute(input, context, options);

expect(mockInvokeFunction).toHaveBeenCalledWith('mock-arn', { num1: 5, num2: 3 });
expect(stateResult).toBe(8);
Expand Down
40 changes: 32 additions & 8 deletions __tests__/stateActions/WaitStateAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ describe('Wait State', () => {
const stateName = 'WaitState';
const input = { prop1: 'test', prop2: 12345 };
const context = {};
const abortSignal = new AbortController().signal;
const options = {
abortSignal,
rootAbortSignal: undefined,
waitTimeOverrideOption: undefined,
};

const waitStateAction = new WaitStateAction(definition, stateName);
const { stateResult } = await waitStateAction.execute(input, context);
const { stateResult } = await waitStateAction.execute(input, context, options);

expect(mockSleepFunction).toHaveBeenCalledWith(10000, undefined, undefined);
expect(mockSleepFunction).toHaveBeenCalledWith(10000, abortSignal, undefined);
expect(stateResult).toEqual({ prop1: 'test', prop2: 12345 });
});

Expand All @@ -41,11 +47,17 @@ describe('Wait State', () => {
const stateName = 'WaitState';
const input = { prop1: 'test', prop2: 12345 };
const context = {};
const abortSignal = new AbortController().signal;
const options = {
abortSignal,
rootAbortSignal: undefined,
waitTimeOverrideOption: undefined,
};

const waitStateAction = new WaitStateAction(definition, stateName);
const { stateResult } = await waitStateAction.execute(input, context);
const { stateResult } = await waitStateAction.execute(input, context, options);

expect(mockSleepFunction).toHaveBeenCalledWith(20700000, undefined, undefined);
expect(mockSleepFunction).toHaveBeenCalledWith(20700000, abortSignal, undefined);
expect(stateResult).toEqual({ prop1: 'test', prop2: 12345 });
});

Expand All @@ -58,11 +70,17 @@ describe('Wait State', () => {
const stateName = 'WaitState';
const input = { waitFor: 10 };
const context = {};
const abortSignal = new AbortController().signal;
const options = {
abortSignal,
rootAbortSignal: undefined,
waitTimeOverrideOption: undefined,
};

const waitStateAction = new WaitStateAction(definition, stateName);
const { stateResult } = await waitStateAction.execute(input, context);
const { stateResult } = await waitStateAction.execute(input, context, options);

expect(mockSleepFunction).toHaveBeenCalledWith(10000, undefined, undefined);
expect(mockSleepFunction).toHaveBeenCalledWith(10000, abortSignal, undefined);
expect(stateResult).toEqual({ waitFor: 10 });
});

Expand All @@ -75,11 +93,17 @@ describe('Wait State', () => {
const stateName = 'WaitState';
const input = { waitUntil: '2022-12-05T05:45:00Z' };
const context = {};
const abortSignal = new AbortController().signal;
const options = {
abortSignal,
rootAbortSignal: undefined,
waitTimeOverrideOption: undefined,
};

const waitStateAction = new WaitStateAction(definition, stateName);
const { stateResult } = await waitStateAction.execute(input, context);
const { stateResult } = await waitStateAction.execute(input, context, options);

expect(mockSleepFunction).toHaveBeenCalledWith(20700000, undefined, undefined);
expect(mockSleepFunction).toHaveBeenCalledWith(20700000, abortSignal, undefined);
expect(stateResult).toEqual({ waitUntil: '2022-12-05T05:45:00Z' });
});

Expand Down
Loading

0 comments on commit dcce1dc

Please sign in to comment.