-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiService.test.ts
More file actions
96 lines (80 loc) · 2.25 KB
/
ApiService.test.ts
File metadata and controls
96 lines (80 loc) · 2.25 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { apiService } from './ApiService';
import settings from '../../config/settings';
describe('ApiService', () => {
describe('create', () => {
it('should call POST verb from axios api', async () => {
await apiService.create({
entity: 'users',
data: {
name: 'John',
lastname: 'Doe'
}
} as any);
expect(apiService.http.post).toHaveBeenCalledWith('/users', {
name: 'John',
lastname: 'Doe'
} as any);
});
});
describe('update', () => {
it('should call PUT verb from axios api', async () => {
await apiService.update({
entity: 'users',
id: 'user-id-1',
data: {
name: 'John',
lastname: 'UpdateDoe'
}
} as any);
expect(apiService.http.put).toHaveBeenCalledWith('/users/user-id-1', {
name: 'John',
lastname: 'UpdateDoe'
});
});
});
describe('get actions', () => {
it('should call GET verb from axios api', async () => {
await apiService.get({
entity: 'users',
id: 'user-id-1'
} as any);
const getSpy = jest.spyOn(apiService.http, 'get');
expect(getSpy).toHaveBeenCalledWith('/users', {
params: {
id: 'user-id-1'
}
} as any);
});
it('should call GET verb from axios api', async () => {
await apiService.getAll({
entity: 'users',
params: {
page: 1,
limit: 100
}
} as any);
const getSpy = jest.spyOn(apiService.http, 'get');
apiService.http.get = getSpy as any;
expect(getSpy).toHaveBeenCalledWith('/users', {
params: {
id: 'user-id-1'
}
} as any);
});
});
describe('delete', () => {
it('should call DELETE verb from axios api', async () => {
await apiService.delete({
entity: 'users',
id: 'user-id-1'
});
expect(apiService.http.delete).toHaveBeenCalledWith('/users/user-id-1');
});
});
describe('http', () => {
it('should have a baseURL property with the expected value regarding the environment', async () => {
const http = apiService.http as any;
expect(http.baseURL).toEqual(settings.SERVICE.BASE_URL);
});
});
});