|
| 1 | +import chai from 'chai'; |
| 2 | +import chaiAsPromised from 'chai-as-promised'; |
| 3 | +import fetchMock from 'fetch-mock'; |
| 4 | +import Client from '../Client'; |
| 5 | +import AssignableStop from './AssignableStop'; |
| 6 | +import { assignableStops as mockAssignableStops } from '../mocks'; |
| 7 | + |
| 8 | +chai.should(); |
| 9 | +chai.use(chaiAsPromised); |
| 10 | + |
| 11 | +describe('When instantiating an assignable route based on customer and ID', () => { |
| 12 | + const client = new Client(); |
| 13 | + const assignableRoute = new AssignableStop(client, AssignableStop.makeHref('SYNC', '1st_and_main')); |
| 14 | + |
| 15 | + it('should set the href', () => assignableRoute.href.should.equal('/1/SYNC/assignable_entities/stops/1st_and_main')); |
| 16 | + it('should not be hydrated', () => assignableRoute.hydrated.should.equal(false)); |
| 17 | +}); |
| 18 | + |
| 19 | +describe('When instantiating an assignable route based on an object', () => { |
| 20 | + const client = new Client(); |
| 21 | + const assignableRoute = new AssignableStop(client, mockAssignableStops.getById('1st_and_main')); |
| 22 | + |
| 23 | + it('should set the ID', () => assignableRoute.id.should.equal('1st_and_main')); |
| 24 | + it('should set the href', () => assignableRoute.href.should.equal('/1/SYNC/assignable_entities/stops/1st_and_main')); |
| 25 | + it('should be hydrated', () => assignableRoute.hydrated.should.equal(true)); |
| 26 | +}); |
| 27 | + |
| 28 | +describe('When fetching an assignable route based on customer and ID', () => { |
| 29 | + const client = new Client(); |
| 30 | + |
| 31 | + beforeEach(() => mockAssignableStops.setUpSuccessfulMock(client)); |
| 32 | + beforeEach(() => fetchMock.catch(503)); |
| 33 | + afterEach(fetchMock.restore); |
| 34 | + |
| 35 | + let promise; |
| 36 | + beforeEach(() => { |
| 37 | + promise = new AssignableStop(client, AssignableStop.makeHref('SYNC', '1st_and_main')).fetch(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should resolve the promise', () => promise.should.be.fulfilled); |
| 41 | + it('should set the ID', () => promise.then(v => v.id).should.eventually.equal('1st_and_main')); |
| 42 | + it('should set the href', () => promise.then(v => v.href).should.eventually.equal('/1/SYNC/assignable_entities/stops/1st_and_main')); |
| 43 | + it('should be hydrated', () => promise.then(v => v.hydrated).should.eventually.equal(true)); |
| 44 | +}); |
0 commit comments