Commit bd3e95ea authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Clement Ho

Replace vue resource with axios for pipeline details page

parent b2f57a56
...@@ -40,10 +40,8 @@ export default class pipelinesMediator { ...@@ -40,10 +40,8 @@ export default class pipelinesMediator {
} }
successCallback(response) { successCallback(response) {
return response.json().then((data) => {
this.state.isLoading = false; this.state.isLoading = false;
this.store.storePipeline(data); this.store.storePipeline(response.data);
});
} }
errorCallback() { errorCallback() {
......
import Vue from 'vue'; import axios from '../../lib/utils/axios_utils';
import VueResource from 'vue-resource';
Vue.use(VueResource);
export default class PipelineService { export default class PipelineService {
constructor(endpoint) { constructor(endpoint) {
this.pipeline = Vue.resource(endpoint); this.pipeline = endpoint;
} }
getPipeline() { getPipeline() {
return this.pipeline.get(); return axios.get(this.pipeline);
} }
// eslint-disable-next-line // eslint-disable-next-line class-methods-use-this
postAction(endpoint) { postAction(endpoint) {
return Vue.http.post(`${endpoint}.json`); return axios.post(`${endpoint}.json`);
} }
} }
---
title: Replace vue resource with axios for pipelines details page
merge_request:
author:
type: other
import _ from 'underscore'; import MockAdapter from 'axios-mock-adapter';
import Vue from 'vue'; import axios from '~/lib/utils/axios_utils';
import PipelineMediator from '~/pipelines/pipeline_details_mediator'; import PipelineMediator from '~/pipelines/pipeline_details_mediator';
describe('PipelineMdediator', () => { describe('PipelineMdediator', () => {
let mediator; let mediator;
let mock;
beforeEach(() => { beforeEach(() => {
mediator = new PipelineMediator({ endpoint: 'foo' }); mock = new MockAdapter(axios);
mediator = new PipelineMediator({ endpoint: 'foo.json' });
});
afterEach(() => {
mock.restore();
}); });
it('should set defaults', () => { it('should set defaults', () => {
expect(mediator.options).toEqual({ endpoint: 'foo' }); expect(mediator.options).toEqual({ endpoint: 'foo.json' });
expect(mediator.state.isLoading).toEqual(false); expect(mediator.state.isLoading).toEqual(false);
expect(mediator.store).toBeDefined(); expect(mediator.store).toBeDefined();
expect(mediator.service).toBeDefined(); expect(mediator.service).toBeDefined();
}); });
describe('request and store data', () => { describe('request and store data', () => {
const interceptor = (request, next) => { it('should store received data', done => {
next(request.respondWith(JSON.stringify({ foo: 'bar' }), { mock.onGet('foo.json').reply(200, { id: '121123' });
status: 200,
}));
};
beforeEach(() => {
Vue.http.interceptors.push(interceptor);
});
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptor, interceptor);
});
it('should store received data', (done) => {
mediator.fetchPipeline(); mediator.fetchPipeline();
setTimeout(() => { setTimeout(() => {
expect(mediator.store.state.pipeline).toEqual({ foo: 'bar' }); expect(mediator.store.state.pipeline).toEqual({ id: '121123' });
done(); done();
}); }, 0);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment