-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
30ad86d
commit f089a0b
Showing
15 changed files
with
268 additions
and
335 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,115 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import fetchMock from 'fetch-mock'; | ||
import Track from '../index'; | ||
import { charlie, messages as mockMessages } from '../mocks'; | ||
|
||
chai.should(); | ||
chai.use(chaiAsPromised); | ||
|
||
describe('When searching for messages by name', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockMessages.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should get a list of messages', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const messagesPromise = api.customer('SYNC').messages() | ||
.withQuery('5k') // Messages containing "5k" in their name | ||
.getPage() | ||
.then(page => page.list) | ||
.then(messages => messages); // Do things with list of messages | ||
|
||
return messagesPromise; | ||
}); | ||
}); | ||
|
||
describe('When retrieving a message by ID', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockMessages.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should get a message', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const messagePromise = api.customer('SYNC').message(1) | ||
.fetch() | ||
.then(message => message); // Do things with message | ||
|
||
return messagePromise; | ||
}); | ||
}); | ||
|
||
describe('When creating a message', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockMessages.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should save a message', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const messagePromise = api.customer('SYNC') | ||
.message({ | ||
href: '/1/SYNC/messages/1', | ||
id: 1, | ||
name: '5k Detour', | ||
text: 'Due to the 5k Race, buses will detour off Figueroa from 6pm to 11am on 2/15/17. Find northbound buses on Hope, southbound buses on Flower.', | ||
start_date: '2017-02-12T08:00:00-08:00', | ||
end_date: '2017-02-15T11:00:00-08:00', | ||
start_time: '08:00:00', | ||
duration: '02:00:00', | ||
days_of_week: 'Monday', | ||
manual_archive_date: null, | ||
tags: [{ | ||
href: '/1/SYNC/tags/1', | ||
}], | ||
routes: [{ | ||
href: '/1/SYNC/routes/1', | ||
}], | ||
stops: [{ | ||
href: '/1/SYNC/stops/1', | ||
}], | ||
sign_messages: [{ | ||
id: 1, | ||
override_text: 'Bus Detour Due to 5k Race', | ||
}], | ||
}) | ||
.create() | ||
.then(message => message); // Do things with message | ||
|
||
return messagePromise; | ||
}); | ||
}); | ||
|
||
describe('When updating a message', () => { | ||
const api = new Track({ autoRenew: false }); | ||
|
||
beforeEach(() => charlie.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => mockMessages.setUpSuccessfulMock(api.client)); | ||
beforeEach(() => fetchMock.catch(503)); | ||
afterEach(fetchMock.restore); | ||
|
||
it('should update a message', () => { | ||
api.logIn({ username: '[email protected]', password: 'securepassword' }); | ||
|
||
const messagePromise = api.customer('SYNC').message(1) | ||
.fetch() | ||
.then((message) => { | ||
// eslint-disable-next-line no-param-reassign | ||
message.name = 'Updated Message Name'; | ||
return message.update(); | ||
}); | ||
|
||
return messagePromise; | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import fetchMock from 'fetch-mock'; | ||
import Client from '../Client'; | ||
|
||
const messages = { | ||
setUpSuccessfulMock: (client) => { | ||
const listResponse = () => new Response( | ||
Client.toBlob(messages.list), { | ||
headers: { | ||
Link: '</1/SYNC/messages?page=1&per_page=10&q=5k&sort=>; rel="next", </1/SYNC/messages?page=1&per_page=10&q=5k&sort=>; rel="last"', | ||
}, | ||
}); | ||
const singleResponse = () => new Response(Client.toBlob(messages.getById(1))); | ||
const createResponse = () => new Response(undefined, { | ||
headers: { | ||
Location: '/1/SYNC/messages/1', | ||
}, | ||
}); | ||
|
||
fetchMock | ||
.get(client.resolve('/1/SYNC/messages?page=1&per_page=10&q=5k&sort='), listResponse) | ||
.get(client.resolve('/1/SYNC/messages/1'), singleResponse) | ||
.post(client.resolve('/1/SYNC/messages'), createResponse) | ||
.put(client.resolve('/1/SYNC/messages/1'), createResponse); | ||
}, | ||
getById: id => messages.list.find(v => v.id === id), | ||
list: [{ | ||
href: '/1/SYNC/messages/1', | ||
id: 1, | ||
name: '5k Detour', | ||
text: 'Due to the 5k Race, buses will detour off Figueroa from 6pm to 11am on 2/15/17. Find northbound buses on Hope, southbound buses on Flower.', | ||
start_date: '2017-02-12T08:00:00-08:00', | ||
end_date: '2017-02-15T11:00:00-08:00', | ||
start_time: '08:00:00', | ||
duration: '02:00:00', | ||
days_of_week: 'Monday', | ||
manual_archive_date: null, | ||
tags: [{ | ||
href: '/1/SYNC/tags/1', | ||
}], | ||
routes: [{ | ||
href: '/1/SYNC/routes/1', | ||
}], | ||
stops: [{ | ||
href: '/1/SYNC/stops/1', | ||
}], | ||
sign_messages: [{ | ||
id: 1, | ||
override_text: 'Bus Detour Due to 5k Race', | ||
}], | ||
}], | ||
}; | ||
|
||
export default messages; |
Oops, something went wrong.