2021-02-14 13:09:20 -05:00
|
|
|
import GroupsService from '~/groups/service/groups_service';
|
2019-09-03 23:45:28 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
import { mockEndpoint, mockParentGroupItem } from '../mock_data';
|
|
|
|
|
|
|
|
describe('GroupsService', () => {
|
|
|
|
let service;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
service = new GroupsService(mockEndpoint);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getGroups', () => {
|
|
|
|
it('should return promise for `GET` request on provided endpoint', () => {
|
2020-04-29 08:10:00 -04:00
|
|
|
jest.spyOn(axios, 'get').mockResolvedValue();
|
2019-09-03 23:45:28 -04:00
|
|
|
const params = {
|
2017-10-04 10:10:24 -04:00
|
|
|
page: 2,
|
|
|
|
filter: 'git',
|
|
|
|
sort: 'created_asc',
|
2017-10-13 04:36:25 -04:00
|
|
|
archived: true,
|
2017-10-04 10:10:24 -04:00
|
|
|
};
|
|
|
|
|
2017-10-13 04:36:25 -04:00
|
|
|
service.getGroups(55, 2, 'git', 'created_asc', true);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-09-03 23:45:28 -04:00
|
|
|
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params: { parent_id: 55 } });
|
2017-10-04 10:10:24 -04:00
|
|
|
|
2017-10-13 04:36:25 -04:00
|
|
|
service.getGroups(null, 2, 'git', 'created_asc', true);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-09-03 23:45:28 -04:00
|
|
|
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params });
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('leaveGroup', () => {
|
|
|
|
it('should return promise for `DELETE` request on provided endpoint', () => {
|
2020-04-29 08:10:00 -04:00
|
|
|
jest.spyOn(axios, 'delete').mockResolvedValue();
|
2017-10-04 10:10:24 -04:00
|
|
|
|
|
|
|
service.leaveGroup(mockParentGroupItem.leavePath);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-09-03 23:45:28 -04:00
|
|
|
expect(axios.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath);
|
2017-10-04 10:10:24 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|