Skip to content

Commit

Permalink
fix tests, update-mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ronhippler committed Feb 16, 2017
1 parent 159a5fe commit 4eecad0
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var monitor = function monitor(stop, offset, amount, callback) {
return requestP(options)
.then(JSON.parse)
.map(function (transport) {
console.log(transport);
var arrivalTimeRelative = parseInt(transport[2]) || 0;
return {
line: transport[0],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec",
"test-live": "NODE_ENV=test_live istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec",
"update-mocks": "NODE_ENV=test_live_update istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec"
"update-mocks": "NODE_ENV=test_update istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var assert = require('assert');

describe('dvb.address', function () {
describe('dvb.address "51.025451, 13.722943"', function () {
utils.mockRequest('address-51-13.json');
utils.mockRequest('address.json');

it('should resolve into an object with city and address properties', function (done) {
utils.dvb.address(51.025451, 13.722943)
Expand All @@ -29,7 +29,7 @@ describe('dvb.address', function () {
});

describe('dvb.address "0, 0"', function () {
utils.mockRequest('empty.json');
utils.mockRequest('address-empty.json');

it('should return null', function (done) {
utils.dvb.address(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion test/coords.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('dvb.coords', function () {
});

describe('dvb.coords "123"', function () {
utils.mockRequest('empty.json');
utils.mockRequest('coords-empty.json');

it('should return null', function (done) {
utils.dvb.coords("123")
Expand Down
1 change: 1 addition & 0 deletions test/data/address-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
File renamed without changes.
1 change: 1 addition & 0 deletions test/data/coords-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
1 change: 1 addition & 0 deletions test/data/find-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"0" }, { "name":"sessionID", "value":"0" } ], "stopFinder": { "message": [ { "name":"code", "value":"-8020" }, { "name":"error", "value":"" } ], "input": { "input":"0#" }, "points": null } }
2 changes: 1 addition & 1 deletion test/data/find-zellescherweg.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"0" }, { "name":"sessionID", "value":"0" } ], "stopFinder": { "message": [ { "name":"code", "value":"-8010" }, { "name":"error", "value":"" } ], "input": { "input":"zellesch" }, "points": { "point": { "usage":"sf", "type":"any", "name":"Dresden, Zellescher Weg", "stateless":"33000312", "anyType":"stop", "sort":"2", "quality":"682", "best":"0", "object":"Zellescher Weg", "mainLoc":"Dresden", "modes":"4,5", "ref": { "id":"33000312", "omc":"14612000", "placeID":"1", "place":"Dresden", "coords":"13.745847050,51.028365791" }, "infos": null } }, "itdOdvAssignedStops": { "stopID":"33000312", "name":"Zellescher Weg", "x":"13.745847050", "y":"51.028365791", "mapName":"WGS84[DD.ddddd]", "value":"33000312:Zellescher Weg", "place":"Dresden", "nameWithPlace":"Dresden Zellescher Weg", "distanceTime":"0", "isTransferStop":"0", "vm":"100", "gid":"de:14612:312" } } }
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"0" }, { "name":"sessionID", "value":"0" } ], "stopFinder": { "message": [ { "name":"code", "value":"-8010" }, { "name":"error", "value":"" } ], "input": { "input":"zellesch" }, "points": { "point": { "usage":"sf", "type":"any", "name":"Dresden, Zellescher Weg", "stateless":"33000312", "anyType":"stop", "sort":"2", "quality":"817", "best":"0", "object":"Zellescher Weg", "mainLoc":"Dresden", "modes":"4,5", "ref": { "id":"33000312", "omc":"14612000", "placeID":"1", "place":"Dresden", "coords":"13.745847050,51.028365791" }, "infos": null } }, "itdOdvAssignedStops": { "stopID":"33000312", "name":"Zellescher Weg", "x":"13.745847050", "y":"51.028365791", "mapName":"WGS84[DD.ddddd]", "value":"33000312:Zellescher Weg", "place":"Dresden", "nameWithPlace":"Dresden Zellescher Weg", "distanceTime":"0", "isTransferStop":"0", "vm":"100", "gid":"de:14612:312" } } }
1 change: 1 addition & 0 deletions test/data/monitor-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 1 addition & 1 deletion test/data/monitor-postplatz.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[["1","Leutewitz",""],["94","Cossebaude","1"],["12","Striesen","1"],["8","Hellerau","1"],["11","Bühlau","1"]]
[["9","Prohlis",""],["11","Bühlau",""],["4","Radebeul West","1"],["1","Prohlis","3"],["4","Laubegast","4"]]
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/data/empty_json.json → test/data/route-empty.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"1" }, { "name":"sessionID", "value":"1828882307" } ], "itdMessageList": [ ], "origin": { "message": [ { "name":"code", "value":"-2000" }, { "name":"error", "value":"stop invalid" } ], "input": { "input":"0" }, "points": null }, "destination": { "message": [ { "name":"code", "value":"-2000" }, { "name":"error", "value":"stop invalid" } ], "input": { "input":"0" }, "points": null }, "via": { "input": { "input":"" }, "points": null }, "dateTime": { "deparr":"arr", "ttpFrom":"20161211", "ttpTo":"20171209", "year":"2017", "month":"2", "day":"16", "hour":"16", "minute":"24" }, "dateRange": [ { "day":"16", "month":"02", "year":"2017", "weekday":"5" }, { "day":"17", "month":"02", "year":"2017", "weekday":"6" }, { "day":"18", "month":"02", "year":"2017", "weekday":"7" }, { "day":"19", "month":"02", "year":"2017", "weekday":"1" }, { "day":"20", "month":"02", "year":"2017", "weekday":"2" }, { "day":"21", "month":"02", "year":"2017", "weekday":"3" }, { "day":"22", "month":"02", "year":"2017", "weekday":"4" }, { "day":"23", "month":"02", "year":"2017", "weekday":"5" }, { "day":"24", "month":"02", "year":"2017", "weekday":"6" }, { "day":"25", "month":"02", "year":"2017", "weekday":"7" }, { "day":"26", "month":"02", "year":"2017", "weekday":"1" }, { "day":"27", "month":"02", "year":"2017", "weekday":"2" }, { "day":"28", "month":"02", "year":"2017", "weekday":"3" }, { "day":"01", "month":"03", "year":"2017", "weekday":"4" }, { "day":"02", "month":"03", "year":"2017", "weekday":"5" } ], "option": { "ptOption": { "active":"1", "maxChanges":"9", "maxTime":"360", "maxWait":"120", "routeType":"LEASTTIME", "changeSpeed":"normal", "lineRestriction":"400", "useProxFootSearch":"0", "useProxFootSearchOrigin":"0", "useProxFootSearchDestination":"0", "bike":"0", "plane":"0", "noCrowded":"0", "noSolidStairs":"0", "noEscalators":"0", "noElevators":"0", "lowPlatformVhcl":"0", "wheelchair":"0", "needElevatedPlt":"0", "assistance":"0", "SOSAvail":"0", "noLonelyTransfer":"0", "illumTransfer":"0", "noInsecurePlaces":"0", "privateTransport":"0", "excludedMeans": [ { "means":"Zug", "value":"0", "selected":"0" }, { "means":"S-Bahn", "value":"1", "selected":"0" }, { "means":"U-Bahn", "value":"2", "selected":"0" }, { "means":"Stadtbahn", "value":"3", "selected":"0" }, { "means":"Straßen-/Trambahn", "value":"4", "selected":"0" }, { "means":"Stadtbus", "value":"5", "selected":"0" }, { "means":"Regionalbus", "value":"6", "selected":"0" }, { "means":"Schnellbus", "value":"7", "selected":"0" }, { "means":"Seil-/Zahnradbahn", "value":"8", "selected":"0" }, { "means":"Schiff", "value":"9", "selected":"0" }, { "means":"AST/Rufbus", "value":"10", "selected":"0" }, { "means":"Sonstige", "value":"11", "selected":"0" }, { "means":"Flugzeug", "value":"12", "selected":"0" }, { "means":"Zug (Nahverkehr)", "value":"13", "selected":"0" }, { "means":"Zug (Fernverkehr)", "value":"14", "selected":"0" }, { "means":"Zug (Fernverkehr mit", "value":"15", "selected":"0" }, { "means":"Zug (Fernverkehr mit", "value":"16", "selected":"0" }, { "means":"Schienenersatzverkeh", "value":"17", "selected":"0" }, { "means":"Zug Shuttle", "value":"18", "selected":"0" }, { "means":"Bürgerbus", "value":"19", "selected":"0" } ], "activeImp":"-1", "activeCom":"-1", "activeSec":"-1" }, "itOption": { "active":"1", "itRouter": { "logASCII":"0", "logSVG":"0" }, "pedestrian": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"50", "traveltimeFactor":"50", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"30", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"connection" }, "itBicycle": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"50", "traveltimeFactor":"50", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"40", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown" }, "mitCar": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"10", "traveltimeFactor":"90", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"40", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown", "mitProfileData":"0", "mitIncidentData":"0", "mitOnlineData":"0", "noHighway":"0", "noTollRoad":"0", "prefSerSt":"0" }, "mitTaxi": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"10", "traveltimeFactor":"90", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"15", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown", "mitProfileData":"0", "mitIncidentData":"0", "mitOnlineData":"0", "noHighway":"0", "noTollRoad":"0", "prefSerSt":"0" } }, "departureTransport": { "meansCode":"100", "value":"10", "speed":"normal" }, "arrivalTransport": { "meansCode":"100", "value":"10", "speed":"normal" } }, "trips": null }
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"1" }, { "name":"sessionID", "value":"1832555959" } ], "itdMessageList": [ ], "origin": { "message": [ { "name":"code", "value":"-2000" }, { "name":"error", "value":"stop invalid" } ], "input": { "input":"0" }, "points": null }, "destination": { "message": [ { "name":"code", "value":"-2000" }, { "name":"error", "value":"stop invalid" } ], "input": { "input":"0" }, "points": null }, "via": { "input": { "input":"" }, "points": null }, "dateTime": { "deparr":"arr", "ttpFrom":"20161211", "ttpTo":"20171209", "year":"2017", "month":"2", "day":"16", "hour":"17", "minute":"25" }, "dateRange": [ { "day":"16", "month":"02", "year":"2017", "weekday":"5" }, { "day":"17", "month":"02", "year":"2017", "weekday":"6" }, { "day":"18", "month":"02", "year":"2017", "weekday":"7" }, { "day":"19", "month":"02", "year":"2017", "weekday":"1" }, { "day":"20", "month":"02", "year":"2017", "weekday":"2" }, { "day":"21", "month":"02", "year":"2017", "weekday":"3" }, { "day":"22", "month":"02", "year":"2017", "weekday":"4" }, { "day":"23", "month":"02", "year":"2017", "weekday":"5" }, { "day":"24", "month":"02", "year":"2017", "weekday":"6" }, { "day":"25", "month":"02", "year":"2017", "weekday":"7" }, { "day":"26", "month":"02", "year":"2017", "weekday":"1" }, { "day":"27", "month":"02", "year":"2017", "weekday":"2" }, { "day":"28", "month":"02", "year":"2017", "weekday":"3" }, { "day":"01", "month":"03", "year":"2017", "weekday":"4" }, { "day":"02", "month":"03", "year":"2017", "weekday":"5" } ], "option": { "ptOption": { "active":"1", "maxChanges":"9", "maxTime":"360", "maxWait":"120", "routeType":"LEASTTIME", "changeSpeed":"normal", "lineRestriction":"400", "useProxFootSearch":"0", "useProxFootSearchOrigin":"0", "useProxFootSearchDestination":"0", "bike":"0", "plane":"0", "noCrowded":"0", "noSolidStairs":"0", "noEscalators":"0", "noElevators":"0", "lowPlatformVhcl":"0", "wheelchair":"0", "needElevatedPlt":"0", "assistance":"0", "SOSAvail":"0", "noLonelyTransfer":"0", "illumTransfer":"0", "noInsecurePlaces":"0", "privateTransport":"0", "excludedMeans": [ { "means":"Zug", "value":"0", "selected":"0" }, { "means":"S-Bahn", "value":"1", "selected":"0" }, { "means":"U-Bahn", "value":"2", "selected":"0" }, { "means":"Stadtbahn", "value":"3", "selected":"0" }, { "means":"Straßen-/Trambahn", "value":"4", "selected":"0" }, { "means":"Stadtbus", "value":"5", "selected":"0" }, { "means":"Regionalbus", "value":"6", "selected":"0" }, { "means":"Schnellbus", "value":"7", "selected":"0" }, { "means":"Seil-/Zahnradbahn", "value":"8", "selected":"0" }, { "means":"Schiff", "value":"9", "selected":"0" }, { "means":"AST/Rufbus", "value":"10", "selected":"0" }, { "means":"Sonstige", "value":"11", "selected":"0" }, { "means":"Flugzeug", "value":"12", "selected":"0" }, { "means":"Zug (Nahverkehr)", "value":"13", "selected":"0" }, { "means":"Zug (Fernverkehr)", "value":"14", "selected":"0" }, { "means":"Zug (Fernverkehr mit", "value":"15", "selected":"0" }, { "means":"Zug (Fernverkehr mit", "value":"16", "selected":"0" }, { "means":"Schienenersatzverkeh", "value":"17", "selected":"0" }, { "means":"Zug Shuttle", "value":"18", "selected":"0" }, { "means":"Bürgerbus", "value":"19", "selected":"0" } ], "activeImp":"-1", "activeCom":"-1", "activeSec":"-1" }, "itOption": { "active":"1", "itRouter": { "logASCII":"0", "logSVG":"0" }, "pedestrian": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"50", "traveltimeFactor":"50", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"30", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"connection" }, "itBicycle": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"50", "traveltimeFactor":"50", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"40", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown" }, "mitCar": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"10", "traveltimeFactor":"90", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"40", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown", "mitProfileData":"0", "mitIncidentData":"0", "mitOnlineData":"0", "noHighway":"0", "noTollRoad":"0", "prefSerSt":"0" }, "mitTaxi": { "computeMonomodalTrip":"0", "computationType":"PT_AND_IT", "useElevation":"0", "speedFactor":"100", "speedFactor":"0", "distanceFactor":"10", "traveltimeFactor":"90", "noTunnel":"0", "noBridge":"0", "noFerry":"0", "maxTime":"15", "minTime":"0", "maxLength":"2147483647", "minLength":"0", "ignoreRestrictions":"0", "computeAlternativeRoutes":"0", "level":"unknown", "mitProfileData":"0", "mitIncidentData":"0", "mitOnlineData":"0", "noHighway":"0", "noTollRoad":"0", "prefSerSt":"0" } }, "departureTransport": { "meansCode":"100", "value":"10", "speed":"normal" }, "arrivalTransport": { "meansCode":"100", "value":"10", "speed":"normal" } }, "trips": null }
2 changes: 1 addition & 1 deletion test/data/route-pragerstr-postplatz.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('dvb.find', function () {
});

describe('dvb.find "0"', function () {
utils.mockRequest('empty_json.json');
utils.mockRequest('find-empty.json');

it('should return an empty array', function (done) {
utils.dvb.find('0#')
Expand Down
2 changes: 1 addition & 1 deletion test/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('dvb.monitor', function () {
});

describe('dvb.monitor "xxx"', function () {
utils.mockRequest('empty_json.json');
utils.mockRequest('monitor-empty.json');

it('should return an empty array', function (done) {
utils.dvb.monitor('xxx', 0, 5)
Expand Down
4 changes: 2 additions & 2 deletions test/pins.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('dvb.pins', function () {
});

describe('dvb.pins "51.026578, 13.713899, 51.035565, 13.737974, POI+PLATFORM"', function () {
utils.mockRequest('pins-poi-pf.json');
utils.mockRequest('pins-poi-and-platform.json');

it('should contain objects with pinType of RENT_A_BIKE or PLATFORM', function (done) {
var hasPOI = false, hasSTOP = false;
Expand All @@ -311,7 +311,7 @@ describe('dvb.pins', function () {
});

describe('dvb.pins "0, 0, 0, 0, stop"', function () {
utils.mockRequest('empty.json');
utils.mockRequest('pins-empty.json');

it('should resolve into an empty array', function (done) {
utils.dvb.pins(0, 0, 0, 0, pinTypes.STOP)
Expand Down
2 changes: 1 addition & 1 deletion test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('dvb.route', function () {
});

describe('dvb.route "0 -> 0"', function () {
utils.mockRequest('empty_json.json');
utils.mockRequest('route-empty.json');

it('should return null', function (done) {
utils.dvb.route('0', '0', new Date(), route.ARRIVAL)
Expand Down
9 changes: 6 additions & 3 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require('fs');
var mockery = require('mockery');
var bluebird = require('bluebird');
var requestP = require('request-promise');

function Utils() {
Expand All @@ -9,21 +10,23 @@ function Utils() {
Utils.prototype.mockRequest = function mockRequest(filename) {
var self = this;
before(function (done) {
if (process.env.NODE_ENV && process.env.NODE_ENV.startsWith('test_live')) {
if (process.env.NODE_ENV && process.env.NODE_ENV.indexOf('live') == -1) {
console.log("use mocks");
var file_path = __dirname + '/data/' + filename;
mockery.enable({
warnOnReplace: true,
warnOnUnregistered: false,
useCleanCache: true
});
mockery.registerMock('request-promise', function (request) {
if (process.env.NODE_ENV == 'test_live_update') {
if (process.env.NODE_ENV == 'test_update') {
return requestP(request).then(function (data) {
fs.writeFileSync(file_path, data + "\n", 'utf8');
return data;
});
} else {
return fs.readFileSync(file_path, 'utf8').trim();
var result = fs.readFileSync(file_path, 'utf8');
return bluebird.resolve(result.trim())
}
});
}
Expand Down

0 comments on commit 4eecad0

Please sign in to comment.