-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(patterns): Added support for ability to expand models to get add…
…itional data from the API (EN-2184) (#20) * feat(patterns): Added support for ability to expand models to get additional data from the API (EN-2184) * fix(paging): Fixed paging implementation
- Loading branch information
Showing
15 changed files
with
239 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import fetchMock from 'fetch-mock'; | ||
import Track from '../index'; | ||
import { charlie, patterns as mockPatterns } from '../mocks'; | ||
|
||
chai.should(); | ||
chai.use(chaiAsPromised); | ||
|
||
describe('When searching for patterns by name', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockPatterns.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should get a list of patterns', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const patternsPromise = api.customer('SYNC').patterns() | ||
.withQuery('blue') // patterns containing "blue" in their name | ||
.getPage() | ||
.then(page => page.list) | ||
.then(patterns => patterns); // Do things with list of patterns | ||
|
||
return patternsPromise; | ||
}); | ||
}); | ||
|
||
describe('When getting a collection of patterns with their associated stop information', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockPatterns.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should get a list of patterns', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const patternsPromise = api.customer('SYNC').patterns() | ||
.withExpandedProperty('stops') | ||
.getPage() | ||
.then(page => page.list) | ||
.then(patterns => patterns); // Do things with list of patterns | ||
|
||
return patternsPromise; | ||
}); | ||
}); | ||
|
||
describe('When retrieving a pattern by ID', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockPatterns.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should get a pattern', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const patternsPromise = api.customer('SYNC').pattern(1) | ||
.fetch() | ||
.then(pattern => pattern); // Do things with pattern | ||
|
||
return patternsPromise; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.