1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
4 import { configureTestBed } from '../../../testing/unit-test-helper';
5 import { RgwBucketService } from './rgw-bucket.service';
7 describe('RgwBucketService', () => {
8 let service: RgwBucketService;
9 let httpTesting: HttpTestingController;
12 providers: [RgwBucketService],
13 imports: [HttpClientTestingModule]
17 service = TestBed.get(RgwBucketService);
18 httpTesting = TestBed.get(HttpTestingController);
25 it('should be created', () => {
26 expect(service).toBeTruthy();
29 it('should call list, with enumerate returning empty', () => {
31 service.list().subscribe((resp) => {
34 const req = httpTesting.expectOne('api/rgw/bucket');
36 expect(req.request.method).toBe('GET');
37 expect(result).toEqual([]);
40 it('should call list, with enumerate returning 2 elements', () => {
42 service.list().subscribe((resp) => {
45 let req = httpTesting.expectOne('api/rgw/bucket');
46 req.flush(['foo', 'bar']);
48 req = httpTesting.expectOne('api/rgw/bucket/foo');
49 req.flush({ name: 'foo' });
51 req = httpTesting.expectOne('api/rgw/bucket/bar');
52 req.flush({ name: 'bar' });
54 expect(req.request.method).toBe('GET');
55 expect(result).toEqual([{ name: 'foo' }, { name: 'bar' }]);
58 it('should call get', () => {
59 service.get('foo').subscribe();
60 const req = httpTesting.expectOne('api/rgw/bucket/foo');
61 expect(req.request.method).toBe('GET');
64 it('should call create', () => {
65 service.create('foo', 'bar').subscribe();
66 const req = httpTesting.expectOne('api/rgw/bucket?bucket=foo&uid=bar');
67 expect(req.request.method).toBe('POST');
70 it('should call update', () => {
71 service.update('foo', 'bar', 'baz').subscribe();
72 const req = httpTesting.expectOne('api/rgw/bucket/foo?bucket_id=bar&uid=baz');
73 expect(req.request.method).toBe('PUT');
76 it('should call delete, with purgeObjects = true', () => {
77 service.delete('foo').subscribe();
78 const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=true');
79 expect(req.request.method).toBe('DELETE');
82 it('should call delete, with purgeObjects = false', () => {
83 service.delete('foo', false).subscribe();
84 const req = httpTesting.expectOne('api/rgw/bucket/foo?purge_objects=false');
85 expect(req.request.method).toBe('DELETE');
88 it('should call exists', () => {
90 service.exists('foo').subscribe((resp) => {
93 const req = httpTesting.expectOne('api/rgw/bucket');
94 expect(req.request.method).toBe('GET');
95 req.flush(['foo', 'bar']);
96 expect(result).toBe(true);