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