Commit 51db1086 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'remove-vue-resource-from-related-issues' into 'master'

Remove vue-resource from related-issues

See merge request gitlab-org/gitlab-ee!16057
parents 43838cdd 99ef7a4e
...@@ -114,8 +114,7 @@ export default { ...@@ -114,8 +114,7 @@ export default {
if (issueToRemove) { if (issueToRemove) {
RelatedIssuesService.remove(issueToRemove.relation_path) RelatedIssuesService.remove(issueToRemove.relation_path)
.then(res => res.json()) .then(({ data }) => {
.then(data => {
this.store.setRelatedIssues(data.issuables); this.store.setRelatedIssues(data.issuables);
}) })
.catch(res => { .catch(res => {
...@@ -140,8 +139,7 @@ export default { ...@@ -140,8 +139,7 @@ export default {
this.isSubmitting = true; this.isSubmitting = true;
this.service this.service
.addRelatedIssues(this.state.pendingReferences) .addRelatedIssues(this.state.pendingReferences)
.then(res => res.json()) .then(({ data }) => {
.then(data => {
// We could potentially lose some pending issues in the interim here // We could potentially lose some pending issues in the interim here
this.store.setPendingReferences([]); this.store.setPendingReferences([]);
this.store.setRelatedIssues(data.issuables); this.store.setRelatedIssues(data.issuables);
...@@ -169,9 +167,8 @@ export default { ...@@ -169,9 +167,8 @@ export default {
this.isFetching = true; this.isFetching = true;
this.service this.service
.fetchRelatedIssues() .fetchRelatedIssues()
.then(res => res.json()) .then(({ data }) => {
.then(issues => { this.store.setRelatedIssues(data);
this.store.setRelatedIssues(issues);
this.isFetching = false; this.isFetching = false;
}) })
.catch(() => { .catch(() => {
...@@ -189,9 +186,8 @@ export default { ...@@ -189,9 +186,8 @@ export default {
move_before_id: beforeId, move_before_id: beforeId,
move_after_id: afterId, move_after_id: afterId,
}) })
.then(res => res.json()) .then(({ data }) => {
.then(res => { if (!data.message) {
if (!res.message) {
this.store.updateIssueOrder(oldIndex, newIndex); this.store.updateIssueOrder(oldIndex, newIndex);
} }
}) })
......
import Vue from 'vue'; import axios from '~/lib/utils/axios_utils';
import vueResource from 'vue-resource';
Vue.use(vueResource);
class RelatedIssuesService { class RelatedIssuesService {
constructor(endpoint) { constructor(endpoint) {
this.relatedIssuesResource = Vue.resource(endpoint); this.endpoint = endpoint;
} }
fetchRelatedIssues() { fetchRelatedIssues() {
return this.relatedIssuesResource.get(); return axios.get(this.endpoint);
} }
addRelatedIssues(newIssueReferences) { addRelatedIssues(newIssueReferences) {
return this.relatedIssuesResource.save( return axios.post(this.endpoint, {
{}, issuable_references: newIssueReferences,
{ });
issuable_references: newIssueReferences,
},
);
} }
static saveOrder({ endpoint, move_before_id, move_after_id }) { static saveOrder({ endpoint, move_before_id, move_after_id }) {
return Vue.http.put(endpoint, { return axios.put(endpoint, {
epic: { epic: {
move_before_id, move_before_id,
move_after_id, move_after_id,
...@@ -31,7 +25,7 @@ class RelatedIssuesService { ...@@ -31,7 +25,7 @@ class RelatedIssuesService {
} }
static remove(endpoint) { static remove(endpoint) {
return Vue.http.delete(endpoint); return axios.delete(endpoint);
} }
} }
......
---
title: Remove vue-resource from related-issues
merge_request: 16057
author: Lee Tickett
type: other
import Vue from 'vue'; import Vue from 'vue';
import _ from 'underscore'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import relatedIssuesRoot from 'ee/related_issues/components/related_issues_root.vue'; import relatedIssuesRoot from 'ee/related_issues/components/related_issues_root.vue';
import relatedIssuesService from 'ee/related_issues/services/related_issues_service'; import relatedIssuesService from 'ee/related_issues/services/related_issues_service';
import { import {
...@@ -11,15 +12,18 @@ import { ...@@ -11,15 +12,18 @@ import {
describe('RelatedIssuesRoot', () => { describe('RelatedIssuesRoot', () => {
let RelatedIssuesRoot; let RelatedIssuesRoot;
let vm; let vm;
let mock;
beforeEach(() => { beforeEach(() => {
RelatedIssuesRoot = Vue.extend(relatedIssuesRoot); RelatedIssuesRoot = Vue.extend(relatedIssuesRoot);
mock = new MockAdapter(axios);
}); });
afterEach(() => { afterEach(() => {
if (vm) { if (vm) {
vm.$destroy(); vm.$destroy();
} }
mock.restore();
}); });
describe('methods', () => { describe('methods', () => {
...@@ -40,40 +44,19 @@ describe('RelatedIssuesRoot', () => { ...@@ -40,40 +44,19 @@ describe('RelatedIssuesRoot', () => {
}); });
it('remove related issue and succeeds', done => { it('remove related issue and succeeds', done => {
const interceptor = (request, next) => { mock.onAny().reply(200, { issues: [] });
next(
request.respondWith(
JSON.stringify({
issues: [],
}),
{
status: 200,
},
),
);
};
Vue.http.interceptors.push(interceptor);
vm.onRelatedIssueRemoveRequest(issuable1.id); vm.onRelatedIssueRemoveRequest(issuable1.id);
setTimeout(() => { setTimeout(() => {
expect(vm.state.relatedIssues).toEqual([]); expect(vm.state.relatedIssues).toEqual([]);
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
done(); done();
}); });
}); });
it('remove related issue, fails, and restores to related issues', done => { it('remove related issue, fails, and restores to related issues', done => {
const interceptor = (request, next) => { mock.onAny().reply(422, {});
next(
request.respondWith(JSON.stringify({}), {
status: 422,
}),
);
};
Vue.http.interceptors.push(interceptor);
vm.onRelatedIssueRemoveRequest(issuable1.id); vm.onRelatedIssueRemoveRequest(issuable1.id);
...@@ -81,8 +64,6 @@ describe('RelatedIssuesRoot', () => { ...@@ -81,8 +64,6 @@ describe('RelatedIssuesRoot', () => {
expect(vm.state.relatedIssues.length).toEqual(1); expect(vm.state.relatedIssues.length).toEqual(1);
expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id); expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id);
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
done(); done();
}); });
}); });
...@@ -162,23 +143,13 @@ describe('RelatedIssuesRoot', () => { ...@@ -162,23 +143,13 @@ describe('RelatedIssuesRoot', () => {
}); });
it('submit pending issue as related issue', done => { it('submit pending issue as related issue', done => {
const interceptor = (request, next) => { mock.onAny().reply(200, {
next( issuables: [issuable1],
request.respondWith( result: {
JSON.stringify({ message: 'something was successfully related',
issuables: [issuable1], status: 'success',
result: { },
message: 'something was successfully related', });
status: 'success',
},
}),
{
status: 200,
},
),
);
};
Vue.http.interceptors.push(interceptor);
vm.store.setPendingReferences([issuable1.reference]); vm.store.setPendingReferences([issuable1.reference]);
vm.onPendingFormSubmit(); vm.onPendingFormSubmit();
...@@ -188,30 +159,18 @@ describe('RelatedIssuesRoot', () => { ...@@ -188,30 +159,18 @@ describe('RelatedIssuesRoot', () => {
expect(vm.state.relatedIssues.length).toEqual(1); expect(vm.state.relatedIssues.length).toEqual(1);
expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id); expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id);
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
done(); done();
}); });
}); });
it('submit multiple pending issues as related issues', done => { it('submit multiple pending issues as related issues', done => {
const interceptor = (request, next) => { mock.onAny().reply(200, {
next( issuables: [issuable1, issuable2],
request.respondWith( result: {
JSON.stringify({ message: 'something was successfully related',
issuables: [issuable1, issuable2], status: 'success',
result: { },
message: 'something was successfully related', });
status: 'success',
},
}),
{
status: 200,
},
),
);
};
Vue.http.interceptors.push(interceptor);
vm.store.setPendingReferences([issuable1.reference, issuable2.reference]); vm.store.setPendingReferences([issuable1.reference, issuable2.reference]);
vm.onPendingFormSubmit(); vm.onPendingFormSubmit();
...@@ -222,8 +181,6 @@ describe('RelatedIssuesRoot', () => { ...@@ -222,8 +181,6 @@ describe('RelatedIssuesRoot', () => {
expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id); expect(vm.state.relatedIssues[0].id).toEqual(issuable1.id);
expect(vm.state.relatedIssues[1].id).toEqual(issuable2.id); expect(vm.state.relatedIssues[1].id).toEqual(issuable2.id);
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
done(); done();
}); });
}); });
...@@ -248,29 +205,17 @@ describe('RelatedIssuesRoot', () => { ...@@ -248,29 +205,17 @@ describe('RelatedIssuesRoot', () => {
}); });
describe('fetchRelatedIssues', () => { describe('fetchRelatedIssues', () => {
const interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify([issuable1, issuable2]), {
status: 200,
}),
);
};
beforeEach(done => { beforeEach(done => {
Vue.http.interceptors.push(interceptor);
vm = new RelatedIssuesRoot({ vm = new RelatedIssuesRoot({
propsData: defaultProps, propsData: defaultProps,
}).$mount(); }).$mount();
mock.onAny().reply(200, [issuable1, issuable2]);
// wait for internal call to fetchRelatedIssues to resolve // wait for internal call to fetchRelatedIssues to resolve
setTimeout(done); setTimeout(done);
}); });
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
});
it('sets isFetching while fetching', done => { it('sets isFetching while fetching', done => {
vm.fetchRelatedIssues(); vm.fetchRelatedIssues();
......
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