Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(functions-test): Fix mockHttpEvent for null bodies #10570

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changesets/10570.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- fix(functions-test): Fix mockHttpEvent for null bodies (#10570) by @Tobbe

With an empty/null payload (which it is by default) the body should be empty, not the string `'null'`

This is a breaking change for anyone who was depending on the current "null" behavior in their api function tests. More specifically, if you're **NOT** passing `body` or `payload` to `mockHttpEvent({ ... })` or if you're trying to explicitly set `payload` to `null` you might have to update your tests.
9 changes: 6 additions & 3 deletions packages/testing/src/api/apiFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export const mockHttpEvent = ({
const payloadAsString =
typeof payload === 'string' ? payload : JSON.stringify(payload)

const body = isBase64Encoded
? Buffer.from(payloadAsString || '').toString('base64')
: payloadAsString
const body =
payload === null
? null
: isBase64Encoded
? Buffer.from(payloadAsString || '').toString('base64')
: payloadAsString

return {
body,
Expand Down
Loading