2017-11-20 04:57:08 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-06-12 05:20:19 -04:00
|
|
|
import JobMediator from '~/jobs/job_details_mediator';
|
|
|
|
import job from './mock_data';
|
|
|
|
|
|
|
|
describe('JobMediator', () => {
|
|
|
|
let mediator;
|
2017-11-20 04:57:08 -05:00
|
|
|
let mock;
|
2017-06-12 05:20:19 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-11-20 04:57:08 -05:00
|
|
|
mediator = new JobMediator({ endpoint: 'jobs/40291672.json' });
|
|
|
|
mock = new MockAdapter(axios);
|
2017-06-12 05:20:19 -04:00
|
|
|
});
|
|
|
|
|
2018-01-23 06:42:02 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-06-12 05:20:19 -04:00
|
|
|
it('should set defaults', () => {
|
|
|
|
expect(mediator.store).toBeDefined();
|
|
|
|
expect(mediator.service).toBeDefined();
|
2017-11-20 04:57:08 -05:00
|
|
|
expect(mediator.options).toEqual({ endpoint: 'jobs/40291672.json' });
|
2017-06-12 05:20:19 -04:00
|
|
|
expect(mediator.state.isLoading).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('request and store data', () => {
|
|
|
|
beforeEach(() => {
|
2017-11-20 04:57:08 -05:00
|
|
|
mock.onGet().reply(200, job, {});
|
2017-06-12 05:20:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should store received data', (done) => {
|
|
|
|
mediator.fetchJob();
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(mediator.store.state.job).toEqual(job);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|