11import Koa from 'koa' ;
22import Router from '@koa/router' ;
3+ import koaBody from 'koa-body' ;
34import serverlessAdapter from '../src' ;
45import { defaultContext , defaultEvent } from './fixtures/fcContext' ;
56
@@ -8,27 +9,26 @@ describe('koa', () => {
89 let router : Router ;
910 beforeEach ( ( ) => {
1011 app = new Koa ( ) ;
12+ app . use ( koaBody ( ) ) ;
1113 router = new Router ( ) ;
1214 } ) ;
1315
1416 it ( 'basic middleware should set statusCode and default body' , async ( ) => {
1517 router . get ( '/api/test' , ( ctx ) => {
16- ctx . status = 200 ;
17- ctx . body = 'Hello, world!' ;
18+ ctx . status = 418 ;
19+ ctx . body = 'Hello, world koa !' ;
1820 } ) ;
1921 app . use ( router . routes ( ) ) ;
2022
2123 const response = await serverlessAdapter ( app ) ( defaultEvent , defaultContext ) ;
2224
2325 expect ( response . statusCode ) . toEqual ( 418 ) ;
24- expect ( response . body ) . toEqual ( `I'm a teapot` ) ;
26+ expect ( response . body ) . toEqual ( 'Hello, world koa!' ) ;
2527 } ) ;
2628
2729 it ( 'basic middleware should get text body' , async ( ) => {
2830 router . get ( '/api/test' , ( ctx ) => {
2931 ctx . status = 200 ;
30- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31- // @ts -expect-error
3232 ctx . body = ctx . request . body ;
3333 } ) ;
3434 app . use ( router . routes ( ) ) ;
@@ -53,21 +53,15 @@ describe('koa', () => {
5353 it ( 'basic middleware should get json body' , async ( ) => {
5454 router . get ( '/api/test' , ( ctx ) => {
5555 ctx . status = 200 ;
56- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57- // @ts -expect-error
5856 ctx . body = ctx . request . body . hello ;
5957 } ) ;
6058
6159 const response = await serverlessAdapter ( app ) (
6260 {
6361 ...defaultEvent ,
6462 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' } ,
7165 } ,
7266 defaultContext ,
7367 ) ;
@@ -80,7 +74,6 @@ describe('koa', () => {
8074 router . get ( '/api/test' , ( ctx ) => {
8175 ctx . status = 200 ;
8276 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83- // @ts -expect-error
8477 ctx . body = ctx . request . body . hello ;
8578 } ) ;
8679
0 commit comments