From 38382529deb5a02a51124773b3fce728dbf628c3 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Mon, 13 Jul 2026 10:19:30 -0500 Subject: [PATCH 1/6] get stop arrivals --- src/resources/Stop.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/resources/Stop.js b/src/resources/Stop.js index 8c998d7..e7f5ef9 100644 --- a/src/resources/Stop.js +++ b/src/resources/Stop.js @@ -63,6 +63,27 @@ class Stop extends Resource { .then(stop => new Stop(this.client, this, stop)); } + /** + * Fetches upcoming arrival predictions for this stop via the client. + * If the customer is configured to sign in by trip, each arrival will include + * trip, schedule, and variance information; otherwise those fields are omitted. + * @param {Object} [options] Options for the request + * @param {number} [options.count=3] Maximum number of arrivals to return. + * Must be a positive integer of 1 or greater, otherwise the default is used. + * @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 From 67090ccea8964d07678a07fd858ed8df747e5146 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Mon, 13 Jul 2026 10:19:40 -0500 Subject: [PATCH 2/6] add tests and documentation --- src/examples/get_stop_arrivals.test.js | 27 ++++++++++++++++++++++++++ src/mocks/index.js | 1 + src/mocks/stopArrivals.js | 15 ++++++++------ src/resources/Stop.test.js | 18 ++++++++++++++++- 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 src/examples/get_stop_arrivals.test.js diff --git a/src/examples/get_stop_arrivals.test.js b/src/examples/get_stop_arrivals.test.js new file mode 100644 index 0000000..feb5731 --- /dev/null +++ b/src/examples/get_stop_arrivals.test.js @@ -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; + }); +}); diff --git a/src/mocks/index.js b/src/mocks/index.js index 719259f..48397ed 100644 --- a/src/mocks/index.js +++ b/src/mocks/index.js @@ -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'; diff --git a/src/mocks/stopArrivals.js b/src/mocks/stopArrivals.js index 4d35f6b..83592ae 100644 --- a/src/mocks/stopArrivals.js +++ b/src/mocks/stopArrivals.js @@ -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' }, }, diff --git a/src/resources/Stop.test.js b/src/resources/Stop.test.js index 288ed53..1a49723 100644 --- a/src/resources/Stop.test.js +++ b/src/resources/Stop.test.js @@ -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); @@ -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)); +}); From 8ce94e5cc93cd55f5ef5e6bd9d395bc8fb695442 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Mon, 13 Jul 2026 11:12:18 -0500 Subject: [PATCH 3/6] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd71d88..63893c5 100644 --- a/package.json +++ b/package.json @@ -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": { From 9522109e9be0d954c69095c166c5ea6b592e02ec Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Mon, 13 Jul 2026 11:26:55 -0500 Subject: [PATCH 4/6] update comment for arrivals --- src/resources/Stop.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/resources/Stop.js b/src/resources/Stop.js index e7f5ef9..de47f96 100644 --- a/src/resources/Stop.js +++ b/src/resources/Stop.js @@ -64,12 +64,10 @@ class Stop extends Resource { } /** - * Fetches upcoming arrival predictions for this stop via the client. - * If the customer is configured to sign in by trip, each arrival will include - * trip, schedule, and variance information; otherwise those fields are omitted. + * 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=3] Maximum number of arrivals to return. - * Must be a positive integer of 1 or greater, otherwise the default is used. + * @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 = {}) { From a1a1f4b2ddb7a855ec7be836548ae6f60bc2f2fb Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Mon, 13 Jul 2026 11:36:59 -0500 Subject: [PATCH 5/6] 3.36.1-development.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index cfffe73..1d710d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.35.1-development-1", + "version": "3.36.1-development.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 63893c5..f514c87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.36.1", + "version": "3.36.1-development.1", "description": "Library to interact with the Syncromatics Track API", "main": "dist/index.js", "scripts": { From 3aa9a181fb4b0c2203fd4b060b78e03cde0b7fd4 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Wed, 22 Jul 2026 17:00:04 -0500 Subject: [PATCH 6/6] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f514c87..63893c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.36.1-development.1", + "version": "3.36.1", "description": "Library to interact with the Syncromatics Track API", "main": "dist/index.js", "scripts": {