|
|
|
@ -58,6 +58,15 @@ describe('Router', function () {
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ regex routes can return NotFoundError', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['/by/id', /\d+/], function () {})
|
|
|
|
|
router.route('/by/id/not-an-id', function (err) {
|
|
|
|
|
expect(err).toBeA(NotFoundError)
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ get based on regex with multiple captures global', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['by', 'order', /(\d+)/g], function (one, two, three) {
|
|
|
|
@ -98,7 +107,6 @@ describe('Router', function () {
|
|
|
|
|
router.route('/by/order/123', {args: [api]})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ get based on function', function (done) {
|
|
|
|
|
function toInt(part) {
|
|
|
|
|
var results = /^(\d+)$/.exec(part)
|
|
|
|
|
if (results) {
|
|
|
|
@ -107,7 +115,7 @@ describe('Router', function () {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it('→ get based on function', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['by', 'order', toInt], function (val) {
|
|
|
|
|
expect(val).toBe(123)
|
|
|
|
@ -119,6 +127,15 @@ describe('Router', function () {
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ function routes can return NotFoundError', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['/by/order', toInt], function () {})
|
|
|
|
|
router.route('/by/order/not-found', function (err) {
|
|
|
|
|
expect(err).toBeA(NotFoundError)
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ check not found error', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.route('/not/real/id', function (err) {
|
|
|
|
|