Commit 391add99 authored by Lee Tickett's avatar Lee Tickett Committed by Mike Greiling

Remove vue-resource from drafts

parent b068f72b
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
import axios from '~/lib/utils/axios_utils';
export default {
createNewDraft(endpoint, data) {
const postData = Object.assign({}, data, { draft_note: data.note });
delete postData.note;
return Vue.http.post(endpoint, postData, { emulateJSON: true });
return axios.post(endpoint, postData);
},
deleteDraft(endpoint, draftId) {
return Vue.http.delete(`${endpoint}/${draftId}`, { emulateJSON: true });
return axios.delete(`${endpoint}/${draftId}`);
},
publishDraft(endpoint, draftId) {
return Vue.http.post(endpoint, { id: draftId }, { emulateJSON: true });
return axios.post(endpoint, { id: draftId });
},
addDraftToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
return axios.post(endpoint, data);
},
fetchDrafts(endpoint) {
return Vue.http.get(endpoint);
return axios.get(endpoint);
},
publish(endpoint) {
return Vue.http.post(endpoint);
return axios.post(endpoint);
},
discard(endpoint) {
return Vue.http.delete(endpoint);
return axios.delete(endpoint);
},
update(endpoint, { draftId, note, resolveDiscussion }) {
return Vue.http.put(
`${endpoint}/${draftId}`,
{ draft_note: { note, resolve_discussion: resolveDiscussion } },
{ emulateJSON: true },
);
return axios.put(`${endpoint}/${draftId}`, {
draft_note: { note, resolve_discussion: resolveDiscussion },
});
},
};
......@@ -15,7 +15,7 @@ export const saveDraft = ({ dispatch }, draft) =>
export const addDraftToDiscussion = ({ commit }, { endpoint, data }) =>
service
.addDraftToDiscussion(endpoint, data)
.then(res => res.json())
.then(res => res.data)
.then(res => {
commit(types.ADD_NEW_DRAFT, res);
return res;
......@@ -27,7 +27,7 @@ export const addDraftToDiscussion = ({ commit }, { endpoint, data }) =>
export const createNewDraft = ({ commit }, { endpoint, data }) =>
service
.createNewDraft(endpoint, data)
.then(res => res.json())
.then(res => res.data)
.then(res => {
commit(types.ADD_NEW_DRAFT, res);
return res;
......@@ -47,7 +47,7 @@ export const deleteDraft = ({ commit, getters }, draft) =>
export const fetchDrafts = ({ commit, getters }) =>
service
.fetchDrafts(getters.getNotesData.draftsPath)
.then(res => res.json())
.then(res => res.data)
.then(data => commit(types.SET_BATCH_COMMENTS_DRAFTS, data))
.catch(() => flash(__('An error occurred while fetching pending comments')));
......@@ -95,7 +95,7 @@ export const updateDraft = ({ commit, getters }, { note, noteText, resolveDiscus
note: noteText,
resolveDiscussion,
})
.then(res => res.json())
.then(res => res.data)
.then(data => commit(types.RECEIVE_DRAFT_UPDATE_SUCCESS, data))
.then(callback)
.catch(() => flash(__('An error occurred while updating the comment')));
......
---
title: Remove vue-resource from drafts
merge_request:
author: Lee Tickett
type: other
import Vue from 'vue';
import VueResource from 'vue-resource';
import _ from 'underscore';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import testAction from 'spec/helpers/vuex_action_helper';
import * as actions from 'ee/batch_comments/stores/modules/batch_comments/actions';
Vue.use(VueResource);
describe('Batch comments store actions', () => {
let interceptor;
let res = {};
let status = 200;
let mock;
beforeEach(() => {
interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify(res), {
status,
}),
);
};
Vue.http.interceptors.push(interceptor);
mock = new MockAdapter(axios);
});
afterEach(() => {
res = {};
status = 200;
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
mock.restore();
});
describe('enableBatchComments', () => {
......@@ -56,6 +42,7 @@ describe('Batch comments store actions', () => {
describe('addDraftToDiscussion', () => {
it('commits ADD_NEW_DRAFT if no errors returned', done => {
res = { id: 1 };
mock.onAny().reply(200, res);
testAction(
actions.addDraftToDiscussion,
......@@ -68,7 +55,7 @@ describe('Batch comments store actions', () => {
});
it('does not commit ADD_NEW_DRAFT if errors returned', done => {
status = 500;
mock.onAny().reply(500);
testAction(
actions.addDraftToDiscussion,
......@@ -84,6 +71,7 @@ describe('Batch comments store actions', () => {
describe('createNewDraft', () => {
it('commits ADD_NEW_DRAFT if no errors returned', done => {
res = { id: 1 };
mock.onAny().reply(200, res);
testAction(
actions.createNewDraft,
......@@ -96,7 +84,7 @@ describe('Batch comments store actions', () => {
});
it('does not commit ADD_NEW_DRAFT if errors returned', done => {
status = 500;
mock.onAny().reply(500);
testAction(
actions.createNewDraft,
......@@ -127,6 +115,7 @@ describe('Batch comments store actions', () => {
commit,
};
res = { id: 1 };
mock.onAny().reply(200);
actions
.deleteDraft(context, { id: 1 })
......@@ -143,8 +132,7 @@ describe('Batch comments store actions', () => {
getters,
commit,
};
res = '';
status = '500';
mock.onAny().reply(500);
actions
.deleteDraft(context, { id: 1 })
......@@ -174,6 +162,7 @@ describe('Batch comments store actions', () => {
commit,
};
res = { id: 1 };
mock.onAny().reply(200, res);
actions
.fetchDrafts(context)
......@@ -201,6 +190,8 @@ describe('Batch comments store actions', () => {
});
it('dispatches actions & commits', done => {
mock.onAny().reply(200);
actions
.publishReview({ dispatch, commit, getters, rootGetters })
.then(() => {
......@@ -214,7 +205,7 @@ describe('Batch comments store actions', () => {
});
it('dispatches error commits', done => {
status = 500;
mock.onAny().reply(500);
actions
.publishReview({ dispatch, commit, getters, rootGetters })
......@@ -233,6 +224,7 @@ describe('Batch comments store actions', () => {
getNotesData: { draftsDiscardPath: gl.TEST_HOST },
};
const commit = jasmine.createSpy('commit');
mock.onAny().reply(200);
actions
.discardReview({ getters, commit })
......@@ -249,8 +241,7 @@ describe('Batch comments store actions', () => {
getNotesData: { draftsDiscardPath: gl.TEST_HOST },
};
const commit = jasmine.createSpy('commit');
status = 500;
mock.onAny().reply(500);
actions
.discardReview({ getters, commit })
......@@ -281,6 +272,7 @@ describe('Batch comments store actions', () => {
commit,
};
res = { id: 1 };
mock.onAny().reply(200, res);
actions
.updateDraft(context, { note: { id: 1 }, noteText: 'test', callback() {} })
......@@ -299,6 +291,7 @@ describe('Batch comments store actions', () => {
};
const callback = jasmine.createSpy('callback');
res = { id: 1 };
mock.onAny().reply(200, res);
actions
.updateDraft(context, { note: { id: 1 }, noteText: 'test', callback })
......
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