Skip to content

Commit

Permalink
Return context and request objects from /api/hello
Browse files Browse the repository at this point in the history
  • Loading branch information
paulshryock committed Jul 13, 2024
1 parent c44bd24 commit 14835c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/routes/api/hello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
}
5 changes: 0 additions & 5 deletions tests/unit/routes/api/hello.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
))
})

0 comments on commit 14835c8

Please sign in to comment.