-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
~80% coverage test suits, need more later
- Loading branch information
Showing
13 changed files
with
493 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules/ | |
builds/ | ||
dist/ | ||
npm-debug.log | ||
coverage/ | ||
.DS_Storage |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/// <reference path="../typings/mocha/mocha.d.ts"/> | ||
/// <reference path="../typings/chai/chai.d.ts"/> | ||
/// <reference path="../typings/supertest/supertest.d.ts"/> | ||
/// <reference path="../typings/koa/koa.d.ts"/> | ||
|
||
import * as tsRouter from '../src'; | ||
import * as chai from 'chai'; | ||
import * as request from 'supertest'; | ||
import * as Koa from 'koa'; | ||
|
||
@tsRouter.Path('/test') | ||
class TestController extends tsRouter.Controller { | ||
@tsRouter.Path('/:v1/:v2') | ||
@tsRouter.GET | ||
@tsRouter.Produce(tsRouter.MediaType.JSON) | ||
async index( | ||
@tsRouter.Params params:Object, | ||
@tsRouter.PathParam('v1') v1:string, | ||
@tsRouter.PathParam('v2') v2:string | ||
):Promise<tsRouter.Response> { | ||
return tsRouter.Response.status(200).body({v1, v2, params}).build(); | ||
} | ||
|
||
@tsRouter.After | ||
async after( | ||
@tsRouter.Params params:Object, | ||
@tsRouter.PathParam('v1') v1:string, | ||
@tsRouter.PathParam('v2') v2:string, | ||
@tsRouter.AppContext context:tsRouter.Context, | ||
@tsRouter.RouteResponse res:tsRouter.Response | ||
) { | ||
res.body = JSON.stringify({v1, v2, params, v3: v1 + v2}); | ||
res.send(context); | ||
} | ||
} | ||
|
||
const app = new Koa(); | ||
const router = new tsRouter.Router(); | ||
router.use(TestController); | ||
app.use(router.routes()); | ||
let server = app.listen(); | ||
describe('GET with path paramters with afterwares', () => { | ||
after(() => { | ||
server.close(); | ||
}) | ||
it('response paramters in back in json', function (done) { | ||
request(app.listen()) | ||
.get('/test/hello/world') | ||
.expect('Content-Type', 'application/json') | ||
.expect({ | ||
params: { | ||
v1: 'hello', | ||
v2: 'world' | ||
}, | ||
v1: 'hello', | ||
v2: 'world', | ||
v3: 'helloworld' | ||
}) | ||
.expect(200, done); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// <reference path="../typings/mocha/mocha.d.ts"/> | ||
/// <reference path="../typings/chai/chai.d.ts"/> | ||
/// <reference path="../typings/supertest/supertest.d.ts"/> | ||
/// <reference path="../typings/koa/koa.d.ts"/> | ||
|
||
import * as tsRouter from '../src'; | ||
import * as chai from 'chai'; | ||
import * as request from 'supertest'; | ||
import * as Koa from 'koa'; | ||
|
||
@tsRouter.Path('/test') | ||
class TestController extends tsRouter.Controller { | ||
@tsRouter.PathParam('v1') private v1:string; | ||
private v2:string; | ||
constructor() { | ||
super(); | ||
this.v1 = this.v1 + this.v1; | ||
} | ||
|
||
@tsRouter.Path('/:v1/:v2') | ||
@tsRouter.GET | ||
@tsRouter.Produce(tsRouter.MediaType.JSON) | ||
async index(@tsRouter.Params params:Object):Promise<tsRouter.Response> { | ||
let v1 = this.v1; | ||
let v2 = this.v2; | ||
return tsRouter.Response.status(200).body({v1, v2, params}).build(); | ||
} | ||
|
||
@tsRouter.Before | ||
async before(@tsRouter.PathParam('v2') v2:string) { | ||
this.v2 = v2; | ||
} | ||
} | ||
|
||
const app = new Koa(); | ||
const router = new tsRouter.Router(); | ||
router.use(TestController); | ||
app.use(router.routes()); | ||
let server = app.listen(); | ||
describe('GET with path paramters with beforewares', () => { | ||
after(() => { | ||
server.close(); | ||
}) | ||
it('response paramters in back in json', function (done) { | ||
request(app.listen()) | ||
.get('/test/hello/world') | ||
.expect('Content-Type', 'application/json') | ||
.expect({ | ||
params: { | ||
v1: 'hello', | ||
v2: 'world' | ||
}, | ||
v1: 'hellohello', | ||
v2: 'world', | ||
}) | ||
.expect(200, done); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// <reference path="../typings/mocha/mocha.d.ts"/> | ||
/// <reference path="../typings/chai/chai.d.ts"/> | ||
/// <reference path="../typings/supertest/supertest.d.ts"/> | ||
/// <reference path="../typings/koa/koa.d.ts"/> | ||
|
||
import * as tsRouter from '../src'; | ||
import * as chai from 'chai'; | ||
import * as request from 'supertest'; | ||
import * as Koa from 'koa'; | ||
|
||
@tsRouter.Path('/test') | ||
class TestController extends tsRouter.Controller { | ||
@tsRouter.Path('') | ||
@tsRouter.POST | ||
@tsRouter.Consume(tsRouter.MediaType.JSON) | ||
@tsRouter.Produce(tsRouter.MediaType.JSON) | ||
async index( | ||
@tsRouter.Body body:Object, | ||
@tsRouter.BodyParam('v1') v1:string, | ||
@tsRouter.BodyParam('v2') v2:string | ||
):Promise<tsRouter.Response> { | ||
return tsRouter.Response.status(200).body({ | ||
hello: v1, | ||
world: v2, | ||
body | ||
}).build(); | ||
} | ||
} | ||
|
||
const app = new Koa(); | ||
const router = new tsRouter.Router(); | ||
router.use(TestController); | ||
app.use(router.routes()); | ||
let server = app.listen(); | ||
describe('POST with body', () => { | ||
after(() => { | ||
server.close(); | ||
}) | ||
it('response body back in json', function (done) { | ||
request(app.listen()) | ||
.post('/test') | ||
.send({ | ||
v1: 'hello', | ||
v2: 'world' | ||
}) | ||
.set('Content-Type', 'application/json') | ||
.expect('Content-Type', 'application/json') | ||
.expect({ | ||
body: { | ||
v1: 'hello', | ||
v2: 'world' | ||
}, | ||
hello: 'hello', | ||
world: 'world' | ||
}) | ||
.expect(200, done); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// <reference path="../typings/mocha/mocha.d.ts"/> | ||
/// <reference path="../typings/chai/chai.d.ts"/> | ||
/// <reference path="../typings/supertest/supertest.d.ts"/> | ||
/// <reference path="../typings/koa/koa.d.ts"/> | ||
|
||
import * as tsRouter from '../src'; | ||
import * as chai from 'chai'; | ||
import * as request from 'supertest'; | ||
import * as Koa from 'koa'; | ||
|
||
@tsRouter.Path('/test') | ||
class TestController extends tsRouter.Controller { | ||
@tsRouter.Path('') | ||
@tsRouter.DELETE | ||
async index():Promise<tsRouter.Response> { | ||
return tsRouter.Response.status(200).body('hello').build(); | ||
} | ||
} | ||
|
||
const app = new Koa(); | ||
const router = new tsRouter.Router(); | ||
router.use(TestController); | ||
app.use(router.routes()); | ||
let server = app.listen(); | ||
describe('DELETE plain text', () => { | ||
after(() => { | ||
server.close(); | ||
}) | ||
it('response plain text', function (done) { | ||
request(app.listen()) | ||
.del('/test') | ||
.expect('Content-Type', 'text/plain') | ||
.expect('hello') | ||
.expect(200, done); | ||
}); | ||
}) |
Oops, something went wrong.