From 850cd9ce854949469c661bf13db3b9ca2baba492 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 31 Oct 2019 19:30:02 +0100 Subject: [PATCH] tests for formatProductsFilter :white_check_mark: --- test/format/index.js | 3 ++ test/format/products-filter.js | 53 ++++++++++++++++++++++++++++++++++ test/index.js | 1 + 3 files changed, 57 insertions(+) create mode 100644 test/format/index.js create mode 100644 test/format/products-filter.js diff --git a/test/format/index.js b/test/format/index.js new file mode 100644 index 00000000..85608599 --- /dev/null +++ b/test/format/index.js @@ -0,0 +1,3 @@ +'use strict' + +require('./products-filter') diff --git a/test/format/products-filter.js b/test/format/products-filter.js new file mode 100644 index 00000000..e00131fc --- /dev/null +++ b/test/format/products-filter.js @@ -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() +}) diff --git a/test/index.js b/test/index.js index 59e53375..017622c5 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,7 @@ 'use strict' require('./parse') +require('./format') require('./bvg-journey') require('./vbb-departures')