]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/user.service.spec.ts
update source to Ceph Pacific 16.2.2
[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 { UserFormModel } from '~/app/core/auth/user-form/user-form.model';
5 import { configureTestBed } from '~/testing/unit-test-helper';
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.inject(UserService);
19 httpTesting = TestBed.inject(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
74 it('should call changePassword', () => {
75 service.changePassword('user0', 'foo', 'bar').subscribe();
76 const req = httpTesting.expectOne('api/user/user0/change_password');
77 expect(req.request.body).toEqual({
78 old_password: 'foo',
79 new_password: 'bar'
80 });
81 expect(req.request.method).toBe('POST');
82 });
83
84 it('should call validatePassword', () => {
85 service.validatePassword('foo').subscribe();
86 const req = httpTesting.expectOne('api/user/validate_password');
87 expect(req.request.method).toBe('POST');
88 expect(req.request.body).toEqual({ password: 'foo', old_password: null, username: null });
89 });
90
91 it('should call validatePassword (incl. name)', () => {
92 service.validatePassword('foo_bar', 'bar').subscribe();
93 const req = httpTesting.expectOne('api/user/validate_password');
94 expect(req.request.method).toBe('POST');
95 expect(req.request.body).toEqual({ password: 'foo_bar', username: 'bar', old_password: null });
96 });
97
98 it('should call validatePassword (incl. old password)', () => {
99 service.validatePassword('foo', null, 'foo').subscribe();
100 const req = httpTesting.expectOne('api/user/validate_password');
101 expect(req.request.method).toBe('POST');
102 expect(req.request.body).toEqual({ password: 'foo', old_password: 'foo', username: null });
103 });
104 });