|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const t = require('tap') |
| 4 | +const test = t.test |
| 5 | +const FindMyWay = require('../') |
| 6 | + |
| 7 | +test('Wildcard route should not be blocked by Parametric with different method / 1', t => { |
| 8 | + t.plan(1) |
| 9 | + const findMyWay = FindMyWay({ |
| 10 | + defaultRoute: (req, res) => { |
| 11 | + t.fail('Should not be defaultRoute') |
| 12 | + } |
| 13 | + }) |
| 14 | + |
| 15 | + findMyWay.on('OPTIONS', '/*', (req, res, params) => { |
| 16 | + t.fail('Should not be here') |
| 17 | + }) |
| 18 | + |
| 19 | + findMyWay.on('OPTIONS', '/obj/*', (req, res, params) => { |
| 20 | + t.strictEqual(req.method, 'OPTIONS') |
| 21 | + }) |
| 22 | + |
| 23 | + findMyWay.on('GET', '/obj/:id', (req, res, params) => { |
| 24 | + t.fail('Should not be GET') |
| 25 | + }) |
| 26 | + |
| 27 | + findMyWay.lookup({ method: 'OPTIONS', url: '/obj/params', headers: {} }, null) |
| 28 | +}) |
| 29 | + |
| 30 | +test('Wildcard route should not be blocked by Parametric with different method / 2', t => { |
| 31 | + t.plan(1) |
| 32 | + const findMyWay = FindMyWay({ |
| 33 | + defaultRoute: (req, res) => { |
| 34 | + t.fail('Should not be defaultRoute') |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + findMyWay.on('OPTIONS', '/*', { version: '1.2.3' }, (req, res, params) => { |
| 39 | + t.fail('Should not be here') |
| 40 | + }) |
| 41 | + |
| 42 | + findMyWay.on('OPTIONS', '/obj/*', { version: '1.2.3' }, (req, res, params) => { |
| 43 | + t.strictEqual(req.method, 'OPTIONS') |
| 44 | + }) |
| 45 | + |
| 46 | + findMyWay.on('GET', '/obj/:id', { version: '1.2.3' }, (req, res, params) => { |
| 47 | + t.fail('Should not be GET') |
| 48 | + }) |
| 49 | + |
| 50 | + findMyWay.lookup({ |
| 51 | + method: 'OPTIONS', |
| 52 | + url: '/obj/params', |
| 53 | + headers: { 'accept-version': '1.2.3' } |
| 54 | + }, null) |
| 55 | +}) |
0 commit comments