Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

linting issues for tab/spaces resolved.

  • Loading branch information...
commit b7d40c17118118b33bb4e748071933fb178a2b87 1 parent ba3db63
@bustardcelly authored
View
2  massroute-examples/node/grunt.js
@@ -29,6 +29,6 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-jasmine-node');
// Default task.
- grunt.registerTask('default', 'jasmine_node');
+ grunt.registerTask('default', 'lint jasmine_node');
};
View
3  massroute-examples/node/package.json
@@ -25,7 +25,8 @@
},
"devDependencies" : {
"grunt" : "~0.3.16",
- "jasmine-node": "*"
+ "jasmine-node": "*",
+ "forever": "0.10.1"
},
"private": "true",
"readme": "# massroute-node"
View
20 massroute-examples/node/script/com/custardbelly/massroute/controller.js
@@ -5,10 +5,10 @@ var promise = require('promise'),
return function( error ) {
response.format({
html: function(){
- response.render('error', error );
+ response.render('error', error );
},
json: function(){
- response.send( JSON.stringify(error) );
+ response.send( JSON.stringify(error) );
}
});
};
@@ -19,10 +19,10 @@ function renderRoutes( request, response ) {
return function( result ) {
response.format({
html: function(){
- response.render('routes', {routes:result});
+ response.render('routes', {routes:result});
},
json: function(){
- response.send( JSON.stringify(result) );
+ response.send( JSON.stringify(result) );
}
});
};
@@ -32,10 +32,10 @@ function renderDestinations( request, response ) {
return function( result ) {
response.format({
html: function(){
- response.render('destinations', {destinations:result});
+ response.render('destinations', {destinations:result});
},
json: function(){
- response.send( JSON.stringify(result) );
+ response.send( JSON.stringify(result) );
}
});
};
@@ -45,10 +45,10 @@ function renderStops( request, response ) {
return function( result ) {
response.format({
html: function(){
- response.render('stops', {stops:result});
+ response.render('stops', {stops:result});
},
json: function(){
- response.send( JSON.stringify(result) );
+ response.send( JSON.stringify(result) );
}
});
};
@@ -58,10 +58,10 @@ function renderPredictions( request, response ) {
return function( result ) {
response.format({
html: function(){
- response.render('predictions', {predictions:result});
+ response.render('predictions', {predictions:result});
},
json: function(){
- response.send( JSON.stringify(result) );
+ response.send( JSON.stringify(result) );
}
});
};
View
40 massroute-examples/node/script/com/custardbelly/massroute/doc.js
@@ -1,25 +1,25 @@
-var express = require('express'),
- swagger = require('swagger'),
- resources = require('./doc-resources');
+var express = require('express'),
+ swagger = require('swagger'),
+ resources = require('./doc-resources');
exports.init = function( app, url ) {
- swagger.setAppHandler(app);
- swagger.addGet( resources.requestRoutes )
- .addGet( resources.findDestinationsByRouteId );
+ swagger.setAppHandler(app);
+ swagger.addGet( resources.requestRoutes )
+ .addGet( resources.findDestinationsByRouteId );
- swagger.configure(url, "0.1");
+ swagger.configure(url, "0.1");
- // REST docs.
- var docs_handler = express.static(process.cwd() + '/doc/swagger-ui-1.1.0/');
- app.get(/^\/docs(\/.*)?$/, function(req, res, next) {
- if (req.url === '/docs') { // express static barfs on root url w/o trailing slash
- res.writeHead(302, { 'Location' : req.url + '/' });
- res.end();
- return;
- }
- // take off leading /docs so that connect locates file correctly
- req.url = req.url.substr('/docs'.length);
- return docs_handler(req, res, next);
- });
-}
+ // REST docs.
+ var docs_handler = express['static'](process.cwd() + '/doc/swagger-ui-1.1.0/');
+ app.get(/^\/docs(\/.*)?$/, function(req, res, next) {
+ if (req.url === '/docs') { // express static barfs on root url w/o trailing slash
+ res.writeHead(302, { 'Location' : req.url + '/' });
+ res.end();
+ return;
+ }
+ // take off leading /docs so that connect locates file correctly
+ req.url = req.url.substr('/docs'.length);
+ return docs_handler(req, res, next);
+ });
+};
View
116 massroute-examples/node/script/com/custardbelly/massroute/model.js
@@ -7,62 +7,62 @@ var _ = require('lodash');
* @param {Aray} destinations
*/
exports.RouteConfiguration = function( routeID, stops, destinations ) {
- var destinationMap,
- destinationStopMap = {};
- return {
- routeID: routeID,
- stops: stops,
- destinations: destinations,
- /**
- * Returns destination from list based on id.
- * @param {String} id
- * @return {Object} Destination object
- */
- getDestinationByID: function( id ) {
- var i = 0,
- item;
- while( i < destinations.length ) {
- item = destinations[i];
- if( id === item.tag ) {
- return item;
- }
- i++;
- }
- return undefined;
- },
- /**
- * Returns mapped destinations based on Inbound/Outbound or whichever other name associated with destination(s).
- * @return {Object} Name-based map.
- */
- getDestinations: function() {
- if( !destinationMap ) {
- destinationMap = {};
- _.each(this.destinations, function(item) {
- if( !destinationMap.hasOwnProperty(item.name) ) {
- destinationMap[item.name] = [];
- }
- destinationMap[item.name].push(item);
- });
- }
- return destinationMap;
- },
- /**
- * Returns list of of Stops associated with destination id.
- * @param {String} id
- * @return {Array} List of stops.
- */
- stopsByDestination: function ( id ) {
- if( !destinationStopMap.hasOwnProperty( id ) ) {
- var list = [],
- destination = this.getDestinationByID( id );
- if( destination ) {
- _.each( destination.stop, function( item ) {
- list[list.length] = stops[item.tag];
- });
- }
- destinationStopMap[id] = list;
- }
- return destinationStopMap[id];
- }
- };
+ var destinationMap,
+ destinationStopMap = {};
+ return {
+ routeID: routeID,
+ stops: stops,
+ destinations: destinations,
+ /**
+ * Returns destination from list based on id.
+ * @param {String} id
+ * @return {Object} Destination object
+ */
+ getDestinationByID: function( id ) {
+ var i = 0,
+ item;
+ while( i < destinations.length ) {
+ item = destinations[i];
+ if( id === item.tag ) {
+ return item;
+ }
+ i++;
+ }
+ return undefined;
+ },
+ /**
+ * Returns mapped destinations based on Inbound/Outbound or whichever other name associated with destination(s).
+ * @return {Object} Name-based map.
+ */
+ getDestinations: function() {
+ if( !destinationMap ) {
+ destinationMap = {};
+ _.each(this.destinations, function(item) {
+ if( !destinationMap.hasOwnProperty(item.name) ) {
+ destinationMap[item.name] = [];
+ }
+ destinationMap[item.name].push(item);
+ });
+ }
+ return destinationMap;
+ },
+ /**
+ * Returns list of of Stops associated with destination id.
+ * @param {String} id
+ * @return {Array} List of stops.
+ */
+ stopsByDestination: function ( id ) {
+ if( !destinationStopMap.hasOwnProperty( id ) ) {
+ var list = [],
+ destination = this.getDestinationByID( id );
+ if( destination ) {
+ _.each( destination.stop, function( item ) {
+ list[list.length] = stops[item.tag];
+ });
+ }
+ destinationStopMap[id] = list;
+ }
+ return destinationStopMap[id];
+ }
+ };
};
View
94 massroute-examples/node/script/com/custardbelly/massroute/parse-util.js
@@ -1,6 +1,6 @@
-var _ = require('lodash'),
- log4js = require('log4js'),
- logger = log4js.getLogger('service');
+var _ = require('lodash'),
+ log4js = require('log4js'),
+ logger = log4js.getLogger('service');
/**
* Converts a list of objects to a keyed map based on provided key value.
@@ -9,12 +9,12 @@ var _ = require('lodash'),
* @return {Object} Mapped object with provided itemKey as the key and object inlist as value.
*/
exports.arrayToKeyMap = function( list, itemKey ) {
- var map = {}, ls = this.mapResult(list);
- _.each( ls, function( item ) {
- map[item[itemKey]] = item;
- });
- return map;
-}
+ var map = {}, ls = this.mapResult(list);
+ _.each( ls, function( item ) {
+ map[item[itemKey]] = item;
+ });
+ return map;
+};
/**
* Returns object represented by the @ character which is a result of the libxml-to-js parser.
@@ -22,15 +22,15 @@ exports.arrayToKeyMap = function( list, itemKey ) {
* @return {Object} Object held under the @ key.
*/
exports.mapResult = function( list ) {
- if( list instanceof Array ) {
- return _.map( list, function( value ) {
- return value["@"];
- });
- }
- else {
- return list["@"];
- }
-}
+ if( list instanceof Array ) {
+ return _.map( list, function( value ) {
+ return value["@"];
+ });
+ }
+ else {
+ return list["@"];
+ }
+};
/**
* Bases prediction item and appends the list of predictions to the object.
@@ -38,37 +38,37 @@ exports.mapResult = function( list ) {
* @return {Object} Prediction object with properly parsed list of predictions.
*/
exports.mapPredictionResult = function( item ) {
- var prediction, predictions = [];
- prediction = item["@"];
- prediction.predictions = (item.direction) ? this.mapResult(item.direction.prediction) : [];
- return prediction;
-}
+ var prediction, predictions = [];
+ prediction = item["@"];
+ prediction.predictions = (item.direction) ? this.mapResult(item.direction.prediction) : [];
+ return prediction;
+};
/**
- * Returns a list of direction objects from either a list or map of parsed directions.
- * @param {Array|Object} list An array or object representing a list of directions.
+ * Returns a list of direction objects from either a list or map of parsed directions.
+ * @param {Array|Object} list An array or object representing a list of directions.
* @return {Array} A list of mapped directions based on parser results.
*/
exports.listDirectionsResult = function( list ) {
- var dir,
- directions = [],
- self = this;
- if( list instanceof Array ) {
- _.each( list, function( item ) {
- dir = item["@"];
- dir.stop = self.mapResult(item.stop);
- directions[directions.length] = dir;
- });
- }
- else {
- try {
- dir = list["@"];
- dir.stop = self.mapResult(list.stop);
- directions[directions.length] = dir;
- }
- catch( e ) {
- logger.error( 'Error in parsing direction. [REASON] :: ' + e.message );
- }
- }
- return directions;
-}
+ var dir,
+ directions = [],
+ self = this;
+ if( list instanceof Array ) {
+ _.each( list, function( item ) {
+ dir = item["@"];
+ dir.stop = self.mapResult(item.stop);
+ directions[directions.length] = dir;
+ });
+ }
+ else {
+ try {
+ dir = list["@"];
+ dir.stop = self.mapResult(list.stop);
+ directions[directions.length] = dir;
+ }
+ catch( e ) {
+ logger.error( 'Error in parsing direction. [REASON] :: ' + e.message );
+ }
+ }
+ return directions;
+};
View
130 massroute-examples/node/script/com/custardbelly/massroute/proxy.js
@@ -1,78 +1,78 @@
-var http = require('http'),
- parser = require('libxml-to-js'),
- parse_util = require('./parse-util'),
- log4js = require('log4js'),
- logger = log4js.getLogger('proxy'),
- // Requirement in using MassDOT service that client can only make a request at most every 10 seconds.
- delay = 10000,
- delayTimer = 0,
- queue = [],
- processing = false,
- Request = {
- options: undefined,
- parseDelegate: undefined,
- deferred: undefined,
- execute: function() {
- var self = this;
- http.get( self.options, function( http_res ) {
- var data = '';
- http_res.on('data', function(chunk) {
- data += chunk;
- })
- .on('end', function() {
- parser( data, self.parseDelegate(self.deferred) );
- });
- })
- .on('error', function(e) {
- self.deferred( JSON.stringify({error:e.message}) );
- });
- }
- };
+var http = require('http'),
+ parser = require('libxml-to-js'),
+ parse_util = require('./parse-util'),
+ log4js = require('log4js'),
+ logger = log4js.getLogger('proxy'),
+ // Requirement in using MassDOT service that client can only make a request at most every 10 seconds.
+ delay = 10000,
+ delayTimer = 0,
+ queue = [],
+ processing = false,
+ Request = {
+ options: undefined,
+ parseDelegate: undefined,
+ deferred: undefined,
+ execute: function() {
+ var self = this;
+ http.get( self.options, function( http_res ) {
+ var data = '';
+ http_res.on('data', function(chunk) {
+ data += chunk;
+ })
+ .on('end', function() {
+ parser( data, self.parseDelegate(self.deferred) );
+ });
+ })
+ .on('error', function(e) {
+ self.deferred( JSON.stringify({error:e.message}) );
+ });
+ }
+ };
// http://onemoredigit.com/post/1527191998/extending-objects-in-node-js
Object.defineProperty(Object.prototype, "extend", {
- enumerable: false,
- value: function(from) {
- var props = Object.getOwnPropertyNames(from);
- var dest = this;
- props.forEach(function(name) {
- var destination = Object.getOwnPropertyDescriptor(from, name);
- Object.defineProperty(dest, name, destination);
- });
- return this;
+ enumerable: false,
+ value: function(from) {
+ var props = Object.getOwnPropertyNames(from);
+ var dest = this;
+ props.forEach(function(name) {
+ var destination = Object.getOwnPropertyDescriptor(from, name);
+ Object.defineProperty(dest, name, destination);
+ });
+ return this;
}
});
function loadNext() {
- clearTimeout( delayTimer );
- if( queue.length > 0 ) {
- logger.debug( 'Request being processed...' );
- processing = true;
- queue.shift().execute();
- delayTimer = setTimeout( loadNext, delay );
- }
- else {
- processing = false;
- }
+ clearTimeout( delayTimer );
+ if( queue.length > 0 ) {
+ logger.debug( 'Request being processed...' );
+ processing = true;
+ queue.shift().execute();
+ delayTimer = setTimeout( loadNext, delay );
+ }
+ else {
+ processing = false;
+ }
}
function queueRequest( options, parseDelegate, deferred ) {
- queue[queue.length] = Object.create(Request).extend({
- options: options,
- parseDelegate: parseDelegate,
- deferred: deferred
- });
- if( !processing ) {
- logger.debug( 'Processing freed up for request.' );
- loadNext();
- }
- else {
- logger.debug( 'Request delayed...' + delayTimer + 'ms' );
- }
-};
+ queue[queue.length] = Object.create(Request).extend({
+ options: options,
+ parseDelegate: parseDelegate,
+ deferred: deferred
+ });
+ if( !processing ) {
+ logger.debug( 'Processing freed up for request.' );
+ loadNext();
+ }
+ else {
+ logger.debug( 'Request delayed...' + delayTimer + 'ms' );
+ }
+}
exports.parse_util = parse_util;
exports.requestData = function( options, parseDelegate, deferred ) {
- logger.debug( 'New request for data...' + options );
- queueRequest(options, parseDelegate, deferred);
-}
+ logger.debug( 'New request for data...' + options );
+ queueRequest(options, parseDelegate, deferred);
+};
View
224 massroute-examples/node/script/com/custardbelly/massroute/service.js
@@ -1,138 +1,138 @@
-var model = require('./model'),
- proxy = require('./proxy'),
- parse_util = proxy.parse_util,
- defer = require('promise').execute,
- routeList,
- configurations = {}, // {<routeid>:model.RouteConfiguration}
- destPath = '/service/publicXMLFeed?command=routeConfig&a=mbta&r={0}',
- predPath = '/service/publicXMLFeed?command=predictions&a=mbta&r={0}&s={1}',
- routeOptions = {
- host: 'webservices.nextbus.com',
- path: '/service/publicXMLFeed?command=routeList&a=mbta'
- },
- destOptions = { host: 'webservices.nextbus.com' },
- predOptions = { host: 'webservices.nextbus.com' },
- log4js = require('log4js'),
- logger = log4js.getLogger('service');
+var model = require('./model'),
+ proxy = require('./proxy'),
+ parse_util = proxy.parse_util,
+ defer = require('promise').execute,
+ routeList,
+ configurations = {}, // {<routeid>:model.RouteConfiguration}
+ destPath = '/service/publicXMLFeed?command=routeConfig&a=mbta&r={0}',
+ predPath = '/service/publicXMLFeed?command=predictions&a=mbta&r={0}&s={1}',
+ routeOptions = {
+ host: 'webservices.nextbus.com',
+ path: '/service/publicXMLFeed?command=routeList&a=mbta'
+ },
+ destOptions = { host: 'webservices.nextbus.com' },
+ predOptions = { host: 'webservices.nextbus.com' },
+ log4js = require('log4js'),
+ logger = log4js.getLogger('service');
function parseRoutes( deferred ) {
- return function( error, result ) {
- if( error ) {
- deferred( {error:error} );
- }
- else {
- routeList = parse_util.mapResult( result.route );
- logger.debug( 'Routes loaded. Total: ' + routeList.length );
- deferred(null, routeList);
- }
- };
+ return function( error, result ) {
+ if( error ) {
+ deferred( {error:error} );
+ }
+ else {
+ routeList = parse_util.mapResult( result.route );
+ logger.debug( 'Routes loaded. Total: ' + routeList.length );
+ deferred(null, routeList);
+ }
+ };
}
function parseDestinations( deferred ) {
- return function( error, result ) {
- if( error ) {
- deferred( {error:error} );
- }
- else {
- var route = result.route["@"],
- stops = result.route.stop,
- directions = result.route.direction,
- configuration;
+ return function( error, result ) {
+ if( error ) {
+ deferred( {error:error} );
+ }
+ else {
+ var route = result.route["@"],
+ stops = result.route.stop,
+ directions = result.route.direction,
+ configuration;
- logger.debug( "Configuration loaded for " + route.tag + "." );
- if( !configurations.hasOwnProperty(route.tag) ) {
- configurations[route.tag] = model.RouteConfiguration( route.tag, parse_util.arrayToKeyMap(stops, 'tag'), parse_util.listDirectionsResult(directions) );
- }
- configuration = configurations[route.tag];
- deferred(null, {
- route:route,
- destinations:configuration.getDestinations()
- });
- }
- };
+ logger.debug( "Configuration loaded for " + route.tag + "." );
+ if( !configurations.hasOwnProperty(route.tag) ) {
+ configurations[route.tag] = model.RouteConfiguration( route.tag, parse_util.arrayToKeyMap(stops, 'tag'), parse_util.listDirectionsResult(directions) );
+ }
+ configuration = configurations[route.tag];
+ deferred(null, {
+ route:route,
+ destinations:configuration.getDestinations()
+ });
+ }
+ };
}
function parsePredictions( deferred ) {
- return function( error, result ) {
- if( error ) {
- deferred( {error:error} );
- }
- else {
- deferred( null, parse_util.mapPredictionResult(result.predictions) );
- }
- };
+ return function( error, result ) {
+ if( error ) {
+ deferred( {error:error} );
+ }
+ else {
+ deferred( null, parse_util.mapPredictionResult(result.predictions) );
+ }
+ };
}
exports.getRoutes = function() {
- logger.debug( "Requesting routes..." );
- if( routeList && routeList.length !== 0 ) {
- logger.debug( "Returning cached routes." );
- return defer( function(deferred) {
- deferred( null, routeList );
- });
- }
- else {
- return defer( proxy.requestData, routeOptions, parseRoutes );
- }
+ logger.debug( "Requesting routes..." );
+ if( routeList && routeList.length !== 0 ) {
+ logger.debug( "Returning cached routes." );
+ return defer( function(deferred) {
+ deferred( null, routeList );
+ });
+ }
+ else {
+ return defer( proxy.requestData, routeOptions, parseRoutes );
+ }
};
exports.getDestinations = function( routeID ) {
- logger.debug( "Requesting destinations (configuration) for Route " + routeID + "..." );
- if( configurations && configurations.hasOwnProperty( routeID ) ) {
- logger.debug( "Configuration already loaded for Route " + routeID + "." );
- return defer( function(deferred) {
- deferred( null, {
- route: {title: routeID, tag: routeID},
- destinations:configurations[routeID].getDestinations()
- });
- });
- }
- else {
- destOptions.path = destPath.replace('{0}', routeID);
- return defer( proxy.requestData, destOptions, parseDestinations );
- }
+ logger.debug( "Requesting destinations (configuration) for Route " + routeID + "..." );
+ if( configurations && configurations.hasOwnProperty( routeID ) ) {
+ logger.debug( "Configuration already loaded for Route " + routeID + "." );
+ return defer( function(deferred) {
+ deferred( null, {
+ route: {title: routeID, tag: routeID},
+ destinations:configurations[routeID].getDestinations()
+ });
+ });
+ }
+ else {
+ destOptions.path = destPath.replace('{0}', routeID);
+ return defer( proxy.requestData, destOptions, parseDestinations );
+ }
};
exports.getStops = function( routeID, destinationID ) {
- var configuration;
+ var configuration;
- logger.debug( "Requesting stops along " + routeID + " for destination " + destinationID );
- if( configurations && configurations.hasOwnProperty( routeID ) ) {
- configuration = configurations[routeID];
- logger.debug( "Stops already cached for Route " + routeID +
- " on destination " + destinationID + ". Returning cache..." );
- return defer( function(deferred) {
- deferred( null, {
- route: {title: routeID, tag: routeID},
- destination: configuration.getDestinationByID( destinationID ),
- stops: configuration.stopsByDestination( destinationID )
- });
- });
- }
- else {
- return this.getDestinations( routeID ).then( function() {
- configuration = configurations[routeID];
- if( configuration ) {
- logger.debug( "Configuration loaded and returning for stops along Route " + routeID +
- " on destination " + destinationID );
- return {
- route: {title: routeID, tag: routeID},
- destination: configuration.getDestinationByID( destinationID ),
- stops: configuration.stopsByDestination( destinationID )
- };
- }
- });
- }
+ logger.debug( "Requesting stops along " + routeID + " for destination " + destinationID );
+ if( configurations && configurations.hasOwnProperty( routeID ) ) {
+ configuration = configurations[routeID];
+ logger.debug( "Stops already cached for Route " + routeID +
+ " on destination " + destinationID + ". Returning cache..." );
+ return defer( function(deferred) {
+ deferred( null, {
+ route: {title: routeID, tag: routeID},
+ destination: configuration.getDestinationByID( destinationID ),
+ stops: configuration.stopsByDestination( destinationID )
+ });
+ });
+ }
+ else {
+ return this.getDestinations( routeID ).then( function() {
+ configuration = configurations[routeID];
+ if( configuration ) {
+ logger.debug( "Configuration loaded and returning for stops along Route " + routeID +
+ " on destination " + destinationID );
+ return {
+ route: {title: routeID, tag: routeID},
+ destination: configuration.getDestinationByID( destinationID ),
+ stops: configuration.stopsByDestination( destinationID )
+ };
+ }
+ });
+ }
};
exports.getPredictions = function( routeID, destinationID, stopID ) {
- logger.debug( "Requesting predictions for stop " + stopID + " along Route " + routeID +
- " on destination " + destinationID + "..." );
- return this.getStops( routeID, destinationID ).then( function() {
- predOptions.path = predPath.replace('{0}', routeID).replace('{1}', stopID);
- return defer( proxy.requestData, predOptions, parsePredictions );
- });
+ logger.debug( "Requesting predictions for stop " + stopID + " along Route " + routeID +
+ " on destination " + destinationID + "..." );
+ return this.getStops( routeID, destinationID ).then( function() {
+ predOptions.path = predPath.replace('{0}', routeID).replace('{1}', stopID);
+ return defer( proxy.requestData, predOptions, parsePredictions );
+ });
};
View
2  massroute-examples/node/test/jasmine/spec/parser.spec.js
@@ -46,7 +46,7 @@ describe('Parser-Util', function() {
firstItem = routes[0];
expect(firstItem['@']).toBeUndefined();
- expect(firstItem['tag']).not.toBeUndefined();
+ expect(firstItem.tag).not.toBeUndefined();
});
it('should create a map of routes based on the \'tag\' value', function() {
View
2  massroute-examples/node/test/jasmine/support/mock.controller.js
@@ -1,5 +1,5 @@
var fs = require('fs'),
- parser = require('libxml-to-js'),
+ parser = require('libxml-to-js'),
proxyquire = require('proxyquire'),
baseProxyDir = process.cwd(),
baseProxyUrl = baseProxyDir + '/script/com/custardbelly/massroute',
View
60 massroute-examples/node/test/jasmine/support/mock.model.js
@@ -1,33 +1,33 @@
-var path = require('path'),
- jasmine = global.jasmine,
- baseProxyUrl = process.cwd() + '/script/com/custardbelly/massroute',
- supportUrl = process.cwd() + '/test/jasmine/support',
- model = require(path.join(baseProxyUrl,'/model.js')),
- stubbedConfiguration = model.RouteConfiguration('1', {
- "34": {
- tag: "34",
- title: "P St @ E 2nd St"
- },
- "35": {
- tag: "35",
- title: "P St @ E Broadway"
- }
- }, []);
+var path = require('path'),
+ jasmine = global.jasmine,
+ baseProxyUrl = process.cwd() + '/script/com/custardbelly/massroute',
+ supportUrl = process.cwd() + '/test/jasmine/support',
+ model = require(path.join(baseProxyUrl,'/model.js')),
+ stubbedConfiguration = model.RouteConfiguration('1', {
+ "34": {
+ tag: "34",
+ title: "P St @ E 2nd St"
+ },
+ "35": {
+ tag: "35",
+ title: "P St @ E Broadway"
+ }
+ }, []);
exports.getConfiguration = function() {
- var spyOnId = jasmine.createSpy(stubbedConfiguration);
+ var spyOnId = jasmine.createSpy(stubbedConfiguration);
- spyOnId.baseObj = stubbedConfiguration;
- spyOnId['getDestinationByID'] = 'getDestinationByID';
- spyOnId.originalValue = stubbedConfiguration['getDestinationByID'];
- spyOnId.andCallFake( function( id ) {
- return {
- tag: '5_1_var0',
- title: 'McCormack Housing via Andrew Station',
- name: 'Inbound',
- stop: [{tag: '34'},{tag: '35'}]
- };
- });
-
- return stubbedConfiguration;
-}
+ spyOnId.baseObj = stubbedConfiguration;
+ spyOnId.getDestinationByID = 'getDestinationByID';
+ spyOnId.originalValue = stubbedConfiguration.getDestinationByID;
+ spyOnId.andCallFake( function( id ) {
+ return {
+ tag: '5_1_var0',
+ title: 'McCormack Housing via Andrew Station',
+ name: 'Inbound',
+ stop: [{tag: '34'},{tag: '35'}]
+ };
+ });
+
+ return stubbedConfiguration;
+};
View
48 massroute-examples/node/test/jasmine/support/mock.service.js
@@ -1,27 +1,27 @@
-var fs = require('fs'),
- path = require('path'),
- parser = require('libxml-to-js'),
- proxyquire = require('proxyquire'),
- baseProxyDir = process.cwd(),
- baseProxyUrl = baseProxyDir + '/script/com/custardbelly/massroute',
- parse_util = require(path.join(baseProxyUrl, '/parse-util.js')),
- supportUrl = baseProxyDir + '/test/jasmine/support',
- listRegex = /routeList/,
- configRegex = /routeConfig/,
- predictionRegex = /predictions/;
+var fs = require('fs'),
+ path = require('path'),
+ parser = require('libxml-to-js'),
+ proxyquire = require('proxyquire'),
+ baseProxyDir = process.cwd(),
+ baseProxyUrl = baseProxyDir + '/script/com/custardbelly/massroute',
+ parse_util = require(path.join(baseProxyUrl, '/parse-util.js')),
+ supportUrl = baseProxyDir + '/test/jasmine/support',
+ listRegex = /routeList/,
+ configRegex = /routeConfig/,
+ predictionRegex = /predictions/;
exports.service = proxyquire.resolve( baseProxyUrl + '/service.js', baseProxyDir, {'./proxy': {
- requestData: function( options, parseDelegate, deferred ) {
- var responder = parseDelegate(deferred);
- if( options.path.match(listRegex) ) {
- parser(fs.readFileSync( supportUrl + '/routes.xml', 'utf-8' ), responder );
- }
- else if( options.path.match(configRegex) ) {
- parser(fs.readFileSync( supportUrl + '/route_config.xml', 'utf-8'), responder);
- }
- else if( options.path.match(predictionRegex) ) {
- parser(fs.readFileSync( supportUrl + '/predictions.xml', 'utf-8'), responder);
- }
- },
- parse_util: parse_util
+ requestData: function( options, parseDelegate, deferred ) {
+ var responder = parseDelegate(deferred);
+ if( options.path.match(listRegex) ) {
+ parser(fs.readFileSync( supportUrl + '/routes.xml', 'utf-8' ), responder );
+ }
+ else if( options.path.match(configRegex) ) {
+ parser(fs.readFileSync( supportUrl + '/route_config.xml', 'utf-8'), responder);
+ }
+ else if( options.path.match(predictionRegex) ) {
+ parser(fs.readFileSync( supportUrl + '/predictions.xml', 'utf-8'), responder);
+ }
+ },
+ parse_util: parse_util
}});
Please sign in to comment.
Something went wrong with that request. Please try again.