1
1
import Koa from 'koa' ;
2
2
import Router from '@koa/router' ;
3
+ import koaBody from 'koa-body' ;
3
4
import serverlessAdapter from '../src' ;
4
5
import { defaultContext , defaultEvent } from './fixtures/fcContext' ;
5
6
@@ -8,27 +9,26 @@ describe('koa', () => {
8
9
let router : Router ;
9
10
beforeEach ( ( ) => {
10
11
app = new Koa ( ) ;
12
+ app . use ( koaBody ( ) ) ;
11
13
router = new Router ( ) ;
12
14
} ) ;
13
15
14
16
it ( 'basic middleware should set statusCode and default body' , async ( ) => {
15
17
router . get ( '/api/test' , ( ctx ) => {
16
- ctx . status = 200 ;
17
- ctx . body = 'Hello, world!' ;
18
+ ctx . status = 418 ;
19
+ ctx . body = 'Hello, world koa !' ;
18
20
} ) ;
19
21
app . use ( router . routes ( ) ) ;
20
22
21
23
const response = await serverlessAdapter ( app ) ( defaultEvent , defaultContext ) ;
22
24
23
25
expect ( response . statusCode ) . toEqual ( 418 ) ;
24
- expect ( response . body ) . toEqual ( `I'm a teapot` ) ;
26
+ expect ( response . body ) . toEqual ( 'Hello, world koa!' ) ;
25
27
} ) ;
26
28
27
29
it ( 'basic middleware should get text body' , async ( ) => {
28
30
router . get ( '/api/test' , ( ctx ) => {
29
31
ctx . status = 200 ;
30
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
- // @ts -expect-error
32
32
ctx . body = ctx . request . body ;
33
33
} ) ;
34
34
app . use ( router . routes ( ) ) ;
@@ -53,21 +53,15 @@ describe('koa', () => {
53
53
it ( 'basic middleware should get json body' , async ( ) => {
54
54
router . get ( '/api/test' , ( ctx ) => {
55
55
ctx . status = 200 ;
56
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
- // @ts -expect-error
58
56
ctx . body = ctx . request . body . hello ;
59
57
} ) ;
60
58
61
59
const response = await serverlessAdapter ( app ) (
62
60
{
63
61
...defaultEvent ,
64
62
httpMethod : 'GET' ,
65
- body : JSON . stringify ( {
66
- hello : 'world' ,
67
- } ) ,
68
- headers : {
69
- 'Content-Type' : 'application/json' ,
70
- } ,
63
+ body : JSON . stringify ( { hello : 'world' } ) ,
64
+ headers : { 'Content-Type' : 'application/json' } ,
71
65
} ,
72
66
defaultContext ,
73
67
) ;
@@ -80,7 +74,6 @@ describe('koa', () => {
80
74
router . get ( '/api/test' , ( ctx ) => {
81
75
ctx . status = 200 ;
82
76
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
- // @ts -expect-error
84
77
ctx . body = ctx . request . body . hello ;
85
78
} ) ;
86
79
0 commit comments