Skip to content

Commit 44e66cf

Browse files
support mocks generated by function
1 parent 240b333 commit 44e66cf

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
---
44

5+
## [0.1.2] 2022-03-28
6+
7+
### Added
8+
9+
- Added support for function generated mocks
10+
- Added support for accepting cli input for function generated mocks
11+
12+
13+
514
## [0.1.0] 2022-03-27
615

716
### Added

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ module.exports = {
6464
'background-task': {
6565
'my-first-mock': { /* payload */ },
6666
'another-mock': { /* payload */ },
67+
'function-mock': (id) => {
68+
return { /* payload */ }
69+
}
6770
}
6871
},
6972
queues: {

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)