Skip to content

Commit

Permalink
add test: parse entire subscription ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Nov 29, 2020
1 parent 018e345 commit e9dee10
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 0 deletions.
151 changes: 151 additions & 0 deletions test/fixtures/vrn-subscription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
'use strict'

module.exports = {
id: 'foo',
hysteresis: {minDeviationInterval: 5, notificationStart: 20},
monitorFlags: ['AF', 'DF', 'DV', 'FTF', 'OF', 'PF'],
connectionInfo: [{
arrivalStation: '8000244',
arrivalPlatform: '1',
arrivalStationName: 'Mannheim Hbf',
arrivalTime: '2020-11-28T18:29:00Z',
departureStation: '8000156',
departurePlatform: '4',
departureStationName: 'Heidelberg Hbf',
departureTime: '2020-11-28T18:13:00Z',
productName: 'S 3'
}],
journeyRefreshToken: '¶HKI¶T$A=1@O=Heidelberg Hbf@L=8000156@a=128@$A=1@O=Mannheim Hbf@L=8000244@a=128@$202011281813$202011281829$S 3$$1$$$',
journey: {
type: 'journey',
legs: [{
tripId: '1|225439|0|80|28112020',
direction: 'Germersheim',
line: {
type: 'line',
id: 's-3',
fahrtNr: '38352',
name: 'S 3',
public: true,
mode: 'train',
product: 'urban-train'
},
reachable: true,

origin: {
type: 'stop',
id: '8000156',
name: 'Heidelberg Hbf',
location: {
type: 'location',
id: '8000156',
latitude: 49.403582,
longitude: 8.67548
},
isMeta: false
},
departure: '2020-11-28T20:16:00+01:00',
plannedDeparture: '2020-11-28T20:13:00+01:00',
departureDelay: 180,
departurePlatform: '4',
plannedDeparturePlatform: '4',

destination: {
type: 'stop',
id: '8000244',
name: 'Mannheim Hbf',
location: {
type: 'location',
id: '8000244',
latitude: 49.479181,
longitude: 8.469268
},
isMeta: false
},
arrival: '2020-11-28T20:31:00+01:00',
plannedArrival: '2020-11-28T20:29:00+01:00',
arrivalDelay: 120,
arrivalPlatform: '1',
plannedArrivalPlatform: '1',

cycle: {min: 600, max: 1200, nr: 9},
alternatives: [{
tripId: '1|225210|0|80|28112020',
line: {
type: 'line',
id: 's-2',
fahrtNr: '38246',
name: 'S 2',
public: true,
mode: 'train',
product: 'urban-train'
},
direction: 'Kaiserslautern Hbf',
when: '1970-01-01T20:33:00+01:00',
plannedWhen: '1970-01-01T20:33:00+01:00',
delay: null
}, {
tripId: '1|1204374|0|80|28112020',
line: {
type: 'line',
id: 's-3',
fahrtNr: '38354',
name: 'S 3',
public: true,
mode: 'train',
product: 'urban-train'
},
direction: 'Bruchsal',
when: '1970-01-01T20:43:00+01:00',
plannedWhen: '1970-01-01T20:43:00+01:00',
delay: null
}, {
tripId: '1|225074|0|80|28112020',
line: {
type: 'line',
id: 's-2',
fahrtNr: '38140',
name: 'S 2',
public: true,
mode: 'train',
product: 'urban-train'
},
direction: 'Kaiserslautern Hbf',
when: '1970-01-01T21:03:00+01:00',
plannedWhen: '1970-01-01T21:03:00+01:00',
delay: null
}, {
tripId: '1|225448|0|80|28112020',
line: {
type: 'line',
id: 's-3',
fahrtNr: '38358',
name: 'S 3',
public: true,
mode: 'train',
product: 'urban-train'
},
direction: 'Germersheim',
when: '1970-01-01T21:13:00+01:00',
plannedWhen: '1970-01-01T21:13:00+01:00',
delay: null
}, {
tripId: '1|225213|0|80|28112020',
line: {
type: 'line',
id: 's-2',
fahrtNr: '38248',
name: 'S 2',
public: true,
mode: 'train',
product: 'urban-train'
},
direction: 'Kaiserslautern Hbf',
when: '1970-01-01T21:33:00+01:00',
plannedWhen: '1970-01-01T21:33:00+01:00',
delay: null
}],
}],
refreshToken: '¶HKI¶T$A=1@O=Heidelberg Hbf@L=8000156@a=128@$A=1@O=Mannheim Hbf@L=8000244@a=128@$202011281813$202011281829$S 3$$1$$$',
},
}
66 changes: 66 additions & 0 deletions test/fixtures/vrn-subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"result": {
"resultCode": "OK"
},
"userId": "B3B3CBF1-86F3-4280-BFE4-E586A3624B1B",
"subscrId": 1349811,
"status": "ACTIVE",
"channels": [
{
"type": "IPHONE",
"address": "3b4b49491e1b1094be093ce6197a3fde1df6dccce33de17d37cf649ec8ec0aa7",
"options": [
{
"type": "CUSTOMER_TYPE",
"value": "com.deutschebahn.vrn"
},
{
"type": "NO_SOUND",
"value": "1"
}
],
"active": true,
"name": "PUSH_IPHONE",
"channelId": "1952745D-F196-4775-B291-FA5CD84A81D4",
"confirmed": true
}
],
"conSubscr": {
"ctxRecon": "¶HKI¶T$A=1@O=Heidelberg Hbf@L=8000156@a=128@$A=1@O=Mannheim Hbf@L=8000244@a=128@$202011281813$202011281829$S 3$$1$$$",
"serviceDays": {
"beginDate": "20191215",
"endDate": "20211211",
"selectedDays": "00011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"hysteresis": {
"minDeviationInterval": 5,
"notificationStart": 20
},
"monitorFlags": [
"AF",
"DF",
"DV",
"FTF",
"OF",
"PF"
],
"data": "GZip:H4sIAAAAAAAAE+1db1PiOhf/KkzHl3qfJm2BOuPIf2UXwQvuXnfv3nFLG6DX0rJpQVl1P9Z99by6zxd7krRAsaCIdW3XMM5A2zQ5v+Tkd05OTuuN4CIN6wNh/0YwkOuZtuaZjt1wdPZNTw+1UQdZSPe0roWEfQ+P0a4wwo4x1r2G6XrC/p83gqk7tKw7GAn7AhB2BYxc8osWuzB1RE643jS41O3ToljYz6vkgHzldoW+/6UJ+1BR7naF3qwMOWSF2Hc/+A6K3c3lONHcS3qDaXuoj/BHzRoTUQEpYGtD8kuolqvC3W7y5aynRM72u/NUyHl29HEDOV9HTLgQ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Orb6hW/FScss3n754pAfl+XvTe3Y+OPw8Ko++Xx4ODyadJza7enwk90tXrZHXqFWOz9zb4o9t3Z4eHdi9wqHh5XTWrdwVb/+s/7lS2dSuCtMylfFr7VpZXIyrVyf9CtfT/TS4GhatGo3R70PesEufi0NSqioFy+Kvcr7o6P6ZfV7Y3z8/bzVmh5759Mm7hZu6O0t77KAKn+fHh6W392UJo1vJaP+vj4o9UqffhRw0SteVqblP60irZvVX7Rr42K3Vi6XKsOiXb2oDlp1o/C5PS70C86Rd45qt7/fHf/4qNfxuVPtnZaL5ape/nGkve/+/q3kVcdnPYtAujz63sKFHwU/NTJhj9fmw4/X5rd8vDbs9GmYER5fMfAVA18x8BXDG1kxMEEQnrAR7fi9S/rMmCe+q1nRd7ONDoHETrGeoGsNwx+MUM3sn9IEpLZBT7mO53vYrFF9gPRLlzGIDLrZrqyDCzro+qAfKEzRWujKQFs6NKkH3Ta6odckLCzQv/8cv6//+88rGaJoDysLsMSSItsgXdCyK3TVIvRgFuqwqxHod3f/B+ZtUTcX4wAA",
"connectionInfo": [
{
"arrivalStation": "8000244",
"arrivalPlatform": "1",
"arrivalStationName": "Mannheim Hbf",
"arrivalTime": "2020-11-28T18:29:00Z",
"departureStation": "8000156",
"departurePlatform": "4",
"departureStationName": "Heidelberg Hbf",
"departureTime": "2020-11-28T18:13:00Z",
"productName": "S 3"
}
]
},
"eventHistory": {
"rtEvents": [],
"himEvents": []
}
}
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require('./vsn-remarks')
require('./db-netz-remarks')
require('./vsn-departures')
require('./vrn-subscription-journey')
require('./vrn-subscription')

require('./throttle')
require('./retry')
25 changes: 25 additions & 0 deletions test/vrn-subscription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const test = require('tape')

const createClient = require('..')
const rawProfile = require('../p/vrn')
const res = require('./fixtures/vrn-subscription.json')
const expected = require('./fixtures/vrn-subscription.js')

const client = createClient(rawProfile, 'public-transport/hafas-client:test')
const {profile} = client

const opt = {
journey: true,
activeDays: false,
}

test('parses a subscription correctly (VRN)', (t) => {
const common = profile.parseCommon({profile, opt, res})
const ctx = {profile, opt, common, res}
const sub = profile.parseSubscription(ctx, 'foo', res.conSubscr)

t.deepEqual(sub, expected)
t.end()
})

0 comments on commit e9dee10

Please sign in to comment.