1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { of as observableOf } from 'rxjs';
6 import { configureTestBed } from '../../../testing/unit-test-helper';
7 import { RgwUserService } from './rgw-user.service';
9 describe('RgwUserService', () => {
10 let service: RgwUserService;
11 let httpTesting: HttpTestingController;
14 imports: [HttpClientTestingModule],
15 providers: [RgwUserService]
19 service = TestBed.get(RgwUserService);
20 httpTesting = TestBed.get(HttpTestingController);
27 it('should be created', () => {
28 expect(service).toBeTruthy();
31 it('should call list with empty result', () => {
33 service.list().subscribe((resp) => {
36 const req = httpTesting.expectOne('api/rgw/user');
37 expect(req.request.method).toBe('GET');
39 expect(result).toEqual([]);
42 it('should call list with result', () => {
44 service.list().subscribe((resp) => {
48 let req = httpTesting.expectOne('api/rgw/user');
49 expect(req.request.method).toBe('GET');
50 req.flush(['foo', 'bar']);
52 req = httpTesting.expectOne('api/rgw/user/foo');
53 expect(req.request.method).toBe('GET');
54 req.flush({ name: 'foo' });
56 req = httpTesting.expectOne('api/rgw/user/bar');
57 expect(req.request.method).toBe('GET');
58 req.flush({ name: 'bar' });
60 expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
63 it('should call enumerate', () => {
64 service.enumerate().subscribe();
65 const req = httpTesting.expectOne('api/rgw/user');
66 expect(req.request.method).toBe('GET');
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');
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');
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');
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');
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');
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');
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');
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');
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');
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');
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');
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');
141 it('should call exists with an existent uid', () => {
142 spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
144 service.exists('foo').subscribe((res) => {
147 expect(result).toBe(true);
150 it('should call exists with a non existent uid', () => {
151 spyOn(service, 'enumerate').and.returnValue(observableOf(['foo', 'bar']));
153 service.exists('baz').subscribe((res) => {
156 expect(result).toBe(false);