Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit ce4f392

Browse files
committed
chore(tests): Refactor tests per Jacob's comments
1 parent e584905 commit ce4f392

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

tests/unit/FirebaseStorage.spec.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,34 @@ describe('$firebaseStorage', function () {
2323
});
2424
});
2525

26-
function setupPutTests(file, mockTask, isPutString) {
26+
function setupPutTests(fileOrRawString, mockTask, isPutString) {
2727
var ref = firebase.storage().ref('thing');
2828
var task = null;
2929
var storage = $firebaseStorage(ref);
3030
var putMethod = isPutString ? 'putString': 'put';
31+
var metadata = {
32+
contentType: 'image/jpeg'
33+
};
3134
// If a MockTask is provided use it as the
3235
// return value of the spy on put
3336
if (mockTask) {
3437
spyOn(ref, putMethod).and.returnValue(mockTask);
3538
} else {
3639
spyOn(ref, putMethod);
3740
}
38-
task = storage['$' + putMethod](file);
41+
if(isPutString) {
42+
task = storage.$putString(fileOrRawString, 'raw', metadata);
43+
} else {
44+
task = storage.$put(fileOrRawString, metadata);
45+
}
3946
return {
4047
ref: ref,
4148
task: task
4249
};
4350
}
4451

45-
function setupPutStringTests(file, mockTask) {
46-
return setupPutTests(file, mockTask, true);
52+
function setupPutStringTests(rawString, mockTask) {
53+
return setupPutTests(rawString, mockTask, true);
4754
}
4855

4956
it('should exist', inject(function () {
@@ -132,7 +139,9 @@ describe('$firebaseStorage', function () {
132139
var mockTask = new MockTask();
133140
var setup = setupPutTests('file', mockTask);
134141
var ref = setup.ref;
135-
expect(ref.put).toHaveBeenCalledWith('file', undefined);
142+
expect(ref.put).toHaveBeenCalledWith('file', {
143+
contentType: 'image/jpeg'
144+
});
136145
});
137146

138147
it('should return the observer functions', function () {
@@ -197,16 +206,27 @@ describe('$firebaseStorage', function () {
197206
expect(mockTask.catch).toHaveBeenCalled();
198207
});
199208

209+
it('$snapshot', function() {
210+
var mockTask = new MockTask();
211+
var setup = null;
212+
var task = null;
213+
mockTask.on('', null, null, function() {});
214+
mockTask.complete();
215+
setup = setupPutTests('file', mockTask);
216+
task = setup.task;
217+
expect(mockTask.snapshot).toEqual(task.$snapshot);
218+
});
219+
200220
});
201221

202222
describe('$putString', function() {
203-
it('should call a storage ref put', function () {
223+
it('should call a storage ref putString', function () {
204224
var mockTask = new MockTask();
205225
var setup = setupPutStringTests('string data', mockTask);
206226
var ref = setup.ref;
207-
// The two undefineds are for the optional parameters that are still
208-
// passed under the hood.
209-
expect(ref.putString).toHaveBeenCalledWith('string data', undefined, undefined);
227+
expect(ref.putString).toHaveBeenCalledWith('string data', 'raw', {
228+
contentType: 'image/jpeg'
229+
});
210230
});
211231
});
212232

@@ -279,6 +299,7 @@ describe('$firebaseStorage', function () {
279299
*/
280300
var MockTask = (function () {
281301
function MockTask() {
302+
this.snapshot = null;
282303
}
283304
MockTask.prototype.on = function (event, successCallback, errorCallback, completionCallback) {
284305
this.event = event;
@@ -287,12 +308,14 @@ var MockTask = (function () {
287308
this.completionCallback = completionCallback;
288309
};
289310
MockTask.prototype.makeProgress = function () {
311+
this.snapshot = {};
290312
this.successCallback();
291313
};
292314
MockTask.prototype.causeError = function () {
293315
this.errorCallback();
294316
};
295317
MockTask.prototype.complete = function () {
318+
this.snapshot = {};
296319
this.completionCallback();
297320
};
298321
MockTask.prototype.cancel = function () { };

0 commit comments

Comments
 (0)