tests for formatProductsFilter

This commit is contained in:
Jannis R 2019-10-31 19:30:02 +01:00
parent 6d5c6081ce
commit 850cd9ce85
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 57 additions and 0 deletions

3
test/format/index.js Normal file
View file

@ -0,0 +1,3 @@
'use strict'
require('./products-filter')

View 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()
})

View file

@ -1,6 +1,7 @@
'use strict' 'use strict'
require('./parse') require('./parse')
require('./format')
require('./bvg-journey') require('./bvg-journey')
require('./vbb-departures') require('./vbb-departures')