14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
- import { expect } from 'chai' ;
17
+ import { expect , use } from 'chai' ;
18
+ import * as sinon from 'sinon' ;
18
19
import { TaskEvent } from '../../src/implementation/taskenums' ;
19
20
import { Headers } from '../../src/implementation/connection' ;
20
21
import {
@@ -34,19 +35,22 @@ import {
34
35
import { Location } from '../../src/implementation/location' ;
35
36
import { newTestConnection , TestingConnection } from './connection' ;
36
37
import { injectTestConnection } from '../../src/platform/connection' ;
38
+ import { newTextConnection } from '../../src/platform/node/connection' ;
39
+ import sinonChai from 'sinon-chai' ;
37
40
38
41
const fakeAppGs = testShared . makeFakeApp ( 'gs://mybucket' ) ;
39
42
const fakeAppGsEndingSlash = testShared . makeFakeApp ( 'gs://mybucket/' ) ;
40
43
const fakeAppInvalidGs = testShared . makeFakeApp ( 'gs://mybucket/hello' ) ;
41
44
const testLocation = new Location ( 'bucket' , 'object' ) ;
45
+ use ( sinonChai ) ;
42
46
43
47
function makeGsUrl ( child : string = '' ) : string {
44
48
return 'gs://' + testShared . bucket + '/' + child ;
45
49
}
46
50
47
51
describe ( 'Firebase Storage > Service' , ( ) => {
48
- before ( ( ) => injectTestConnection ( newTestConnection ) ) ;
49
- after ( ( ) => injectTestConnection ( null ) ) ;
52
+ // before(() => injectTestConnection(newTestConnection));
53
+ // after(() => injectTestConnection(null));
50
54
51
55
describe ( 'simple constructor' , ( ) => {
52
56
const service = new FirebaseStorageImpl (
@@ -227,6 +231,13 @@ GOOG4-RSA-SHA256`
227
231
} ) ;
228
232
} ) ;
229
233
describe ( 'connectStorageEmulator(service, host, port, options)' , ( ) => {
234
+ let sandbox : sinon . SinonSandbox ;
235
+ beforeEach ( ( ) => {
236
+ sandbox = sinon . createSandbox ( ) ;
237
+ } ) ;
238
+ afterEach ( ( ) => {
239
+ sandbox . restore ( ) ;
240
+ } ) ;
230
241
it ( 'sets emulator host correctly' , done => {
231
242
function newSend ( connection : TestingConnection , url : string ) : void {
232
243
// Expect emulator host to be in url of storage operations requests,
@@ -270,6 +281,25 @@ GOOG4-RSA-SHA256`
270
281
expect ( service . _protocol ) . to . equal ( 'https' ) ;
271
282
void getDownloadURL ( ref ( service , 'test.png' ) ) ;
272
283
} ) ;
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
+ } ) ;
273
303
it ( 'sets mock user token string if specified' , done => {
274
304
const mockUserToken = 'my-mock-user-token' ;
275
305
function newSend (
0 commit comments