|
| 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 RiderAppConfiguration from './RiderAppConfiguration'; |
| 6 | +import { riderAppConfiguration as mocks } from '../mocks'; |
| 7 | + |
| 8 | +chai.should(); |
| 9 | +chai.use(chaiAsPromised); |
| 10 | + |
| 11 | +describe('When instantiating a Rider App Configuration based on customer', () => { |
| 12 | + const client = new Client(); |
| 13 | + const config = new RiderAppConfiguration(client, RiderAppConfiguration.makeHref('SYNC')); |
| 14 | + |
| 15 | + it('should set the href', () => config.href.should.equal('/1/SYNC/rider_app_configuration')); |
| 16 | + it('should not be hydrated', () => config.hydrated.should.equal(false)); |
| 17 | +}); |
| 18 | + |
| 19 | +describe('When instantiating a Rider App Configuration based on an object', () => { |
| 20 | + const client = new Client(); |
| 21 | + const config = new RiderAppConfiguration(client, mocks.rawObject); |
| 22 | + |
| 23 | + it('should set the href', () => config.href.should.equal('/1/SYNC/rider_app_configuration')); |
| 24 | + it('should set the splash image url', () => config.splash_image_url.should.equal('https://example.com/logo.png')); |
| 25 | + it('should set the accent color', () => config.accent_color.should.equal('#ABCDEF')); |
| 26 | + it('should be hydrated', () => config.hydrated.should.equal(true)); |
| 27 | +}); |
| 28 | + |
| 29 | +describe('When fetching a Rider App Configuration based on customer', () => { |
| 30 | + const client = new Client(); |
| 31 | + |
| 32 | + beforeEach(() => mocks.setUpSuccessfulMock(client)); |
| 33 | + beforeEach(() => fetchMock.catch(503)); |
| 34 | + afterEach(fetchMock.restore); |
| 35 | + |
| 36 | + let promise; |
| 37 | + beforeEach(() => { |
| 38 | + promise = new RiderAppConfiguration(client, RiderAppConfiguration.makeHref('SYNC')).fetch(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should resolve the promise', () => promise.should.be.fulfilled); |
| 42 | + it('should set the href', () => promise.then(v => v.href).should.eventually.equal('/1/SYNC/rider_app_configuration')); |
| 43 | + it('should be hydrated', () => promise.then(v => v.hydrated).should.eventually.equal(true)); |
| 44 | +}); |
| 45 | + |
| 46 | +describe('When updating a Rider App Configuration for a customer', () => { |
| 47 | + const client = new Client(); |
| 48 | + |
| 49 | + beforeEach(() => mocks.setUpSuccessfulMock(client)); |
| 50 | + beforeEach(() => fetchMock.catch(503)); |
| 51 | + afterEach(fetchMock.restore); |
| 52 | + |
| 53 | + let promise; |
| 54 | + beforeEach(() => { |
| 55 | + const config = new RiderAppConfiguration(client, RiderAppConfiguration.makeHref('SYNC')); |
| 56 | + config.splash_image_url = 'https://example.com/logo.png'; |
| 57 | + config.accent_color = '#ABCDEF'; |
| 58 | + promise = config.update(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should resolve the promise', () => promise.should.be.fulfilled); |
| 62 | + it('should set the href', () => promise.then(v => v.href).should.eventually.equal('/1/SYNC/rider_app_configuration')); |
| 63 | +}); |
0 commit comments