Skip to content

Commit 739b010

Browse files
karagulamoseduardoboucaskodiakhq[bot]
authoredJan 11, 2022
fix: identity default for function:invoke w/o arg (#3971)
* fix: identity default for function:invoke w/o arg * Update src/commands/functions/functions-invoke.js Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent e4236e3 commit 739b010

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed
 

‎src/commands/functions/functions-invoke.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const events = [
2323
'identity-signup',
2424
'identity-login',
2525
]
26+
2627
const eventTriggeredFunctions = new Set([...events, ...events.map((name) => `${name}${BACKGROUND}`)])
2728

2829
const DEFAULT_PORT = 8888
@@ -186,20 +187,8 @@ const functionsInvoke = async (nameArgument, options, command) => {
186187
}
187188
} else {
188189
// NOT an event triggered function, but may still want to simulate authentication locally
189-
let isAuthenticated = false
190-
if (typeof options.identity === 'undefined') {
191-
const { isAuthed } = await inquirer.prompt([
192-
{
193-
type: 'confirm',
194-
name: 'isAuthed',
195-
message: `Invoke with emulated Netlify Identity authentication headers? (pass --identity/--no-identity to override)`,
196-
default: true,
197-
},
198-
])
199-
isAuthenticated = isAuthed
200-
} else {
201-
isAuthenticated = options.identity
202-
}
190+
const isAuthenticated = Boolean(options.identity)
191+
203192
if (isAuthenticated) {
204193
headers = {
205194
authorization:

‎tests/command.functions.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ const { withMockApi } = require('./utils/mock-api')
1616
const { killProcess } = require('./utils/process')
1717
const { withSiteBuilder } = require('./utils/site-builder')
1818

19+
test('should return function response when invoked with no identity argument', async (t) => {
20+
await withSiteBuilder('function-invoke-with-no-identity-argument', async (builder) => {
21+
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({
22+
path: 'test-invoke.js',
23+
handler: async () => ({
24+
statusCode: 200,
25+
body: 'success',
26+
}),
27+
})
28+
29+
await builder.buildAsync()
30+
31+
await withDevServer({ cwd: builder.directory }, async (server) => {
32+
const stdout = await callCli(['functions:invoke', 'test-invoke', `--port=${server.port}`], {
33+
cwd: builder.directory,
34+
})
35+
t.is(stdout, 'success')
36+
})
37+
})
38+
})
39+
1940
test('should return function response when invoked', async (t) => {
2041
await withSiteBuilder('site-with-ping-function', async (builder) => {
2142
builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({

1 commit comments

Comments
 (1)

github-actions[bot] commented on Jan 11, 2022

@github-actions[bot]

📊 Benchmark results

Package size: 356 MB

Please sign in to comment.