2018-04-11 09:54:19 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-02-16 07:07:04 -05:00
|
|
|
import PipelineMediator from '~/pipelines/pipeline_details_mediator';
|
2017-06-02 09:24:42 -04:00
|
|
|
|
|
|
|
describe('PipelineMdediator', () => {
|
|
|
|
let mediator;
|
2018-04-11 09:54:19 -04:00
|
|
|
let mock;
|
|
|
|
|
2017-06-02 09:24:42 -04:00
|
|
|
beforeEach(() => {
|
2018-04-11 09:54:19 -04:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mediator = new PipelineMediator({ endpoint: 'foo.json' });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2017-06-02 09:24:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set defaults', () => {
|
2018-04-11 09:54:19 -04:00
|
|
|
expect(mediator.options).toEqual({ endpoint: 'foo.json' });
|
2017-06-02 09:24:42 -04:00
|
|
|
expect(mediator.state.isLoading).toEqual(false);
|
|
|
|
expect(mediator.store).toBeDefined();
|
|
|
|
expect(mediator.service).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('request and store data', () => {
|
2018-04-11 09:54:19 -04:00
|
|
|
it('should store received data', done => {
|
|
|
|
mock.onGet('foo.json').reply(200, { id: '121123' });
|
2017-06-02 09:24:42 -04:00
|
|
|
mediator.fetchPipeline();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-04-11 09:54:19 -04:00
|
|
|
expect(mediator.store.state.pipeline).toEqual({ id: '121123' });
|
2017-06-02 09:24:42 -04:00
|
|
|
done();
|
2018-04-11 09:54:19 -04:00
|
|
|
}, 0);
|
2017-06-02 09:24:42 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|