mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
tests for formatProductsFilter ✅
This commit is contained in:
parent
6d5c6081ce
commit
850cd9ce85
3 changed files with 57 additions and 0 deletions
3
test/format/index.js
Normal file
3
test/format/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
'use strict'
|
||||
|
||||
require('./products-filter')
|
53
test/format/products-filter.js
Normal file
53
test/format/products-filter.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const format = require('../../format/products-filter')
|
||||
|
||||
const products = [
|
||||
{
|
||||
id: 'train',
|
||||
bitmasks: [1, 2],
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'bus',
|
||||
bitmasks: [4],
|
||||
default: true
|
||||
},
|
||||
{
|
||||
id: 'tram',
|
||||
bitmasks: [8, 32],
|
||||
default: false
|
||||
},
|
||||
]
|
||||
|
||||
const profile = {products}
|
||||
const ctx = {
|
||||
common: {},
|
||||
opt: {},
|
||||
profile
|
||||
}
|
||||
|
||||
test('formatProductsFilter works without customisations', (t) => {
|
||||
const expected = 1 | 2 | 4
|
||||
const filter = {}
|
||||
t.deepEqual(format(profile)(filter), {
|
||||
type: 'PROD',
|
||||
mode: 'INC',
|
||||
value: expected + ''
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('formatProductsFilter works with customisations', (t) => {
|
||||
t.equal(+format(profile)({
|
||||
bus: true
|
||||
}).value, 1 | 2 | 4)
|
||||
t.equal(+format(profile)({
|
||||
bus: false
|
||||
}).value, 1 | 2)
|
||||
t.equal(+format(profile)({
|
||||
tram: true
|
||||
}).value, 1 | 2 | 4 | 8 | 32)
|
||||
t.end()
|
||||
})
|
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
require('./parse')
|
||||
require('./format')
|
||||
|
||||
require('./bvg-journey')
|
||||
require('./vbb-departures')
|
||||
|
|
Loading…
Add table
Reference in a new issue