1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { RoleService } from './role.service';
7 describe('RoleService', () => {
8 let service: RoleService;
9 let httpTesting: HttpTestingController;
12 providers: [RoleService],
13 imports: [HttpClientTestingModule]
17 service = TestBed.get(RoleService);
18 httpTesting = TestBed.get(HttpTestingController);
25 it('should be created', () => {
26 expect(service).toBeTruthy();
29 it('should call list', () => {
30 service.list().subscribe();
31 const req = httpTesting.expectOne('api/role');
32 expect(req.request.method).toBe('GET');
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');
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');
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');
53 it('should check if role name exists', () => {
55 service.exists('role1').subscribe((res: boolean) => {
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();
64 it('should check if role name does not exist', () => {
66 service.exists('role2').subscribe((res: boolean) => {
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();