|
|
@ -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) {
|
|
|
|
it('→ get based on regex with multiple captures global', function (done) {
|
|
|
|
var router = new Router()
|
|
|
|
var router = new Router()
|
|
|
|
router.add(['by', 'order', /(\d+)/g], function (one, two, three) {
|
|
|
|
router.add(['by', 'order', /(\d+)/g], function (one, two, three) {
|
|
|
@ -98,16 +107,15 @@ describe('Router', function () {
|
|
|
|
router.route('/by/order/123', {args: [api]})
|
|
|
|
router.route('/by/order/123', {args: [api]})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('→ get based on function', function (done) {
|
|
|
|
function toInt(part) {
|
|
|
|
function toInt(part) {
|
|
|
|
var results = /^(\d+)$/.exec(part)
|
|
|
|
var results = /^(\d+)$/.exec(part)
|
|
|
|
if (results) {
|
|
|
|
if (results) {
|
|
|
|
return parseInt(results[0], 10)
|
|
|
|
return parseInt(results[0], 10)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
return null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
it('→ get based on function', function (done) {
|
|
|
|
var router = new Router()
|
|
|
|
var router = new Router()
|
|
|
|
router.add(['by', 'order', toInt], function (val) {
|
|
|
|
router.add(['by', 'order', toInt], function (val) {
|
|
|
|
expect(val).toBe(123)
|
|
|
|
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) {
|
|
|
|
it('→ check not found error', function (done) {
|
|
|
|
var router = new Router()
|
|
|
|
var router = new Router()
|
|
|
|
router.route('/not/real/id', function (err) {
|
|
|
|
router.route('/not/real/id', function (err) {
|
|
|
|