Skip to content

Commit 862fb91

Browse files
committed
Added test for storage
1 parent 2722d47 commit 862fb91

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

packages/storage/src/platform/node/connection.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,22 @@ export class FetchStreamConnection extends FetchConnection<
157157
url: string,
158158
method: string,
159159
body?: NodeJS.ArrayBufferView | Blob | string,
160-
headers?: Record<string, string>
160+
headers?: Record<string, string>,
161+
isUsingEmulator?: boolean
161162
): Promise<void> {
162163
if (this.sent_) {
163164
throw internalError('cannot .send() more than once');
164165
}
165166
this.sent_ = true;
166167

167168
try {
168-
const response = await newFetch(url, method, headers, body);
169+
const response = await newFetch(
170+
url,
171+
method,
172+
headers,
173+
body,
174+
isUsingEmulator
175+
);
169176
this.headers_ = response.headers;
170177
this.statusCode_ = response.status;
171178
this.errorCode_ = ErrorCode.NO_ERROR;

packages/storage/test/unit/service.test.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
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';
1819
import { TaskEvent } from '../../src/implementation/taskenums';
1920
import { Headers } from '../../src/implementation/connection';
2021
import {
@@ -34,19 +35,22 @@ import {
3435
import { Location } from '../../src/implementation/location';
3536
import { newTestConnection, TestingConnection } from './connection';
3637
import { injectTestConnection } from '../../src/platform/connection';
38+
import { newTextConnection } from '../../src/platform/node/connection';
39+
import sinonChai from 'sinon-chai';
3740

3841
const fakeAppGs = testShared.makeFakeApp('gs://mybucket');
3942
const fakeAppGsEndingSlash = testShared.makeFakeApp('gs://mybucket/');
4043
const fakeAppInvalidGs = testShared.makeFakeApp('gs://mybucket/hello');
4144
const testLocation = new Location('bucket', 'object');
45+
use(sinonChai);
4246

4347
function makeGsUrl(child: string = ''): string {
4448
return 'gs://' + testShared.bucket + '/' + child;
4549
}
4650

4751
describe('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

Comments
 (0)