Skip to content

Commit

Permalink
more cases are contemplated in the payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanelutti committed Jan 11, 2023
1 parent 4b3231b commit 091d1da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/handler.js
Expand Up @@ -53,10 +53,10 @@ module.exports = class Handler {

await this.emitEnded();

if(!stateMachine)
if(!stateMachine || !result || (!result?.session && !result?.body))
return result;

if(StepFunction.dataExceedsLimit(result?.body))
if(StepFunction.dataExceedsLimit(result.body))
result.body = await Lambda.bodyToS3Path('step-function-payloads', result.body, dispatcher.payloadFixedProperties);

['body', 'session'].forEach(defaultField => {
Expand Down
46 changes: 44 additions & 2 deletions tests/handler.js
Expand Up @@ -387,7 +387,7 @@ describe('Handler', () => {
sinon.assert.calledOnceWithExactly(Lambda.bodyToS3Path, 'step-function-payloads', body, []);
});

it('Should use a default value when the payload has no session or body and the lambda is executed as a step function', async () => {
it('Should return the same value when the payload has no session and body and the lambda is executed as a step function', async () => {

const stateMachine = {
id: 'id-state-machine',
Expand All @@ -403,7 +403,49 @@ describe('Handler', () => {
assert.deepStrictEqual(await Handler.handle(
LambdaFunctionExample,
{ stateMachine }
), { session: null, body: null, stateMachine });
), {});
});

it('Should use a default value when the payload has no body and the lambda is executed as a step function', async () => {

const stateMachine = {
id: 'id-state-machine',
name: 'state-machine-test'
};
class LambdaFunctionExample {

process() {
return {
session: 'session'
};
}
}

assert.deepStrictEqual(await Handler.handle(
LambdaFunctionExample,
{ stateMachine }
), { session: 'session', body: null, stateMachine });
});

it('Should use a default value when the payload has no sessions and the lambda is executed as a step function', async () => {

const stateMachine = {
id: 'id-state-machine',
name: 'state-machine-test'
};
class LambdaFunctionExample {

process() {
return {
body: {}
};
}
}

assert.deepStrictEqual(await Handler.handle(
LambdaFunctionExample,
{ stateMachine }
), { session: null, body: {}, stateMachine });
});
});
});

0 comments on commit 091d1da

Please sign in to comment.