UNPKG

nextcaltrain

Version:
61 lines (47 loc) 1.9 kB
// jshint camelcase:false "use strict"; var test = require("tape"); var CURRENT_YEAR = new Date().getFullYear(); var loadCaltrainSchedule = require("./async"); var isStopAtStation = require("./lib/util").isStopAtStation; test("caltrain", function(t) { loadCaltrainSchedule(function(err, getSchedule) { t.ifError(err); var getNextStop = getSchedule({ from: "ctsf", to: "ctsmat", date: new Date(CURRENT_YEAR, 11, 1, 12), }); var stop = getNextStop(); t.equal(stop.serviceDate.getFullYear(), CURRENT_YEAR); t.equal(stop.serviceDate.getMonth(), 11); t.equal(stop.serviceDate.getDate(), 1); t.equal(stop.trip.route_id, stop.route.route_id); t.equal(stop.trip.service_id, stop.service.service_id); var firstTripStop = stop.tripStops[0]; var lastTripStop = stop.tripStops[stop.tripStops.length - 1]; t.equal(stop.trip.trip_id, firstTripStop.stopTime.trip_id); t.equal(firstTripStop.stopTime.stop_id, "70012"); t.equal(firstTripStop.date.getFullYear(), CURRENT_YEAR); t.equal(firstTripStop.date.getMonth(), 11); t.equal(firstTripStop.date.getDate(), 1); t.equal(firstTripStop.date.getHours(), 12); t.equal(firstTripStop.date.getMinutes(), 7); t.assert(isStopAtStation(firstTripStop.stop, stop.fromStation)); t.assert(isStopAtStation(lastTripStop.stop, stop.toStation)); // Assert trip of stop times stop.tripStops.forEach(function(tripStop) { t.equal(tripStop.stopTime.trip_id, stop.trip.trip_id); }); // Assert and station are same stop.tripStops.forEach(function(tripStop) { t.assert(isStopAtStation(tripStop.stop, tripStop.station)); }); // Assert order of dates stop.tripStops.slice(1).forEach(function(tripStop, index) { var prevTripStop = stop.tripStops[index]; t.ok(tripStop.date >= prevTripStop.date); }); t.end(); }); });