Commit 383ad8d6 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'remove-vue-resource-from-group-service' into 'master'

Remove vue resource from group service

See merge request gitlab-org/gitlab-ce!32420
parents df6f1dd9 e8c58d62
......@@ -95,10 +95,8 @@ export default {
if (updatePagination) {
this.updatePagination(res.headers);
}
return res;
return res.data;
})
.then(res => res.json())
.catch(() => {
this.isLoading = false;
$.scrollTo(0);
......@@ -190,11 +188,10 @@ export default {
this.targetGroup.isBeingRemoved = true;
this.service
.leaveGroup(this.targetGroup.leavePath)
.then(res => res.json())
.then(res => {
$.scrollTo(0);
this.store.removeGroup(this.targetGroup, this.targetParentGroup);
Flash(res.notice, 'notice');
Flash(res.data.notice, 'notice');
})
.catch(err => {
let message = COMMON_STR.FAILURE;
......
import Vue from 'vue';
import '../../vue_shared/vue_resource_interceptor';
import axios from '~/lib/utils/axios_utils';
export default class GroupsService {
constructor(endpoint) {
this.groups = Vue.resource(endpoint);
this.endpoint = endpoint;
}
getGroups(parentId, page, filterGroups, sort, archived) {
const data = {};
const params = {};
if (parentId) {
data.parent_id = parentId;
params.parent_id = parentId;
} else {
// Do not send the following param for sub groups
if (page) {
data.page = page;
params.page = page;
}
if (filterGroups) {
data.filter = filterGroups;
params.filter = filterGroups;
}
if (sort) {
data.sort = sort;
params.sort = sort;
}
if (archived) {
data.archived = archived;
params.archived = archived;
}
}
return this.groups.get(data);
return axios.get(this.endpoint, { params });
}
// eslint-disable-next-line class-methods-use-this
leaveGroup(endpoint) {
return Vue.http.delete(endpoint);
return axios.delete(endpoint);
}
}
---
title: Remove vue resource from group service
merge_request:
author: Lee Tickett
type: other
import '~/flash';
import $ from 'jquery';
import Vue from 'vue';
......@@ -333,7 +334,7 @@ describe('AppComponent', () => {
it('hides modal confirmation leave group and remove group item from tree', done => {
const notice = `You left the "${childGroupItem.fullName}" group.`;
spyOn(vm.service, 'leaveGroup').and.returnValue(returnServicePromise({ notice }));
spyOn(vm.service, 'leaveGroup').and.returnValue(Promise.resolve({ data: { notice } }));
spyOn(vm.store, 'removeGroup').and.callThrough();
spyOn(window, 'Flash');
spyOn($, 'scrollTo');
......
import Vue from 'vue';
import VueResource from 'vue-resource';
import axios from '~/lib/utils/axios_utils';
import GroupsService from '~/groups/service/groups_service';
import { mockEndpoint, mockParentGroupItem } from '../mock_data';
Vue.use(VueResource);
describe('GroupsService', () => {
let service;
......@@ -15,8 +12,8 @@ describe('GroupsService', () => {
describe('getGroups', () => {
it('should return promise for `GET` request on provided endpoint', () => {
spyOn(service.groups, 'get').and.stub();
const queryParams = {
spyOn(axios, 'get').and.stub();
const params = {
page: 2,
filter: 'git',
sort: 'created_asc',
......@@ -25,21 +22,21 @@ describe('GroupsService', () => {
service.getGroups(55, 2, 'git', 'created_asc', true);
expect(service.groups.get).toHaveBeenCalledWith({ parent_id: 55 });
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params: { parent_id: 55 } });
service.getGroups(null, 2, 'git', 'created_asc', true);
expect(service.groups.get).toHaveBeenCalledWith(queryParams);
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params });
});
});
describe('leaveGroup', () => {
it('should return promise for `DELETE` request on provided endpoint', () => {
spyOn(Vue.http, 'delete').and.stub();
spyOn(axios, 'delete').and.stub();
service.leaveGroup(mockParentGroupItem.leavePath);
expect(Vue.http.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath);
expect(axios.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath);
});
});
});
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