]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
2 | import { TestBed } from '@angular/core/testing'; | |
3 | ||
4 | import { configureTestBed } from '../../../testing/unit-test-helper'; | |
5 | import { RoleService } from './role.service'; | |
6 | ||
7 | describe('RoleService', () => { | |
8 | let service: RoleService; | |
9 | let httpTesting: HttpTestingController; | |
10 | ||
11 | configureTestBed({ | |
12 | providers: [RoleService], | |
13 | imports: [HttpClientTestingModule] | |
14 | }); | |
15 | ||
16 | beforeEach(() => { | |
17 | service = TestBed.get(RoleService); | |
18 | httpTesting = TestBed.get(HttpTestingController); | |
19 | }); | |
20 | ||
21 | afterEach(() => { | |
22 | httpTesting.verify(); | |
23 | }); | |
24 | ||
25 | it('should be created', () => { | |
26 | expect(service).toBeTruthy(); | |
27 | }); | |
28 | ||
29 | it('should call list', () => { | |
30 | service.list().subscribe(); | |
31 | const req = httpTesting.expectOne('api/role'); | |
32 | expect(req.request.method).toBe('GET'); | |
33 | }); | |
34 | ||
35 | it('should call delete', () => { | |
36 | service.delete('role1').subscribe(); | |
37 | const req = httpTesting.expectOne('api/role/role1'); | |
38 | expect(req.request.method).toBe('DELETE'); | |
39 | }); | |
40 | ||
41 | it('should call get', () => { | |
42 | service.get('role1').subscribe(); | |
43 | const req = httpTesting.expectOne('api/role/role1'); | |
44 | expect(req.request.method).toBe('GET'); | |
45 | }); | |
46 | ||
9f95a23c TL |
47 | it('should call clone', () => { |
48 | service.clone('foo', 'bar').subscribe(); | |
49 | const req = httpTesting.expectOne('api/role/foo/clone?new_name=bar'); | |
50 | expect(req.request.method).toBe('POST'); | |
51 | }); | |
52 | ||
11fdf7f2 TL |
53 | it('should check if role name exists', () => { |
54 | let exists: boolean; | |
55 | service.exists('role1').subscribe((res: boolean) => { | |
56 | exists = res; | |
57 | }); | |
58 | const req = httpTesting.expectOne('api/role'); | |
59 | expect(req.request.method).toBe('GET'); | |
60 | req.flush([{ name: 'role0' }, { name: 'role1' }]); | |
61 | expect(exists).toBeTruthy(); | |
62 | }); | |
63 | ||
64 | it('should check if role name does not exist', () => { | |
65 | let exists: boolean; | |
66 | service.exists('role2').subscribe((res: boolean) => { | |
67 | exists = res; | |
68 | }); | |
69 | const req = httpTesting.expectOne('api/role'); | |
70 | expect(req.request.method).toBe('GET'); | |
71 | req.flush([{ name: 'role0' }, { name: 'role1' }]); | |
72 | expect(exists).toBeFalsy(); | |
73 | }); | |
74 | }); |