Got tests running, made changes to get tests to compile

This commit is contained in:
Matthew Bull
2017-11-06 11:36:38 +00:00
parent a9b5d8c180
commit 31c8432e74
3 changed files with 43 additions and 15 deletions

View File

@@ -5,13 +5,11 @@
import * as Koa from 'koa';
import * as Joi from 'joi';
type METHODS = 'POST' | 'GET' | 'DELETE' | 'PUT' | 'PATCH' | 'OPTIONS' | 'HEAD';
interface Spec {
method: METHODS;
method: string;
path: string|RegExp;
handler: (ctx: Koa.Context) => void;
validate: {
validate?: {
type: string;
body?: Joi.AnySchema;
params?: Joi.AnySchema;
@@ -19,7 +17,7 @@ interface Spec {
};
}
declare class Router {
interface Router {
route(spec: Spec): Router;
middleware(): Koa.Middleware;
}
@@ -29,6 +27,6 @@ interface createRouter {
Joi: typeof Joi;
}
declare namespace createRouter {}
declare var create: createRouter;
export = createRouter;
export = create;

View File

@@ -1,20 +1,50 @@
import * as router from 'koa-joi-router';
import { Context } from 'koa';
const { Joi } = router;
const spec1 = {
route: '/user',
path: '/user',
method: 'POST',
handler: (ctx) => ctx.body = '';
handler: (ctx: Context) => ctx.body = '',
};
router().route(spec1);
const spec2: ISpec = {
const spec2 = {
method: 'PATCH',
route: '/user',
validate: {},
handler: (ctx) => ctx.stat
path: '/user',
validate: {
type: 'json',
},
handler: (ctx: Context) => ctx.status = 201,
};
router().route(spec2);
const spec3 = {
method: 'PATCH',
path: '/user',
validate: {
type: 'json',
body: Joi.any(),
},
handler: (ctx: Context) => ctx.status = 201,
};
router().route(spec3);
const spec4 = {
method: 'PATCH',
path: '/user',
validate: {
type: 'json',
201: Joi.object(),
},
handler: (ctx: Context) => {
ctx.status = 201;
ctx.body = {};
},
};
router().route(spec3);

View File

@@ -1,7 +1,7 @@
{
"files": [
"index.d.ts",
"koa-tests.ts"
"koa-joi-router-tests.ts"
],
"compilerOptions": {
"module": "commonjs",
@@ -10,7 +10,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [