Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

db-prices

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-prices - npm Package Compare versions

Comparing version
0.1.4
to
1.0.0
+1
-2
LICENSE
The MIT License (MIT)
Copyright (c) 2017, Julius Tens, Jannis R
Copyright (c) 2016, Julius Tens, Jannis R
Permission is hereby granted, free of charge, to any person obtaining a

@@ -6,0 +5,0 @@ copy of this software and associated documentation files (the "Software"),

{
"name": "db-prices",
"description": "Find the cheapest routes using the DB Sparpreise API.",
"version": "0.1.4",
"version": "1.0.0",
"keywords": [

@@ -23,3 +23,3 @@ "train",

"main": "index.js",
"files": ["index.js", "test.js"],
"files": ["index.js"],
"dependencies": {

@@ -26,0 +26,0 @@ "got": "^6.3.0",

'use strict'
const floor = require('floordate')
const isRoughlyEqual = require('is-roughly-equal')
const co = require('co').wrap
const stations = require('db-stations')
const test = require('tape-co').default
const prices = require('./index')
const hour = 60 * 60 * 1000
const day = 24 * hour
const berlin = 8011160
const münchen = 8000261
const when = new Date(floor(new Date(), 'day') + day)
const validDate = (d) => d instanceof Date && isRoughlyEqual(2 * hour, +when)
const validPrice = (p) => 'number' === typeof p && p > 0 && p < 1000
const findStation = (id) => new Promise((yay, nay) =>
stations(id).on('error', nay).once('data', yay))
const validTrip = co(function* (test, t) {
test.ok(t, 'missing trip')
test.ok(validDate(t.start), 'invalid data')
test.ok(t.from, 'missing `from`')
test.ok(yield findStation(t.from.station), 'station not found')
// test.equal(typeof t.from.platform, 'string')
test.ok(validDate(t.end))
test.ok(t.to, 'missing `to`')
test.ok(yield findStation(t.to.station), 'station not found')
// test.equal(typeof t.to.platform, 'string')
test.equal(typeof t.line, 'string')
test.equal(typeof t.type, 'string')
})
const validOffer = (test, o) => {
test.ok(o, 'missing offer')
test.equal(typeof o.discount, 'boolean')
test.ok(validPrice(o.price), 'invalid price')
test.ok(Array.isArray(o.routes), 'missing routes') // avoiding recursion here
test.equal(typeof o.anyTrain, 'boolean')
}
const validRoute = co(function* (test, r) {
test.ok(r, 'missing route')
test.ok(Array.isArray(r.trips), 'missing trips')
test.ok(r.trips.length > 0, 'missing trips')
for (let trip of r.trips)
yield validTrip(test, trip)
test.equal(typeof r.transfers, 'number')
test.ok(r.transfers >= 0 && r.transfers < 10, 'weird nr of transfers')
test.equal(typeof r.nightTrain, 'boolean')
validOffer(test, r.offer)
})
test('Berlin Hbf -> München Hbf', function* (test) {
const results = yield prices(berlin, münchen, when)
test.ok(Array.isArray(results))
test.ok(results.length > 0, 'no results')
for (let result of results)
yield validRoute(test, result)
})
// todo: opt.class
// todo: opt.noICETrains
// todo: opt.transferTime
// todo: opt.duration
// todo: opt.preferFastRoutes