]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/user.service.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / user.service.spec.ts
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 { UserFormModel } from '../../core/auth/user-form/user-form.model';
6 import { UserService } from './user.service';
7
8 describe('UserService', () => {
9 let service: UserService;
10 let httpTesting: HttpTestingController;
11
12 configureTestBed({
13 providers: [UserService],
14 imports: [HttpClientTestingModule]
15 });
16
17 beforeEach(() => {
18 service = TestBed.get(UserService);
19 httpTesting = TestBed.get(HttpTestingController);
20 });
21
22 afterEach(() => {
23 httpTesting.verify();
24 });
25
26 it('should be created', () => {
27 expect(service).toBeTruthy();
28 });
29
30 it('should call create', () => {
31 const user = new UserFormModel();
32 user.username = 'user0';
33 user.password = 'pass0';
34 user.name = 'User 0';
35 user.email = 'user0@email.com';
36 user.roles = ['administrator'];
37 service.create(user).subscribe();
38 const req = httpTesting.expectOne('api/user');
39 expect(req.request.method).toBe('POST');
40 expect(req.request.body).toEqual(user);
41 });
42
43 it('should call delete', () => {
44 service.delete('user0').subscribe();
45 const req = httpTesting.expectOne('api/user/user0');
46 expect(req.request.method).toBe('DELETE');
47 });
48
49 it('should call update', () => {
50 const user = new UserFormModel();
51 user.username = 'user0';
52 user.password = 'pass0';
53 user.name = 'User 0';
54 user.email = 'user0@email.com';
55 user.roles = ['administrator'];
56 service.update(user).subscribe();
57 const req = httpTesting.expectOne('api/user/user0');
58 expect(req.request.body).toEqual(user);
59 expect(req.request.method).toBe('PUT');
60 });
61
62 it('should call get', () => {
63 service.get('user0').subscribe();
64 const req = httpTesting.expectOne('api/user/user0');
65 expect(req.request.method).toBe('GET');
66 });
67
68 it('should call list', () => {
69 service.list().subscribe();
70 const req = httpTesting.expectOne('api/user');
71 expect(req.request.method).toBe('GET');
72 });
73 });