@@ -27,7 +27,7 @@ import * as utils from '../utils';
2727import * as mocks from '../../resources/mocks' ;
2828
2929import { FirebaseApp } from '../../../src/firebase-app' ;
30- import { HttpRequestHandler } from '../../../src/utils/api-request' ;
30+ import { HttpClient } from '../../../src/utils/api-request' ;
3131import { FirebaseInstanceIdRequestHandler } from '../../../src/instance-id/instance-id-request' ;
3232
3333chai . should ( ) ;
@@ -56,6 +56,7 @@ describe('FirebaseInstanceIdRequestHandler', () => {
5656 expectedHeaders = {
5757 Authorization : 'Bearer ' + mockAccessToken ,
5858 } ;
59+ return mockApp . INTERNAL . getToken ( ) ;
5960 } ) ;
6061
6162 afterEach ( ( ) => {
@@ -75,31 +76,31 @@ describe('FirebaseInstanceIdRequestHandler', () => {
7576 describe ( 'deleteInstanceId' , ( ) => {
7677 const httpMethod = 'DELETE' ;
7778 const host = 'console.firebase.google.com' ;
78- const port = 443 ;
7979 const path = `/v1/project/${ projectId } /instanceId/test-iid` ;
8080 const timeout = 10000 ;
8181
8282 it ( 'should be fulfilled given a valid instance ID' , ( ) => {
8383 const expectedResult = { } ;
84-
85- const stub = sinon . stub ( HttpRequestHandler . prototype , 'sendRequest' )
86- . returns ( Promise . resolve ( expectedResult ) ) ;
84+ const stub = sinon . stub ( HttpClient . prototype , 'send' )
85+ . resolves ( utils . responseFrom ( expectedResult ) ) ;
8786 stubs . push ( stub ) ;
8887
8988 const requestHandler = new FirebaseInstanceIdRequestHandler ( mockApp , projectId ) ;
9089 return requestHandler . deleteInstanceId ( 'test-iid' )
9190 . then ( ( result ) => {
9291 expect ( result ) . to . deep . equal ( expectedResult ) ;
93- expect ( stub ) . to . have . been . calledOnce . and . calledWith (
94- host , port , path , httpMethod , undefined , expectedHeaders , timeout ) ;
92+ expect ( stub ) . to . have . been . calledOnce . and . calledWith ( {
93+ method : httpMethod ,
94+ url : `https://${ host } ${ path } ` ,
95+ headers : expectedHeaders ,
96+ timeout,
97+ } ) ;
9598 } ) ;
9699 } ) ;
97100
98101 it ( 'should throw for HTTP 404 errors' , ( ) => {
99- const expectedResult = { statusCode : 404 } ;
100-
101- const stub = sinon . stub ( HttpRequestHandler . prototype , 'sendRequest' )
102- . rejects ( expectedResult ) ;
102+ const stub = sinon . stub ( HttpClient . prototype , 'send' )
103+ . rejects ( utils . errorFrom ( { } , 404 ) ) ;
103104 stubs . push ( stub ) ;
104105
105106 const requestHandler = new FirebaseInstanceIdRequestHandler ( mockApp , projectId ) ;
@@ -114,10 +115,8 @@ describe('FirebaseInstanceIdRequestHandler', () => {
114115 } ) ;
115116
116117 it ( 'should throw for HTTP 409 errors' , ( ) => {
117- const expectedResult = { statusCode : 409 } ;
118-
119- const stub = sinon . stub ( HttpRequestHandler . prototype , 'sendRequest' )
120- . rejects ( expectedResult ) ;
118+ const stub = sinon . stub ( HttpClient . prototype , 'send' )
119+ . rejects ( utils . errorFrom ( { } , 409 ) ) ;
121120 stubs . push ( stub ) ;
122121
123122 const requestHandler = new FirebaseInstanceIdRequestHandler ( mockApp , projectId ) ;
@@ -132,10 +131,9 @@ describe('FirebaseInstanceIdRequestHandler', () => {
132131 } ) ;
133132
134133 it ( 'should throw for unexpected HTTP errors' , ( ) => {
135- const expectedResult = { statusCode : 511 } ;
136-
137- const stub = sinon . stub ( HttpRequestHandler . prototype , 'sendRequest' )
138- . rejects ( expectedResult ) ;
134+ const expectedResult = { error : 'test error' } ;
135+ const stub = sinon . stub ( HttpClient . prototype , 'send' )
136+ . rejects ( utils . errorFrom ( expectedResult , 511 ) ) ;
139137 stubs . push ( stub ) ;
140138
141139 const requestHandler = new FirebaseInstanceIdRequestHandler ( mockApp , projectId ) ;
@@ -145,7 +143,7 @@ describe('FirebaseInstanceIdRequestHandler', () => {
145143 } )
146144 . catch ( ( error ) => {
147145 expect ( error . code ) . to . equal ( 'instance-id/api-error' ) ;
148- expect ( error . message ) . to . equal ( JSON . stringify ( expectedResult ) ) ;
146+ expect ( error . message ) . to . equal ( 'test error' ) ;
149147 } ) ;
150148 } ) ;
151149 } ) ;
0 commit comments