@@ -304,4 +304,76 @@ describe('SecurityRulesApiClient', () => {
304304 . should . eventually . be . rejected . and . deep . equal ( expected ) ;
305305 } ) ;
306306 } ) ;
307+
308+ describe ( 'deleteRuleset' , ( ) => {
309+ const INVALID_NAMES : any [ ] = [ null , undefined , '' , 1 , true , { } , [ ] ] ;
310+ INVALID_NAMES . forEach ( ( invalidName ) => {
311+ it ( `should reject when called with: ${ JSON . stringify ( invalidName ) } ` , ( ) => {
312+ return apiClient . deleteRuleset ( invalidName )
313+ . should . eventually . be . rejected . and . have . property (
314+ 'message' , 'Ruleset name must be a non-empty string.' ) ;
315+ } ) ;
316+ } ) ;
317+
318+ it ( `should reject when called with prefixed name` , ( ) => {
319+ return apiClient . deleteRuleset ( 'projects/foo/rulesets/bar' )
320+ . should . eventually . be . rejected . and . have . property (
321+ 'message' , 'Ruleset name must not contain any "/" characters.' ) ;
322+ } ) ;
323+
324+ it ( 'should resolve on success' , ( ) => {
325+ const stub = sinon
326+ . stub ( HttpClient . prototype , 'send' )
327+ . resolves ( utils . responseFrom ( { } ) ) ;
328+ stubs . push ( stub ) ;
329+ return apiClient . deleteRuleset ( RULESET_NAME )
330+ . then ( ( ) => {
331+ expect ( stub ) . to . have . been . calledOnce . and . calledWith ( {
332+ method : 'DELETE' ,
333+ url : 'https://firebaserules.googleapis.com/v1/projects/test-project/rulesets/ruleset-id' ,
334+ } ) ;
335+ } ) ;
336+ } ) ;
337+
338+ it ( 'should throw when a full platform error response is received' , ( ) => {
339+ const stub = sinon
340+ . stub ( HttpClient . prototype , 'send' )
341+ . rejects ( utils . errorFrom ( ERROR_RESPONSE , 404 ) ) ;
342+ stubs . push ( stub ) ;
343+ const expected = new FirebaseSecurityRulesError ( 'not-found' , 'Requested entity not found' ) ;
344+ return apiClient . deleteRuleset ( RULESET_NAME )
345+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
346+ } ) ;
347+
348+ it ( 'should throw unknown-error when error code is not present' , ( ) => {
349+ const stub = sinon
350+ . stub ( HttpClient . prototype , 'send' )
351+ . rejects ( utils . errorFrom ( { } , 404 ) ) ;
352+ stubs . push ( stub ) ;
353+ const expected = new FirebaseSecurityRulesError ( 'unknown-error' , 'Unknown server error: {}' ) ;
354+ return apiClient . deleteRuleset ( RULESET_NAME )
355+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
356+ } ) ;
357+
358+ it ( 'should throw unknown-error for non-json response' , ( ) => {
359+ const stub = sinon
360+ . stub ( HttpClient . prototype , 'send' )
361+ . rejects ( utils . errorFrom ( 'not json' , 404 ) ) ;
362+ stubs . push ( stub ) ;
363+ const expected = new FirebaseSecurityRulesError (
364+ 'unknown-error' , 'Unexpected response with status: 404 and body: not json' ) ;
365+ return apiClient . deleteRuleset ( RULESET_NAME )
366+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
367+ } ) ;
368+
369+ it ( 'should throw when rejected with a FirebaseAppError' , ( ) => {
370+ const expected = new FirebaseAppError ( 'network-error' , 'socket hang up' ) ;
371+ const stub = sinon
372+ . stub ( HttpClient . prototype , 'send' )
373+ . rejects ( expected ) ;
374+ stubs . push ( stub ) ;
375+ return apiClient . deleteRuleset ( RULESET_NAME )
376+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
377+ } ) ;
378+ } ) ;
307379} ) ;
0 commit comments