From e6c2f153b7130e27168b2aaa0c7aba88a9220332 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 14 May 2024 11:48:17 +0200 Subject: [PATCH 1/2] fix(functions-test): Fix mockHttpEvent for null bodies --- packages/testing/src/api/apiFunction.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/testing/src/api/apiFunction.ts b/packages/testing/src/api/apiFunction.ts index ae77d97ba6c6..62d4770ebd69 100644 --- a/packages/testing/src/api/apiFunction.ts +++ b/packages/testing/src/api/apiFunction.ts @@ -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, From d56f1911624e2ffed727bcc4596303967386ba04 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 14 May 2024 13:49:34 +0200 Subject: [PATCH 2/2] changeset --- .changesets/10570.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changesets/10570.md diff --git a/.changesets/10570.md b/.changesets/10570.md new file mode 100644 index 000000000000..679568957b17 --- /dev/null +++ b/.changesets/10570.md @@ -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.