1 |
84a8db02
|
Hung Hoang
|
import {TestBed} from '@angular/core/testing';
|
2 |
|
|
|
3 |
fd5ab42e
|
Hung Hoang
|
import {UsersService} from '../api/users.service';
|
4 |
84a8db02
|
Hung Hoang
|
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
5 |
d2799ca5
|
Jakub Danek
|
import {Languages, RequestStatus, UserType, VacationType} from '../../enums/common.enum';
|
6 |
fd5ab42e
|
Hung Hoang
|
import {environment} from '../../../environments/environment';
|
7 |
84a8db02
|
Hung Hoang
|
|
8 |
|
|
describe('UsersService', () => {
|
9 |
|
|
let service: UsersService;
|
10 |
|
|
let httpMock: HttpTestingController;
|
11 |
|
|
const baseUrl: string = environment.apiUrl;
|
12 |
|
|
|
13 |
|
|
beforeEach(() => {
|
14 |
|
|
TestBed.configureTestingModule({
|
15 |
|
|
imports: [HttpClientTestingModule],
|
16 |
|
|
providers: [UsersService]
|
17 |
|
|
});
|
18 |
|
|
|
19 |
|
|
service = TestBed.get(UsersService);
|
20 |
|
|
httpMock = TestBed.get(HttpTestingController);
|
21 |
|
|
});
|
22 |
|
|
afterEach(() => httpMock.verify());
|
23 |
|
|
|
24 |
d2799ca5
|
Jakub Danek
|
it('getLoggedUser', () => {
|
25 |
|
|
const dummyData = {
|
26 |
|
|
id: 1,
|
27 |
|
|
firstName: 'Tomas',
|
28 |
|
|
lastName: 'Novak',
|
29 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
30 |
|
|
vacationCount: 8.5,
|
31 |
|
|
sickDayCount: 3,
|
32 |
|
|
status: 'ACCEPTED',
|
33 |
|
|
role: 'EMPLOYER',
|
34 |
|
|
notification: '2000/12/01 09:00:00'
|
35 |
|
|
};
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
service.getLoggedUserProfile().subscribe((data: any) => {
|
39 |
|
|
expect(data.id).toBe(1);
|
40 |
|
|
expect(data.vacationCount).toBe(8.5);
|
41 |
|
|
expect(data.sickDayCount).toBe(3);
|
42 |
|
|
expect(data.status).toBe(RequestStatus.ACCEPTED);
|
43 |
|
|
expect(data.role).toBe(UserType.EMPLOYER);
|
44 |
|
|
expect(data.notification).toBeDefined();
|
45 |
|
|
});
|
46 |
|
|
|
47 |
|
|
const req = httpMock.expectOne(baseUrl + '/api/user/me/profile');
|
48 |
|
|
expect(req.request.method).toBe('GET');
|
49 |
|
|
req.flush(dummyData);
|
50 |
|
|
});
|
51 |
|
|
|
52 |
|
|
it('getLoggedUserWithLanguage', () => {
|
53 |
|
|
const dummyData = {
|
54 |
|
|
id: 1,
|
55 |
|
|
firstName: 'Tomas',
|
56 |
|
|
lastName: 'Novak',
|
57 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
58 |
|
|
vacationCount: 8.5,
|
59 |
|
|
sickDayCount: 3,
|
60 |
|
|
status: 'ACCEPTED',
|
61 |
|
|
role: 'EMPLOYER',
|
62 |
|
|
notification: '2000/12/01 09:00:00'
|
63 |
|
|
};
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
service.getLoggedUserProfileWithLanguage(Languages.ENGLISH).subscribe((data: any) => {
|
67 |
|
|
expect(data.id).toBe(1);
|
68 |
|
|
expect(data.vacationCount).toBe(8.5);
|
69 |
|
|
expect(data.sickDayCount).toBe(3);
|
70 |
|
|
expect(data.status).toBe(RequestStatus.ACCEPTED);
|
71 |
|
|
expect(data.role).toBe(UserType.EMPLOYER);
|
72 |
|
|
expect(data.notification).toBeDefined();
|
73 |
|
|
});
|
74 |
|
|
|
75 |
|
|
const req = httpMock.expectOne(baseUrl + '/api/user/me/profile?lang=EN');
|
76 |
|
|
expect(req.request.method).toBe('GET');
|
77 |
|
|
req.flush(dummyData);
|
78 |
|
|
});
|
79 |
84a8db02
|
Hung Hoang
|
|
80 |
|
|
it('getAuthorizationRequests', () => {
|
81 |
|
|
const dummyRequests = [
|
82 |
|
|
{ id: 1, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' },
|
83 |
|
|
{ id: 2, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' },
|
84 |
|
|
{ id: 3, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' },
|
85 |
|
|
{ id: 4, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' },
|
86 |
|
|
{ id: 5, firstName: 'Tomas', lastName: 'Novak', timestamp: '2019/05/24 21:55:11' }
|
87 |
|
|
];
|
88 |
|
|
|
89 |
|
|
service.getAuthorizationRequests().subscribe((data: any) => {
|
90 |
|
|
expect(data.length).toBe(5);
|
91 |
|
|
expect(data[4].lastName).toBe('Novak');
|
92 |
|
|
expect(data[4].firstName).toBe('Tomas');
|
93 |
|
|
expect(data[4].id).toBe(5);
|
94 |
|
|
expect(data[4].timestamp).toBeDefined();
|
95 |
|
|
});
|
96 |
|
|
|
97 |
4bcef705
|
Hung Hoang
|
const req = httpMock.expectOne(baseUrl + '/api/users/requests/authorization');
|
98 |
84a8db02
|
Hung Hoang
|
expect(req.request.method).toBe('GET');
|
99 |
|
|
req.flush(dummyRequests);
|
100 |
|
|
});
|
101 |
|
|
|
102 |
|
|
it('getVacationRequests', () => {
|
103 |
|
|
const dummyRequests = [
|
104 |
|
|
{id: 1, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'},
|
105 |
|
|
{ id: 2, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', from: '09:30', to: '18:30', type: 'VACATION', timestamp: '2019/05/24 21:59:32' },
|
106 |
|
|
{id: 3, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'},
|
107 |
|
|
{ id: 4, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', from: '09:30', to: '18:30', type: 'VACATION', timestamp: '2019/05/24 21:59:32' },
|
108 |
|
|
{id: 5, firstName: 'Tomas', lastName: 'Novak', date: '2019/05/24', type: 'SICKDAY', timestamp: '2019/05/24 21:59:32'}
|
109 |
|
|
];
|
110 |
|
|
service.getVacationRequests().subscribe((data: any) => {
|
111 |
|
|
expect(data.length).toBe(5);
|
112 |
|
|
|
113 |
|
|
expect(data[0].firstName).toBeDefined();
|
114 |
|
|
expect(data[0].lastName).toBeDefined();
|
115 |
|
|
|
116 |
|
|
expect(data[0].type).toBe(VacationType.SICKDAY);
|
117 |
|
|
expect(data[0].to).toBeUndefined();
|
118 |
|
|
expect(data[0].from).toBeUndefined();
|
119 |
|
|
|
120 |
|
|
expect(data[1].type).toBe(VacationType.VACATION);
|
121 |
|
|
expect(data[1].to).toBeDefined();
|
122 |
|
|
expect(data[1].from).toBeDefined();
|
123 |
|
|
});
|
124 |
|
|
|
125 |
4bcef705
|
Hung Hoang
|
const req = httpMock.expectOne(baseUrl + '/api/users/requests/vacation');
|
126 |
84a8db02
|
Hung Hoang
|
expect(req.request.method).toBe('GET');
|
127 |
|
|
req.flush(dummyRequests);
|
128 |
|
|
});
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
it('getAllUsers', () => {
|
132 |
|
|
const dummyRequests = [
|
133 |
|
|
{
|
134 |
|
|
id: 1,
|
135 |
|
|
firstName: 'Tomas',
|
136 |
|
|
lastName: 'unknown',
|
137 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
138 |
|
|
calendar: [
|
139 |
|
|
{
|
140 |
|
|
id: 1,
|
141 |
|
|
date: '2019/05/24',
|
142 |
|
|
from: '09:00',
|
143 |
|
|
to: '13:00',
|
144 |
|
|
type: 'VACATION',
|
145 |
|
|
status: 'ACCEPTED'
|
146 |
|
|
},
|
147 |
|
|
{
|
148 |
|
|
id: 2,
|
149 |
|
|
date: '2019/05/25',
|
150 |
|
|
from: '09:00',
|
151 |
|
|
to: '13:00',
|
152 |
|
|
type: 'VACATION',
|
153 |
|
|
status: 'ACCEPTED'
|
154 |
|
|
}
|
155 |
|
|
]
|
156 |
|
|
},
|
157 |
|
|
{
|
158 |
|
|
id: 2,
|
159 |
|
|
firstName: 'Tomas',
|
160 |
|
|
lastName: 'unknown',
|
161 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
162 |
|
|
calendar: [
|
163 |
|
|
{
|
164 |
|
|
id: 1,
|
165 |
|
|
date: '2019/05/24',
|
166 |
|
|
from: '09:00',
|
167 |
|
|
to: '13:00',
|
168 |
|
|
type: 'VACATION',
|
169 |
|
|
status: 'ACCEPTED'
|
170 |
|
|
},
|
171 |
|
|
{
|
172 |
|
|
id: 2,
|
173 |
|
|
date: '2019/05/25',
|
174 |
|
|
from: '09:00',
|
175 |
|
|
to: '13:00',
|
176 |
|
|
type: 'VACATION',
|
177 |
|
|
status: 'ACCEPTED'
|
178 |
|
|
}
|
179 |
|
|
]
|
180 |
|
|
},
|
181 |
|
|
{
|
182 |
|
|
id: 3,
|
183 |
|
|
firstName: 'Tomas',
|
184 |
|
|
lastName: 'unknown',
|
185 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
186 |
|
|
calendar: [
|
187 |
|
|
{
|
188 |
|
|
id: 1,
|
189 |
|
|
date: '2019/05/24',
|
190 |
|
|
from: '09:00',
|
191 |
|
|
to: '13:00',
|
192 |
|
|
type: 'VACATION',
|
193 |
|
|
status: 'ACCEPTED'
|
194 |
|
|
},
|
195 |
|
|
{
|
196 |
|
|
id: 2,
|
197 |
|
|
date: '2019/05/25',
|
198 |
|
|
from: '09:00',
|
199 |
|
|
to: '13:00',
|
200 |
|
|
type: 'VACATION',
|
201 |
|
|
status: 'ACCEPTED'
|
202 |
|
|
}
|
203 |
|
|
]
|
204 |
|
|
},
|
205 |
|
|
{
|
206 |
|
|
id: 4,
|
207 |
|
|
firstName: 'Tomas',
|
208 |
|
|
lastName: 'unknown',
|
209 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
210 |
|
|
calendar: [
|
211 |
|
|
{
|
212 |
|
|
id: 1,
|
213 |
|
|
date: '2019/05/24',
|
214 |
|
|
from: '09:00',
|
215 |
|
|
to: '13:00',
|
216 |
|
|
type: 'VACATION',
|
217 |
|
|
status: 'ACCEPTED'
|
218 |
|
|
},
|
219 |
|
|
{
|
220 |
|
|
id: 2,
|
221 |
|
|
date: '2019/05/25',
|
222 |
|
|
from: '09:00',
|
223 |
|
|
to: '13:00',
|
224 |
|
|
type: 'VACATION',
|
225 |
|
|
status: 'ACCEPTED'
|
226 |
|
|
}
|
227 |
|
|
]
|
228 |
|
|
},
|
229 |
|
|
{
|
230 |
|
|
id: 5,
|
231 |
|
|
firstName: 'Tomas',
|
232 |
|
|
lastName: 'unknown',
|
233 |
|
|
photo: 'https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg',
|
234 |
|
|
calendar: [
|
235 |
|
|
{
|
236 |
|
|
id: 1,
|
237 |
|
|
date: '2019/05/24',
|
238 |
|
|
from: '09:00',
|
239 |
|
|
to: '13:00',
|
240 |
|
|
type: 'VACATION',
|
241 |
|
|
status: 'ACCEPTED'
|
242 |
|
|
},
|
243 |
|
|
{
|
244 |
|
|
id: 2,
|
245 |
|
|
date: '2019/05/25',
|
246 |
|
|
from: '09:00',
|
247 |
|
|
to: '13:00',
|
248 |
|
|
type: 'VACATION',
|
249 |
|
|
status: 'ACCEPTED'
|
250 |
|
|
}
|
251 |
|
|
]
|
252 |
|
|
}
|
253 |
|
|
];
|
254 |
|
|
service.getUsers().subscribe((data: any) => {
|
255 |
|
|
expect(data.length).toBe(5);
|
256 |
|
|
expect(data[0].id).toBe(1);
|
257 |
|
|
expect(data[0].firstName).toBeDefined();
|
258 |
|
|
expect(data[0].lastName).toBeDefined();
|
259 |
|
|
expect(data[0].photo).toBeDefined();
|
260 |
|
|
expect(data[0].calendar[0].type).toBe(VacationType.VACATION);
|
261 |
|
|
expect(data[0].calendar[0].status).toBe(RequestStatus.ACCEPTED);
|
262 |
|
|
expect(data[0].calendar[0].id).toBe(1);
|
263 |
|
|
expect(data[0].calendar[1].id).toBe(2);
|
264 |
|
|
});
|
265 |
|
|
|
266 |
4bcef705
|
Hung Hoang
|
const req = httpMock.expectOne(baseUrl + '/api/users');
|
267 |
84a8db02
|
Hung Hoang
|
expect(req.request.method).toBe('GET');
|
268 |
|
|
req.flush(dummyRequests);
|
269 |
|
|
});
|
270 |
|
|
|
271 |
|
|
});
|