]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
2 | import { TestBed } from '@angular/core/testing'; | |
3 | ||
cd265ab1 | 4 | import { of as observableOf, throwError } from 'rxjs'; |
11fdf7f2 | 5 | |
f67539c2 | 6 | import { configureTestBed, RgwHelper } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
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(() => { | |
f67539c2 TL |
19 | service = TestBed.inject(RgwUserService); |
20 | httpTesting = TestBed.inject(HttpTestingController); | |
21 | RgwHelper.selectDaemon(); | |
11fdf7f2 TL |
22 | }); |
23 | ||
24 | afterEach(() => { | |
25 | httpTesting.verify(); | |
26 | }); | |
27 | ||
28 | it('should be created', () => { | |
29 | expect(service).toBeTruthy(); | |
30 | }); | |
31 | ||
32 | it('should call list with empty result', () => { | |
33 | let result; | |
34 | service.list().subscribe((resp) => { | |
35 | result = resp; | |
36 | }); | |
f67539c2 | 37 | const req = httpTesting.expectOne(`api/rgw/user?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
38 | expect(req.request.method).toBe('GET'); |
39 | req.flush([]); | |
40 | expect(result).toEqual([]); | |
41 | }); | |
42 | ||
43 | it('should call list with result', () => { | |
44 | let result; | |
45 | service.list().subscribe((resp) => { | |
46 | result = resp; | |
47 | }); | |
f67539c2 | 48 | let req = httpTesting.expectOne(`api/rgw/user?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
49 | expect(req.request.method).toBe('GET'); |
50 | req.flush(['foo', 'bar']); | |
51 | ||
f67539c2 | 52 | req = httpTesting.expectOne(`api/rgw/user/foo?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
53 | expect(req.request.method).toBe('GET'); |
54 | req.flush({ name: 'foo' }); | |
55 | ||
f67539c2 | 56 | req = httpTesting.expectOne(`api/rgw/user/bar?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
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(); | |
f67539c2 | 65 | const req = httpTesting.expectOne(`api/rgw/user?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
66 | expect(req.request.method).toBe('GET'); |
67 | }); | |
68 | ||
69 | it('should call get', () => { | |
70 | service.get('foo').subscribe(); | |
f67539c2 | 71 | const req = httpTesting.expectOne(`api/rgw/user/foo?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
72 | expect(req.request.method).toBe('GET'); |
73 | }); | |
74 | ||
75 | it('should call getQuota', () => { | |
76 | service.getQuota('foo').subscribe(); | |
f67539c2 | 77 | const req = httpTesting.expectOne(`api/rgw/user/foo/quota?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
78 | expect(req.request.method).toBe('GET'); |
79 | }); | |
80 | ||
81 | it('should call update', () => { | |
82 | service.update('foo', { xxx: 'yyy' }).subscribe(); | |
f67539c2 | 83 | const req = httpTesting.expectOne(`api/rgw/user/foo?${RgwHelper.DAEMON_QUERY_PARAM}&xxx=yyy`); |
11fdf7f2 TL |
84 | expect(req.request.method).toBe('PUT'); |
85 | }); | |
86 | ||
87 | it('should call updateQuota', () => { | |
88 | service.updateQuota('foo', { xxx: 'yyy' }).subscribe(); | |
f67539c2 TL |
89 | const req = httpTesting.expectOne( |
90 | `api/rgw/user/foo/quota?${RgwHelper.DAEMON_QUERY_PARAM}&xxx=yyy` | |
91 | ); | |
11fdf7f2 TL |
92 | expect(req.request.method).toBe('PUT'); |
93 | }); | |
94 | ||
95 | it('should call create', () => { | |
96 | service.create({ foo: 'bar' }).subscribe(); | |
f67539c2 | 97 | const req = httpTesting.expectOne(`api/rgw/user?${RgwHelper.DAEMON_QUERY_PARAM}&foo=bar`); |
11fdf7f2 TL |
98 | expect(req.request.method).toBe('POST'); |
99 | }); | |
100 | ||
101 | it('should call delete', () => { | |
102 | service.delete('foo').subscribe(); | |
f67539c2 | 103 | const req = httpTesting.expectOne(`api/rgw/user/foo?${RgwHelper.DAEMON_QUERY_PARAM}`); |
11fdf7f2 TL |
104 | expect(req.request.method).toBe('DELETE'); |
105 | }); | |
106 | ||
107 | it('should call createSubuser', () => { | |
108 | service.createSubuser('foo', { xxx: 'yyy' }).subscribe(); | |
f67539c2 TL |
109 | const req = httpTesting.expectOne( |
110 | `api/rgw/user/foo/subuser?${RgwHelper.DAEMON_QUERY_PARAM}&xxx=yyy` | |
111 | ); | |
11fdf7f2 TL |
112 | expect(req.request.method).toBe('POST'); |
113 | }); | |
114 | ||
115 | it('should call deleteSubuser', () => { | |
116 | service.deleteSubuser('foo', 'bar').subscribe(); | |
f67539c2 TL |
117 | const req = httpTesting.expectOne( |
118 | `api/rgw/user/foo/subuser/bar?${RgwHelper.DAEMON_QUERY_PARAM}` | |
119 | ); | |
11fdf7f2 TL |
120 | expect(req.request.method).toBe('DELETE'); |
121 | }); | |
122 | ||
123 | it('should call addCapability', () => { | |
124 | service.addCapability('foo', 'bar', 'baz').subscribe(); | |
f67539c2 TL |
125 | const req = httpTesting.expectOne( |
126 | `api/rgw/user/foo/capability?${RgwHelper.DAEMON_QUERY_PARAM}&type=bar&perm=baz` | |
127 | ); | |
11fdf7f2 TL |
128 | expect(req.request.method).toBe('POST'); |
129 | }); | |
130 | ||
131 | it('should call deleteCapability', () => { | |
132 | service.deleteCapability('foo', 'bar', 'baz').subscribe(); | |
f67539c2 TL |
133 | const req = httpTesting.expectOne( |
134 | `api/rgw/user/foo/capability?${RgwHelper.DAEMON_QUERY_PARAM}&type=bar&perm=baz` | |
135 | ); | |
11fdf7f2 TL |
136 | expect(req.request.method).toBe('DELETE'); |
137 | }); | |
138 | ||
139 | it('should call addS3Key', () => { | |
140 | service.addS3Key('foo', { xxx: 'yyy' }).subscribe(); | |
f67539c2 TL |
141 | const req = httpTesting.expectOne( |
142 | `api/rgw/user/foo/key?${RgwHelper.DAEMON_QUERY_PARAM}&key_type=s3&xxx=yyy` | |
143 | ); | |
11fdf7f2 TL |
144 | expect(req.request.method).toBe('POST'); |
145 | }); | |
146 | ||
147 | it('should call deleteS3Key', () => { | |
148 | service.deleteS3Key('foo', 'bar').subscribe(); | |
f67539c2 TL |
149 | const req = httpTesting.expectOne( |
150 | `api/rgw/user/foo/key?${RgwHelper.DAEMON_QUERY_PARAM}&key_type=s3&access_key=bar` | |
151 | ); | |
11fdf7f2 TL |
152 | expect(req.request.method).toBe('DELETE'); |
153 | }); | |
154 | ||
cd265ab1 TL |
155 | it('should call exists with an existent uid', (done) => { |
156 | spyOn(service, 'get').and.returnValue(observableOf({})); | |
11fdf7f2 | 157 | service.exists('foo').subscribe((res) => { |
cd265ab1 TL |
158 | expect(res).toBe(true); |
159 | done(); | |
11fdf7f2 | 160 | }); |
11fdf7f2 TL |
161 | }); |
162 | ||
cd265ab1 TL |
163 | it('should call exists with a non existent uid', (done) => { |
164 | spyOn(service, 'get').and.returnValue(throwError('bar')); | |
11fdf7f2 | 165 | service.exists('baz').subscribe((res) => { |
cd265ab1 TL |
166 | expect(res).toBe(false); |
167 | done(); | |
11fdf7f2 | 168 | }); |
11fdf7f2 TL |
169 | }); |
170 | }); |