1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import GroupsService from '~/groups/service/groups_service';
import axios from '~/lib/utils/axios_utils';
import { mockEndpoint, mockParentGroupItem } from '../mock_data';
describe('GroupsService', () => {
let service;
beforeEach(() => {
service = new GroupsService(mockEndpoint, 'created_asc');
});
describe('getGroups', () => {
it('should return promise for `GET` request on provided endpoint', () => {
jest.spyOn(axios, 'get').mockResolvedValue();
const params = {
page: 2,
filter: 'git',
sort: 'created_asc',
};
service.getGroups(55, 2, 'git', 'created_asc');
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params: { parent_id: 55 } });
service.getGroups(null, 2, 'git', 'created_asc');
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, { params });
});
describe('when sort argument is undefined', () => {
it('calls API with `initialSort` argument', () => {
jest.spyOn(axios, 'get').mockResolvedValue();
service.getGroups(undefined, 2, 'git', undefined);
expect(axios.get).toHaveBeenCalledWith(mockEndpoint, {
params: { sort: 'created_asc', filter: 'git', page: 2 },
});
});
});
});
describe('leaveGroup', () => {
it('should return promise for `DELETE` request on provided endpoint', () => {
jest.spyOn(axios, 'delete').mockResolvedValue();
service.leaveGroup(mockParentGroupItem.leavePath);
expect(axios.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath);
});
});
});
|