@@ -2,11 +2,11 @@ import Koa from 'koa';
22import KoaRouter from 'koa-router' ; // or import Router from 'koa-router';
33import request from 'supertest' ;
44import bodyParser from 'koa-bodyparser' ; // Add this
5- import ERest , { KoaHandler , API } from '../lib' ; // Adjust path as needed
5+ import ERest from '../lib' ; // Adjust path as needed
66
77// Helper to set up ERest instance for forceGroup: false
88const setupERestNoGroup = ( ) => {
9- return new ERest < KoaHandler > ( {
9+ return new ERest ( {
1010 info : { title : 'Koa Test No Group' } ,
1111 // Ensure default error handlers are set up if your tests rely on specific status codes for errors
1212 missingParameterError : ( msg : string ) => ( { status : 400 , message : `Missing Parameter: ${ msg } ` } as any ) , // Example
@@ -16,7 +16,7 @@ const setupERestNoGroup = () => {
1616
1717// Helper to set up ERest instance for forceGroup: true
1818const setupERestWithGroup = ( ) => {
19- return new ERest < KoaHandler > ( {
19+ return new ERest ( {
2020 info : { title : 'Koa Test With Group' } ,
2121 forceGroup : true ,
2222 groups : {
@@ -35,22 +35,22 @@ describe('ERest Koa Integration', () => {
3535 app . use ( bodyParser ( ) ) ; // Use bodyParser for all non-group tests
3636 const erest = setupERestNoGroup ( ) ;
3737 const router = new KoaRouter ( ) ;
38-
38+ const api = erest . group ( "Index" ) ; ;
3939 // Test 1.1
40- erest . api . get ( '/test-koa' ) . register ( async ( ctx : Koa . Context ) => { ctx . body = { success : true , data : 'koa works' } ; } ) ;
40+ api . get ( '/test-koa' ) . register ( async ( ctx : Koa . Context ) => { ctx . body = { success : true , data : 'koa works' } ; } ) ;
4141
4242 // Test 1.2
43- erest . api . get ( '/query-test' )
43+ api . get ( '/query-test' )
4444 . query ( { name : { type : 'string' , required : true } } )
4545 . register ( async ( ctx : Koa . Context ) => { ctx . body = { name : ( ctx . request as any ) . $params . query . name } ; } ) ;
4646
4747 // Test 1.3
48- erest . api . post ( '/body-test' )
48+ api . post ( '/body-test' )
4949 . body ( { id : { type : 'int' , required : true } } )
5050 . register ( async ( ctx : Koa . Context ) => { ctx . body = { id : ( ctx . request as any ) . $params . body . id } ; } ) ;
5151
5252 // After all API definitions for this block
53- erest . bindRouterToKoa ( router , ( e , s ) => erest . checkerKoa ( e , s as API < KoaHandler > ) ) ;
53+ erest . bindRouterToKoa ( router , ( e , s ) => erest . checkerKoa ( e , s ) ) ;
5454 app . use ( router . routes ( ) ) . use ( router . allowedMethods ( ) ) ;
5555
5656 // Now run the actual test executions that were commented out above
@@ -79,7 +79,7 @@ describe('ERest Koa Integration', () => {
7979 erestGroup . group ( 'user' ) . get ( '/info' ) . register ( async ( ctx : Koa . Context ) => { ctx . body = { group : 'user info' } ; } ) ;
8080
8181 // After all API definitions for this block
82- erestGroup . bindKoaRouterToApp ( appGroup , KoaRouter , ( e , s ) => erestGroup . checkerKoa ( e , s as API < KoaHandler > ) ) ;
82+ erestGroup . bindKoaRouterToApp ( appGroup , KoaRouter , ( e , s ) => erestGroup . checkerKoa ( e , s ) ) ;
8383
8484 // Now run the actual test executions
8585 it ( 'should handle basic GET request in a group with explicit prefix (execution)' , async ( ) => {
0 commit comments