Skip to content

Commit 41cacaf

Browse files
committed
fix: direct invoke
1 parent b255366 commit 41cacaf

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,11 @@ const runDirect = wrap(processTask)
9393
.with(secrets, { name: getSecretName })
9494
.with(helixStatus);
9595

96-
function isSqsEvent(event, context) {
97-
if (Array.isArray(event?.Records)) {
98-
return true;
99-
}
100-
if (Array.isArray(context?.invocation?.event?.Records)) {
101-
return true;
102-
}
103-
return typeof event?.type !== 'string';
96+
function isSqsEvent(event) {
97+
return Array.isArray(event?.Records);
10498
}
10599

106100
export const main = async (event, context) => {
107-
const handler = isSqsEvent(event, context) ? runSQS : runDirect;
101+
const handler = isSqsEvent(event) ? runSQS : runDirect;
108102
return handler(event, context);
109103
};

test/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,25 @@ describe('Index Tests', () => {
195195
expect(resp.status).to.equal(200);
196196
expect(directContext.log.info.calledWith('Found task handler for type: dummy')).to.be.true;
197197
});
198+
199+
it('treats direct invocation with context invocation records as direct', async () => {
200+
const directContext = {
201+
...context,
202+
invocation: {
203+
event: {
204+
Records: [{
205+
body: JSON.stringify({ fake: 'value' }),
206+
}],
207+
},
208+
},
209+
};
210+
const directEvent = {
211+
type: 'dummy',
212+
siteId: 'direct-site',
213+
};
214+
215+
const resp = await main(directEvent, directContext);
216+
expect(resp.status).to.equal(200);
217+
expect(directContext.log.info.calledWith('Found task handler for type: dummy')).to.be.true;
218+
});
198219
});

0 commit comments

Comments
 (0)