1 |
4bcef705
|
Hung Hoang
|
import {TestBed} from '@angular/core/testing';
|
2 |
|
|
|
3 |
|
|
import {UserService} from './user.service';
|
4 |
|
|
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
5 |
|
|
import {Languages, RequestStatus, UserType, VacationType} from '../enums/common.enum';
|
6 |
|
|
import {environment} from '../../environments/environment';
|
7 |
|
|
|
8 |
|
|
describe('UsersService', () => {
|
9 |
|
|
let service: UserService;
|
10 |
|
|
let httpMock: HttpTestingController;
|
11 |
|
|
const baseUrl: string = environment.apiUrl;
|
12 |
|
|
|
13 |
|
|
beforeEach(() => {
|
14 |
|
|
TestBed.configureTestingModule({
|
15 |
|
|
imports: [HttpClientTestingModule],
|
16 |
|
|
providers: [UserService]
|
17 |
|
|
});
|
18 |
|
|
|
19 |
|
|
service = TestBed.get(UserService);
|
20 |
|
|
httpMock = TestBed.get(HttpTestingController);
|
21 |
|
|
});
|
22 |
|
|
afterEach(() => httpMock.verify());
|
23 |
|
|
|
24 |
|
|
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 |
|
|
|
80 |
|
|
it('getLoggedUserCalendar', () => {
|
81 |
|
|
const dummyData = [
|
82 |
|
|
{id: 1, date: '2000/10/10', from: '09:00', to: '13:00', type: 'VACATION'},
|
83 |
|
|
{id: 2, date: '2000/10/11', type: 'SICKDAY'},
|
84 |
|
|
{id: 3, date: '2000/10/12', from: '09:00', to: '13:00', type: 'VACATION'},
|
85 |
|
|
{id: 4, date: '2000/10/13', type: 'SICKDAY'},
|
86 |
|
|
{id: 5, date: '2000/10/14', from: '09:00', to: '13:00', type: 'VACATION'}
|
87 |
|
|
];
|
88 |
|
|
|
89 |
|
|
service.getLoggedUserCalendar(new Date(1995, 10, 25))
|
90 |
|
|
.subscribe((data: any) => {
|
91 |
|
|
expect(data.length).toBe(5);
|
92 |
|
|
expect(data[1].type).toBe(VacationType.SICKDAY);
|
93 |
|
|
expect(data[2].type).toBe(VacationType.VACATION);
|
94 |
|
|
expect(data[2].from).toBeDefined();
|
95 |
|
|
expect(data[2].to).toBeDefined();
|
96 |
|
|
});
|
97 |
|
|
|
98 |
|
|
const req = httpMock.expectOne(baseUrl + '/api/user/me/calendar?from=1995/10/25');
|
99 |
|
|
expect(req.request.method).toBe('GET');
|
100 |
|
|
req.flush(dummyData);
|
101 |
|
|
});
|
102 |
|
|
|
103 |
|
|
it('getLoggedUserCalendarWithOptions', () => {
|
104 |
|
|
const dummyData = [
|
105 |
|
|
{id: 1, date: '2000/10/10', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'},
|
106 |
|
|
{id: 2, date: '2000/10/11', type: 'SICKDAY', status: 'ACCEPTED'},
|
107 |
|
|
{id: 3, date: '2000/10/12', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'},
|
108 |
|
|
{id: 4, date: '2000/10/13', type: 'SICKDAY', status: 'ACCEPTED'},
|
109 |
|
|
{id: 5, date: '2000/10/14', from: '09:00', to: '13:00', type: 'VACATION', status: 'ACCEPTED'}
|
110 |
|
|
];
|
111 |
|
|
|
112 |
|
|
service.getLoggedUserCalendarWithOptions(new Date(1995, 10, 25), null, null, RequestStatus.ACCEPTED)
|
113 |
|
|
.subscribe((data: any) => {
|
114 |
|
|
expect(data.length).toBe(5);
|
115 |
|
|
expect(data[0].status).toBeDefined();
|
116 |
|
|
expect(data[0].status).toBe(RequestStatus.ACCEPTED);
|
117 |
|
|
expect(data[1].status).toBe(RequestStatus.ACCEPTED);
|
118 |
|
|
expect(data[2].status).toBe(RequestStatus.ACCEPTED);
|
119 |
|
|
expect(data[3].status).toBe(RequestStatus.ACCEPTED);
|
120 |
|
|
expect(data[4].status).toBe(RequestStatus.ACCEPTED);
|
121 |
|
|
});
|
122 |
|
|
|
123 |
|
|
const req = httpMock.expectOne(baseUrl + '/api/user/me/calendar?from=1995/10/25&status=ACCEPTED');
|
124 |
|
|
expect(req.request.method).toBe('GET');
|
125 |
|
|
req.flush(dummyData);
|
126 |
|
|
});
|
127 |
|
|
});
|