Aktueller Stand
This commit is contained in:
109
backend/node_modules/find-my-way/test/constraint.default-versioning.test.js
generated
vendored
109
backend/node_modules/find-my-way/test/constraint.default-versioning.test.js
generated
vendored
@@ -1,7 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const FindMyWay = require('..')
|
||||
const noop = () => { }
|
||||
|
||||
@@ -13,13 +12,13 @@ test('A route could support multiple versions (find) / 1', t => {
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, noop)
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, noop)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
t.ok(findMyWay.find('GET', '/', { version: '1.2.3' }))
|
||||
t.ok(findMyWay.find('GET', '/', { version: '3.x' }))
|
||||
t.ok(findMyWay.find('GET', '/', { version: '3.2.0' }))
|
||||
t.notOk(findMyWay.find('GET', '/', { version: '2.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/', { version: '2.3.4' }))
|
||||
t.notOk(findMyWay.find('GET', '/', { version: '3.2.1' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '1.2.3' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '3.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '3.2.0' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/', { version: '2.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/', { version: '2.3.4' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/', { version: '3.2.1' }))
|
||||
})
|
||||
|
||||
test('A route could support multiple versions (find) / 2', t => {
|
||||
@@ -30,13 +29,13 @@ test('A route could support multiple versions (find) / 2', t => {
|
||||
findMyWay.on('GET', '/test', { constraints: { version: '1.2.3' } }, noop)
|
||||
findMyWay.on('GET', '/test', { constraints: { version: '3.2.0' } }, noop)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/test', { version: '1.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test', { version: '1.2.3' }))
|
||||
t.ok(findMyWay.find('GET', '/test', { version: '3.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test', { version: '3.2.0' }))
|
||||
t.notOk(findMyWay.find('GET', '/test', { version: '2.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/test', { version: '2.3.4' }))
|
||||
t.notOk(findMyWay.find('GET', '/test', { version: '3.2.1' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test', { version: '1.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test', { version: '1.2.3' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test', { version: '3.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test', { version: '3.2.0' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test', { version: '2.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test', { version: '2.3.4' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test', { version: '3.2.1' }))
|
||||
})
|
||||
|
||||
test('A route could support multiple versions (find) / 3', t => {
|
||||
@@ -48,16 +47,16 @@ test('A route could support multiple versions (find) / 3', t => {
|
||||
findMyWay.on('GET', '/test/:id/hello', { constraints: { version: '3.2.0' } }, noop)
|
||||
findMyWay.on('GET', '/test/name/hello', { constraints: { version: '4.0.0' } }, noop)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' }))
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' }))
|
||||
t.ok(findMyWay.find('GET', '/test/name/hello', { version: '4.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test/name/hello', { version: '3.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.3.4' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.1' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '4.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/name/hello', { version: '4.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/name/hello', { version: '3.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.3.4' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.2.1' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '4.x' }))
|
||||
})
|
||||
|
||||
test('A route could support multiple versions (find) / 4', t => {
|
||||
@@ -68,14 +67,14 @@ test('A route could support multiple versions (find) / 4', t => {
|
||||
findMyWay.on('GET', '/test/*', { constraints: { version: '1.2.3' } }, noop)
|
||||
findMyWay.on('GET', '/test/hello', { constraints: { version: '3.2.0' } }, noop)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' }))
|
||||
t.ok(findMyWay.find('GET', '/test/hello', { version: '3.x' }))
|
||||
t.ok(findMyWay.find('GET', '/test/hello', { version: '3.2.0' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.x' }))
|
||||
t.notOk(findMyWay.find('GET', '/test/hello', { version: '2.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/hello', { version: '3.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/test/hello', { version: '3.2.0' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/test/hello', { version: '2.x' }))
|
||||
})
|
||||
|
||||
test('A route could support multiple versions (find) / 5', t => {
|
||||
@@ -86,7 +85,7 @@ test('A route could support multiple versions (find) / 5', t => {
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, () => false)
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, () => true)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/', { version: '*' }).handler())
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '*' }).handler())
|
||||
})
|
||||
|
||||
test('Find with a version but without versioned routes', t => {
|
||||
@@ -96,7 +95,7 @@ test('Find with a version but without versioned routes', t => {
|
||||
|
||||
findMyWay.on('GET', '/', noop)
|
||||
|
||||
t.notOk(findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
t.assert.ok(!findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
})
|
||||
|
||||
test('A route could support multiple versions (lookup)', t => {
|
||||
@@ -105,18 +104,18 @@ test('A route could support multiple versions (lookup)', t => {
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: (req, res) => {
|
||||
const versions = ['2.x', '2.3.4', '3.2.1']
|
||||
t.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, (req, res) => {
|
||||
const versions = ['1.x', '1.2.3']
|
||||
t.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, (req, res) => {
|
||||
const versions = ['3.x', '3.2.0']
|
||||
t.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1)
|
||||
})
|
||||
|
||||
findMyWay.lookup({
|
||||
@@ -168,31 +167,31 @@ test('It should always choose the highest version of a route', t => {
|
||||
const findMyWay = FindMyWay()
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '2.3.0' } }, (req, res) => {
|
||||
t.fail('We should not be here')
|
||||
t.assert.fail('We should not be here')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '2.4.0' } }, (req, res) => {
|
||||
t.pass('Yeah!')
|
||||
t.assert.ok('Yeah!')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.3.0' } }, (req, res) => {
|
||||
t.pass('Yeah!')
|
||||
t.assert.ok('Yeah!')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, (req, res) => {
|
||||
t.fail('We should not be here')
|
||||
t.assert.fail('We should not be here')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '3.2.2' } }, (req, res) => {
|
||||
t.fail('We should not be here')
|
||||
t.assert.fail('We should not be here')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '4.4.0' } }, (req, res) => {
|
||||
t.fail('We should not be here')
|
||||
t.assert.fail('We should not be here')
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', { constraints: { version: '4.3.2' } }, (req, res) => {
|
||||
t.pass('Yeah!')
|
||||
t.assert.ok('Yeah!')
|
||||
})
|
||||
|
||||
findMyWay.lookup({
|
||||
@@ -222,8 +221,8 @@ test('Declare the same route with and without version', t => {
|
||||
findMyWay.on('GET', '/', noop)
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.2.0' } }, noop)
|
||||
|
||||
t.ok(findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
t.ok(findMyWay.find('GET', '/', {}))
|
||||
t.assert.ok(findMyWay.find('GET', '/', { version: '1.x' }))
|
||||
t.assert.ok(findMyWay.find('GET', '/', {}))
|
||||
})
|
||||
|
||||
test('It should throw if you declare multiple times the same route', t => {
|
||||
@@ -235,9 +234,9 @@ test('It should throw if you declare multiple times the same route', t => {
|
||||
|
||||
try {
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, noop)
|
||||
t.fail('It should throw')
|
||||
t.assert.fail('It should throw')
|
||||
} catch (err) {
|
||||
t.equal(err.message, 'Method \'GET\' already declared for route \'/\' with constraints \'{"version":"1.2.3"}\'')
|
||||
t.assert.equal(err.message, 'Method \'GET\' already declared for route \'/\' with constraints \'{"version":"1.2.3"}\'')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -246,12 +245,12 @@ test('Versioning won\'t work if there are no versioned routes', t => {
|
||||
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: (req, res) => {
|
||||
t.fail('We should not be here')
|
||||
t.assert.fail('We should not be here')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', (req, res) => {
|
||||
t.pass('Yeah!')
|
||||
t.assert.ok('Yeah!')
|
||||
})
|
||||
|
||||
findMyWay.lookup({
|
||||
@@ -271,15 +270,15 @@ test('Unversioned routes aren\'t triggered when unknown versions are requested',
|
||||
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: (req, res) => {
|
||||
t.ok('We should be here')
|
||||
t.assert.ok('We should be here')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/', (req, res) => {
|
||||
t.fail('unversioned route shouldnt be hit!')
|
||||
t.assert.fail('unversioned route shouldnt be hit!')
|
||||
})
|
||||
findMyWay.on('GET', '/', { constraints: { version: '1.0.0' } }, (req, res) => {
|
||||
t.fail('versioned route shouldnt be hit for wrong version!')
|
||||
t.assert.fail('versioned route shouldnt be hit for wrong version!')
|
||||
})
|
||||
|
||||
findMyWay.lookup({
|
||||
|
||||
Reference in New Issue
Block a user