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