1 | import tap from 'tap'
|
2 |
|
3 | import { wrapHandler } from '../lib/wrapHandler'
|
4 | import { AWS } from '../lib/types'
|
5 |
|
6 | const context = {} as AWS['HandlerContext']
|
7 |
|
8 | function stubEvent(props: Partial<AWS['HandlerEvent']>): AWS['HandlerEvent'] {
|
9 | return {
|
10 | rawUrl: '',
|
11 | rawQuery: '',
|
12 | path: '',
|
13 | httpMethod: 'GET',
|
14 | headers: {},
|
15 | multiValueHeaders: {},
|
16 | queryStringParameters: null,
|
17 | multiValueQueryStringParameters: {},
|
18 | body: null,
|
19 | isBase64Encoded: false,
|
20 | ...props,
|
21 | }
|
22 | }
|
23 |
|
24 | tap.test('wrapHandler', async (t) => {
|
25 | t.plan(2)
|
26 |
|
27 | const handler = wrapHandler({
|
28 | route: '/:slug',
|
29 | async handler(event, context) {
|
30 | t.equal(event.routeParameters.slug, 'foo')
|
31 | return {
|
32 | body: 'foo',
|
33 | }
|
34 | },
|
35 | })
|
36 |
|
37 | const response = await handler(
|
38 | stubEvent({
|
39 | path: '/foo',
|
40 | }),
|
41 | context
|
42 | )
|
43 |
|
44 | t.equal(response.body, 'foo')
|
45 | })
|