-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hanlde multi-parametric route (issue #17)
Detect multi parametric path (new nodeType=4) Handle lookup for multi parametric path Unit test issue #17
- Loading branch information
Bruno Scopelliti
committed
Sep 23, 2017
1 parent
ddc113a
commit c4b5515
Showing
2 changed files
with
160 additions
and
4 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
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,132 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const FindMyWay = require('../') | ||
|
||
test('Parametric route with fixed suffix', t => { | ||
t.plan(1) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:param-bar', (req, res, params) => { | ||
t.equal(params.param, 'foo') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
}) | ||
|
||
test('Parametric route with fixed suffix', t => { | ||
t.plan(1) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:$param', (req, res, params) => { | ||
t.equal(params.$param, 'foo') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo' }, null) | ||
}) | ||
|
||
test('Multi parametric route / 1', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p1-:p2', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
}) | ||
|
||
test('Multi parametric route / 2', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p1-:p2', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar-baz') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz' }, null) | ||
}) | ||
|
||
test('Multi parametric route / 3', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p_1-:$p', (req, res, params) => { | ||
t.equal(params.p_1, 'foo') | ||
t.equal(params.$p, 'bar') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
}) | ||
|
||
test('Multi parametric route with fixed suffix', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p1-:p2-baz', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz' }, null) | ||
}) | ||
|
||
test('Multi parametric route with wildcard', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p1-:p2/*', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/baz' }, null) | ||
}) | ||
|
||
test('Nested multi parametric route', t => { | ||
t.plan(3) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('Should not be defaultRoute') | ||
} | ||
}) | ||
|
||
findMyWay.on('GET', '/a/:p1-:p2/b/:p3', (req, res, params) => { | ||
t.equal(params.p1, 'foo') | ||
t.equal(params.p2, 'bar') | ||
t.equal(params.p3, 'baz') | ||
}) | ||
|
||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b/baz' }, null) | ||
}) |