Skip to content

Commit

Permalink
Updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Sep 27, 2017
1 parent 76124b8 commit 3547753
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/issue-20.test.js
Expand Up @@ -61,20 +61,20 @@ test('Should be 404 / 3', t => {
t.fail('We should not be here')
})

findMyWay.lookup({ method: 'GET', url: '/a/' }, null)
findMyWay.lookup({ method: 'GET', url: '/a//' }, null)
})

test('Should be 404 / 4', t => {
test('Should get an empty parameter', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.pass('Everything good')
t.fail('We should not be here')
}
})

findMyWay.on('GET', '/a/:param', (req, res, params) => {
t.fail('We should not be here')
t.equal(params.param, '')
})

findMyWay.lookup({ method: 'GET', url: '/a//' }, null)
findMyWay.lookup({ method: 'GET', url: '/a/' }, null)
})
118 changes: 118 additions & 0 deletions test/issue-28.test.js
@@ -0,0 +1,118 @@
'use strict'

const t = require('tap')
const test = t.test
const FindMyWay = require('../')

test('wildcard (more complex test)', t => {
t.plan(3)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('we should not be here, the url is: ' + req.url)
}
})

findMyWay.on('GET', '/test/*', (req, res, params) => {
switch (params['*']) {
case 'hello':
t.ok('correct parameter')
break
case 'hello/world':
t.ok('correct parameter')
break
case '':
t.ok('correct parameter')
break
default:
t.fail('wrong parameter: ' + params['*'])
}
})

findMyWay.lookup(
{ method: 'GET', url: '/test/hello' },
null
)

findMyWay.lookup(
{ method: 'GET', url: '/test/hello/world' },
null
)

findMyWay.lookup(
{ method: 'GET', url: '/test/' },
null
)
})

test('Wildcard inside a node with a static route but different method', t => {
t.plan(2)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('we should not be here, the url is: ' + req.url)
}
})

findMyWay.on('GET', '/test/hello', (req, res, params) => {
t.is(req.method, 'GET')
})

findMyWay.on('OPTIONS', '/*', (req, res, params) => {
t.is(req.method, 'OPTIONS')
})

findMyWay.lookup(
{ method: 'GET', url: '/test/hello' },
null
)

findMyWay.lookup(
{ method: 'OPTIONS', url: '/test/hello' },
null
)
})

test('Wildcard inside a node with a static route but different method (more complex case)', t => {
t.plan(5)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
if (req.url === '/test/helloo' && req.method === 'GET') {
t.ok('Everything fine')
} else {
t.fail('we should not be here, the url is: ' + req.url)
}
}
})

findMyWay.on('GET', '/test/hello', (req, res, params) => {
t.is(req.method, 'GET')
})

findMyWay.on('OPTIONS', '/*', (req, res, params) => {
t.is(req.method, 'OPTIONS')
})

findMyWay.lookup(
{ method: 'GET', url: '/test/hello' },
null
)

findMyWay.lookup(
{ method: 'GET', url: '/test/helloo' },
null
)

findMyWay.lookup(
{ method: 'OPTIONS', url: '/test/' },
null
)

findMyWay.lookup(
{ method: 'OPTIONS', url: '/test' },
null
)

findMyWay.lookup(
{ method: 'OPTIONS', url: '/test/helloo' },
null
)
})

0 comments on commit 3547753

Please sign in to comment.