Skip to content

Commit 448279b

Browse files
support mocks generated by function
1 parent 240b333 commit 448279b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
let { cwd, preferences } = inv._project
1515
let jsonMocks = join(cwd, 'sandbox-invoke-mocks.json')
1616
let jsMocks = join(cwd, 'sandbox-invoke-mocks.js')
17+
let inputPromptOpen = false
1718

1819
let pragmas = [ 'events', 'queues', 'scheduled', 'tables-streams' ]
1920
let prefs = preferences?.sandbox?.invoker
@@ -45,7 +46,7 @@ module.exports = {
4546
strong: colors.white,
4647
}
4748
}
48-
if (input === 'i') {
49+
if (input === 'i' && !inputPromptOpen) {
4950
if (Object.keys(events).length === 1) {
5051
let none = 'No Lambdas found to invoke'
5152
if (pragmas.length) update.status(none, `Using the following pragmas: @${pragmas.join(', @')}`)
@@ -91,6 +92,21 @@ module.exports = {
9192
}, options)
9293
mockName = selection.mock
9394
userPayload = mocks[pragma][name][mockName] || {}
95+
96+
if (typeof userPayload === "function") {
97+
inputPromptOpen = true;
98+
let { mockinput } = await prompt(
99+
{
100+
type: "input",
101+
name: "mockinput",
102+
message: "What input to use for mock function?",
103+
},
104+
options
105+
);
106+
inputPromptOpen = false;
107+
let mockInputArgs = mockinput.split(",");
108+
userPayload = userPayload(...mockInputArgs);
109+
}
94110
}
95111

96112
let payload

0 commit comments

Comments
 (0)