From 14835c88fa213d60c527066e60885669c143df88 Mon Sep 17 00:00:00 2001 From: Paul Shryock Date: Sat, 13 Jul 2024 11:10:32 -0400 Subject: [PATCH] Return context and request objects from /api/hello --- src/routes/api/hello.ts | 13 ++++++++----- tests/unit/routes/api/hello.test.ts | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/routes/api/hello.ts b/src/routes/api/hello.ts index 1f346be..0af227c 100644 --- a/src/routes/api/hello.ts +++ b/src/routes/api/hello.ts @@ -3,11 +3,14 @@ import type { Context } from '@netlify/functions' /** * Says hello. * - * @param {Request} _request HTTP request. - * @param {Context} _context Netlify function context. - * @return {Response} HTTP response. + * @param {Request} request HTTP request. + * @param {Context} context Netlify function context. + * @return {Response} HTTP response. * @since unreleased */ -export default function hello(_request: Request, _context: Context): Response { - return new Response('Hello, world!', { status: 200, statusText: 'OK' }) +export default function hello(request: Request, context: Context): Response { + return new Response(JSON.stringify({ context, request }), { + status: 200, + statusText: 'OK', + }) } diff --git a/tests/unit/routes/api/hello.test.ts b/tests/unit/routes/api/hello.test.ts index 0d92c17..7a3bb9f 100644 --- a/tests/unit/routes/api/hello.test.ts +++ b/tests/unit/routes/api/hello.test.ts @@ -8,9 +8,4 @@ describe('GET /api/hello', () => { it('should return a 200 status code', () => expect(hello({} as Request, {} as Context).status).toBe(200)) - - it('should return response text of "Hello, world!"', async () => - expect(await hello({} as Request, {} as Context).text()).toBe( - 'Hello, world!', - )) })