Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "syncromatics-track-api",
"version": "3.36.0",
"version": "3.36.1",
"description": "Library to interact with the Syncromatics Track API",
"main": "dist/index.js",
"scripts": {
Expand Down
27 changes: 27 additions & 0 deletions src/examples/get_stop_arrivals.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import fetchMock from 'fetch-mock';
import Track from '../index';
import { charlie, stopArrivals as mockStopArrivals } from '../mocks';

chai.should();
chai.use(chaiAsPromised);

describe('When retrieving arrivals for a stop', () => {
const api = new Track({ autoRenew: false });

beforeEach(() => charlie.setUpSuccessfulMock(api.client));
beforeEach(() => mockStopArrivals.setUpSuccessfulMock(api.client));
beforeEach(() => fetchMock.catch(503));
afterEach(fetchMock.restore);

it('should get a list of arrivals for the stop', () => {
api.logIn({ username: 'charlie@example.com', password: 'securepassword' });

const arrivalsPromise = api.customer('SYNC').stop(1)
.arrivals()
.then(arrivals => arrivals); // Do things with list of arrivals

return arrivalsPromise;
});
});
1 change: 1 addition & 0 deletions src/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { default as servicePackages } from './servicePackages';
export { default as services } from './services';
export { default as signs } from './signs';
export { default as stops } from './stops';
export { default as stopArrivals } from './stopArrivals';
export { default as tags } from './tags';
export { default as trips } from './trips';
export { default as twitter } from './twitter';
Expand Down
15 changes: 9 additions & 6 deletions src/mocks/stopArrivals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ const stopArrivals = {
},
list: [
{
secondsToArrival: 60,
as_of: '2017-01-01T00:00:00.000-07:00',
source: 'realtime',
arrive_variance: 30,
as_of: '2017-01-01T00:00:15.000-07:00',
pattern: { href: '/1/SYNC/patterns/1' },
route: { href: '/1/SYNC/routes/1' },
scheduled_arrival: '2017-01-01T00:00:45.000-07:00',
seconds_to_arrival: 60,
source: 'realtime',
stop: { href: '/1/SYNC/stops/1' },
trip: { href: '/1/SYNC/trips/1' },
vehicle: { href: '/1/SYNC/vehicles/1' },
},
{
secondsToArrival: 360,
as_of: '2017-01-01T00:00:00.000-07:00',
source: 'realtime',
as_of: '2017-01-01T00:00:15.000-07:00',
pattern: { href: '/1/SYNC/patterns/1' },
route: { href: '/1/SYNC/routes/1' },
seconds_to_arrival: 360,
source: 'realtime',
stop: { href: '/1/SYNC/stops/1' },
vehicle: { href: '/1/SYNC/vehicles/2' },
},
Expand Down
19 changes: 19 additions & 0 deletions src/resources/Stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ class Stop extends Resource {
.then(stop => new Stop(this.client, this, stop));
}

/**
* Fetches upcoming arrival predictions for this stop.
* For more information, read official Track-API documentation.
* @param {Object} [options] Options for the request
* @param {number} [options.count] Optional maximum number of arrivals to return.
* @returns {Promise} If successful, an array of arrival prediction objects for this stop
*/
arrivals(options = {}) {
const { count } = options;
let url = `${this.href}/arrivals`;

if (count) {
url += `?count=${count}`;
}

return this.client.get(url)
.then(response => response.json());
}

/**
* Saves data for a stop via the client
* @returns {Promise} If successful, returns a stop with the id included
Expand Down
18 changes: 17 additions & 1 deletion src/resources/Stop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chaiAsPromised from 'chai-as-promised';
import fetchMock from 'fetch-mock';
import Client from '../Client';
import Stop from './Stop';
import { stops as mockStops } from '../mocks';
import { stops as mockStops, stopArrivals as mockStopArrivals } from '../mocks';

chai.should();
chai.use(chaiAsPromised);
Expand Down Expand Up @@ -84,3 +84,19 @@ describe('When updating a stop', () => {
it('should set the href', () => promise.then(v => v.href).should.eventually.equal('/1/SYNC/stops/1'));
it('should set the name', () => promise.then(v => v.name).should.eventually.equal(updateValue));
});

describe('When fetching arrivals for a stop', () => {
const client = new Client();

beforeEach(() => mockStopArrivals.setUpSuccessfulMock(client));
beforeEach(() => fetchMock.catch(503));
afterEach(fetchMock.restore);

let promise;
beforeEach(() => {
promise = new Stop(client, Stop.makeHref('SYNC', 1)).arrivals();
});

it('should resolve the promise', () => promise.should.be.fulfilled);
it('should return the list of arrivals', () => promise.should.eventually.deep.equal(mockStopArrivals.list));
});
Loading