1414 * See the License for the specific language governing permissions and
1515 * limitations under the License.
1616 */
17- import { expect } from 'chai' ;
17+ import { expect , use } from 'chai' ;
18+ import * as sinon from 'sinon' ;
1819import { TaskEvent } from '../../src/implementation/taskenums' ;
1920import { Headers } from '../../src/implementation/connection' ;
2021import {
@@ -34,19 +35,22 @@ import {
3435import { Location } from '../../src/implementation/location' ;
3536import { newTestConnection , TestingConnection } from './connection' ;
3637import { injectTestConnection } from '../../src/platform/connection' ;
38+ import { newTextConnection } from '../../src/platform/node/connection' ;
39+ import sinonChai from 'sinon-chai' ;
3740
3841const fakeAppGs = testShared . makeFakeApp ( 'gs://mybucket' ) ;
3942const fakeAppGsEndingSlash = testShared . makeFakeApp ( 'gs://mybucket/' ) ;
4043const fakeAppInvalidGs = testShared . makeFakeApp ( 'gs://mybucket/hello' ) ;
4144const testLocation = new Location ( 'bucket' , 'object' ) ;
45+ use ( sinonChai ) ;
4246
4347function makeGsUrl ( child : string = '' ) : string {
4448 return 'gs://' + testShared . bucket + '/' + child ;
4549}
4650
4751describe ( 'Firebase Storage > Service' , ( ) => {
48- before ( ( ) => injectTestConnection ( newTestConnection ) ) ;
49- after ( ( ) => injectTestConnection ( null ) ) ;
52+ // before(() => injectTestConnection(newTestConnection));
53+ // after(() => injectTestConnection(null));
5054
5155 describe ( 'simple constructor' , ( ) => {
5256 const service = new FirebaseStorageImpl (
@@ -227,6 +231,13 @@ GOOG4-RSA-SHA256`
227231 } ) ;
228232 } ) ;
229233 describe ( 'connectStorageEmulator(service, host, port, options)' , ( ) => {
234+ let sandbox : sinon . SinonSandbox ;
235+ beforeEach ( ( ) => {
236+ sandbox = sinon . createSandbox ( ) ;
237+ } ) ;
238+ afterEach ( ( ) => {
239+ sandbox . restore ( ) ;
240+ } ) ;
230241 it ( 'sets emulator host correctly' , done => {
231242 function newSend ( connection : TestingConnection , url : string ) : void {
232243 // Expect emulator host to be in url of storage operations requests,
@@ -270,6 +281,25 @@ GOOG4-RSA-SHA256`
270281 expect ( service . _protocol ) . to . equal ( 'https' ) ;
271282 void getDownloadURL ( ref ( service , 'test.png' ) ) ;
272283 } ) ;
284+ it ( 'sets the credentials' , ( ) => {
285+ const stub = sandbox . stub ( globalThis , 'fetch' ) . resolves ( ) ;
286+ const textConnection = newTextConnection ( ) ;
287+ textConnection . send (
288+ 'http://something.cloudworkstations.dev' ,
289+ 'POST' ,
290+ undefined ,
291+ undefined ,
292+ true
293+ ) ;
294+ expect ( stub ) . to . have . been . called ;
295+ expect ( stub ) . to . have . been . calledWithMatch (
296+ 'http://something.cloudworkstations.dev' ,
297+ {
298+ credentials : 'include'
299+ }
300+ ) ;
301+ stub . restore ( ) ;
302+ } ) ;
273303 it ( 'sets mock user token string if specified' , done => {
274304 const mockUserToken = 'my-mock-user-token' ;
275305 function newSend (
0 commit comments