@@ -21,6 +21,8 @@ import { RgwBucketFormComponent } from './rgw-bucket-form.component';
2121import { RgwRateLimitComponent } from '../rgw-rate-limit/rgw-rate-limit.component' ;
2222import { CheckboxModule , SelectModule } from 'carbon-components-angular' ;
2323import { NO_ERRORS_SCHEMA } from '@angular/core' ;
24+ import { By } from '@angular/platform-browser' ;
25+ import { LoadingStatus } from '~/app/shared/forms/cd-form' ;
2426
2527describe ( 'RgwBucketFormComponent' , ( ) => {
2628 let component : RgwBucketFormComponent ;
@@ -30,6 +32,7 @@ describe('RgwBucketFormComponent', () => {
3032 let rgwBucketServiceGetSpy : jasmine . Spy ;
3133 let enumerateSpy : jasmine . Spy ;
3234 let formHelper : FormHelper ;
35+ let childComponent : RgwRateLimitComponent ;
3336
3437 configureTestBed ( {
3538 declarations : [ RgwBucketFormComponent , RgwRateLimitComponent ] ,
@@ -338,4 +341,90 @@ describe('RgwBucketFormComponent', () => {
338341 component . deleteTag ( 0 ) ;
339342 expect ( updateValidationSpy ) . toHaveBeenCalled ( ) ;
340343 } ) ;
344+
345+ describe ( 'should call bucket ratelimit API with correct bucket name' , ( ) => {
346+ beforeEach ( ( ) => {
347+ component . loading = LoadingStatus . Ready ;
348+ fixture . detectChanges ( ) ;
349+ childComponent = fixture . debugElement . query ( By . directive ( RgwRateLimitComponent ) )
350+ . componentInstance ;
351+ } ) ;
352+ it ( 'Scenario 1: tenanted owner with tenanted bucket name' , ( ) => {
353+ const rateLimitSpy = spyOn ( rgwBucketService , 'updateBucketRateLimit' ) . and . returnValue (
354+ observableOf ( [ ] )
355+ ) ;
356+ component . editing = true ;
357+ formHelper . setMultipleValues ( {
358+ bid : 'tenant/bucket1' ,
359+ owner : 'tenant$user1'
360+ } ) ;
361+ childComponent . form . patchValue ( {
362+ rate_limit_enabled : true ,
363+ rate_limit_max_readOps : 100 ,
364+ rate_limit_max_writeOps : 200 ,
365+ rate_limit_max_readBytes : '10MB' ,
366+ rate_limit_max_writeBytes : '20MB' ,
367+ rate_limit_max_readOps_unlimited : true , // Unlimited
368+ rate_limit_max_writeOps_unlimited : true , // Unlimited
369+ rate_limit_max_readBytes_unlimited : true , // Unlimited
370+ rate_limit_max_writeBytes_unlimited : true // Unlimited
371+ } ) ;
372+ childComponent . form . get ( 'rate_limit_enabled' ) . markAsDirty ( ) ;
373+ const rateLimitConfig = childComponent . getRateLimitFormValue ( ) ;
374+ component . updateBucketRateLimit ( ) ;
375+ expect ( rateLimitSpy ) . toHaveBeenCalledWith ( 'tenant/bucket1' , rateLimitConfig ) ;
376+ } ) ;
377+
378+ it ( 'Scenario 2: non tenanted owner with tenanted bucket name' , ( ) => {
379+ const rateLimitSpy = spyOn ( rgwBucketService , 'updateBucketRateLimit' ) . and . returnValue (
380+ observableOf ( [ ] )
381+ ) ;
382+ component . editing = true ;
383+ formHelper . setMultipleValues ( {
384+ bid : 'tenant/bucket1' ,
385+ owner : 'non_tenanted_user'
386+ } ) ;
387+ childComponent . form . patchValue ( {
388+ rate_limit_enabled : true ,
389+ rate_limit_max_readOps : 100 ,
390+ rate_limit_max_writeOps : 200 ,
391+ rate_limit_max_readBytes : '10MB' ,
392+ rate_limit_max_writeBytes : '20MB' ,
393+ rate_limit_max_readOps_unlimited : true , // Unlimited
394+ rate_limit_max_writeOps_unlimited : true , // Unlimited
395+ rate_limit_max_readBytes_unlimited : true , // Unlimited
396+ rate_limit_max_writeBytes_unlimited : true // Unlimited
397+ } ) ;
398+ childComponent . form . get ( 'rate_limit_enabled' ) . markAsDirty ( ) ;
399+ const rateLimitConfig = childComponent . getRateLimitFormValue ( ) ;
400+ component . updateBucketRateLimit ( ) ;
401+ expect ( rateLimitSpy ) . toHaveBeenCalledWith ( 'bucket1' , rateLimitConfig ) ;
402+ } ) ;
403+
404+ it ( 'Scenario 3: tenanted owner and with non-tenanted bucket name' , ( ) => {
405+ const rateLimitSpy = spyOn ( rgwBucketService , 'updateBucketRateLimit' ) . and . returnValue (
406+ observableOf ( [ ] )
407+ ) ;
408+ component . editing = true ;
409+ formHelper . setMultipleValues ( {
410+ bid : 'bucket1' ,
411+ owner : 'tenant$user1'
412+ } ) ;
413+ childComponent . form . patchValue ( {
414+ rate_limit_enabled : true ,
415+ rate_limit_max_readOps : 100 ,
416+ rate_limit_max_writeOps : 200 ,
417+ rate_limit_max_readBytes : '10MB' ,
418+ rate_limit_max_writeBytes : '20MB' ,
419+ rate_limit_max_readOps_unlimited : true , // Unlimited
420+ rate_limit_max_writeOps_unlimited : true , // Unlimited
421+ rate_limit_max_readBytes_unlimited : true , // Unlimited
422+ rate_limit_max_writeBytes_unlimited : true // Unlimited
423+ } ) ;
424+ childComponent . form . get ( 'rate_limit_enabled' ) . markAsDirty ( ) ;
425+ const rateLimitConfig = childComponent . getRateLimitFormValue ( ) ;
426+ component . updateBucketRateLimit ( ) ;
427+ expect ( rateLimitSpy ) . toHaveBeenCalledWith ( 'tenant/bucket1' , rateLimitConfig ) ;
428+ } ) ;
429+ } ) ;
341430} ) ;
0 commit comments