]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user.service.spec.ts
85aef0d07def4123b32387d205523184bcd87f60
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rgw-user.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
3
4 import { of as observableOf } from 'rxjs';
5
6 import { configureTestBed } from '../../../testing/unit-test-helper';
7 import { RgwUserService } from './rgw-user.service';
8
9 describe('RgwUserService', () => {
10 let service: RgwUserService;
11 let httpTesting: HttpTestingController;
12
13 configureTestBed({
14 imports: [HttpClientTestingModule],
15 providers: [RgwUserService]
16 });
17
18 beforeEach(() => {
19 service = TestBed.get(RgwUserService);
20 httpTesting = TestBed.get(HttpTestingController);
21 });
22
23 afterEach(() => {
24 httpTesting.verify();
25 });
26
27 it('should be created', () => {
28 expect(service).toBeTruthy();
29 });
30
31 it('should call list with empty result', () => {
32 let result;
33 service.list().subscribe((resp) => {
34 result = resp;
35 });
36 const req = httpTesting.expectOne('api/rgw/user');
37 expect(req.request.method).toBe('GET');
38 req.flush([]);
39 expect(result).toEqual([]);
40 });
41
42 it('should call list with result', () => {
43 let result;
44 service.list().subscribe((resp) => {
45 result = resp;
46 });
47
48 let req = httpTesting.expectOne('api/rgw/user');
49 expect(req.request.method).toBe('GET');
50 req.flush(['foo', 'bar']);
51
52 req = httpTesting.expectOne('api/rgw/user/foo');
53 expect(req.request.method).toBe('GET');
54 req.flush({ name: 'foo' });
55
56 req = httpTesting.expectOne('api/rgw/user/bar');
57 expect(req.request.method).toBe('GET');
58 req.flush({ name: 'bar' });
59
60 expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
61 });
62
63 it('should call enumerate', () => {
64 service.enumerate().subscribe();
65 const req = httpTesting.expectOne('api/rgw/user');
66 expect(req.request.method).toBe('GET');
67 });
68
69 it('should call get', () => {
70 service.get('foo').subscribe();
71 const req = httpTesting.expectOne('api/rgw/user/foo');
72 expect(req.request.method).toBe('GET');
73 });
74
75 it('should call getQuota', () => {
76 service.getQuota('foo').subscribe();
77 const req = httpTesting.expectOne('api/rgw/user/foo/quota');
78 expect(req.request.method).toBe('GET');
79 });
80
81 it('should call update', () => {
82 service.update('foo', { xxx: 'yyy' }).subscribe();
83 const req = httpTesting.expectOne('api/rgw/user/foo?xxx=yyy');
84 expect(req.request.method).toBe('PUT');
85 });
86
87 it('should call updateQuota', () => {
88 service.updateQuota('foo', { xxx: 'yyy' }).subscribe();
89 const req = httpTesting.expectOne('api/rgw/user/foo/quota?xxx=yyy');
90 expect(req.request.method).toBe('PUT');
91 });
92
93 it('should call create', () => {
94 service.create({ foo: 'bar' }).subscribe();
95 const req = httpTesting.expectOne('api/rgw/user?foo=bar');
96 expect(req.request.method).toBe('POST');
97 });
98
99 it('should call delete', () => {
100 service.delete('foo').subscribe();
101 const req = httpTesting.expectOne('api/rgw/user/foo');
102 expect(req.request.method).toBe('DELETE');
103 });
104
105 it('should call createSubuser', () => {
106 service.createSubuser('foo', { xxx: 'yyy' }).subscribe();
107 const req = httpTesting.expectOne('api/rgw/user/foo/subuser?xxx=yyy');
108 expect(req.request.method).toBe('POST');
109 });
110
111 it('should call deleteSubuser', () => {
112 service.deleteSubuser('foo', 'bar').subscribe();
113 const req = httpTesting.expectOne('api/rgw/user/foo/subuser/bar');
114 expect(req.request.method).toBe('DELETE');
115 });
116
117 it('should call addCapability', () => {
118 service.addCapability('foo', 'bar', 'baz').subscribe();
119 const req = httpTesting.expectOne('api/rgw/user/foo/capability?type=bar&perm=baz');
120 expect(req.request.method).toBe('POST');
121 });
122
123 it('should call deleteCapability', () => {
124 service.deleteCapability('foo', 'bar', 'baz').subscribe();
125 const req = httpTesting.expectOne('api/rgw/user/foo/capability?type=bar&perm=baz');
126 expect(req.request.method).toBe('DELETE');
127 });
128
129 it('should call addS3Key', () => {
130 service.addS3Key('foo', { xxx: 'yyy' }).subscribe();
131 const req = httpTesting.expectOne('api/rgw/user/foo/key?key_type=s3&xxx=yyy');
132 expect(req.request.method).toBe('POST');
133 });
134
135 it('should call deleteS3Key', () => {
136 service.deleteS3Key('foo', 'bar').subscribe();
137 const req = httpTesting.expectOne('api/rgw/user/foo/key?key_type=s3&access_key=bar');
138 expect(req.request.method).toBe('DELETE');
139 });
140
141 it('should call exists with an existent uid', () => {
142 spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
143 let result;
144 service.exists('foo').subscribe((res) => {
145 result = res;
146 });
147 expect(result).toBe(true);
148 });
149
150 it('should call exists with a non existent uid', () => {
151 spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
152 let result;
153 service.exists('baz').subscribe((res) => {
154 result = res;
155 });
156 expect(result).toBe(false);
157 });
158 });