Skip to content

Commit 3cdc6e2

Browse files
committed
chore(tests): Refactor from Jacob's comments
1 parent 8621d25 commit 3cdc6e2

File tree

6 files changed

+83
-207
lines changed

6 files changed

+83
-207
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ script:
1717
- sh ./tests/travis.sh
1818
before_script:
1919
- grunt install
20-
script:
21-
- sh ./tests/travis.sh
2220
after_script:
2321
- cat ./tests/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
2422
env:

src/storage/FirebaseStorage.js

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
totalBytes: storageSnapshot.totalBytes
1313
};
1414
}
15-
15+
1616
function _$put(storageRef, file, $digestFn) {
1717
var task = storageRef.put(file);
1818

@@ -22,50 +22,31 @@
2222
$digestFn(function () {
2323
callback.apply(null, [unwrapStorageSnapshot(task.snapshot)]);
2424
});
25-
return true;
26-
}, function () {}, function () {});
25+
});
2726
},
2827
$error: function $error(callback) {
2928
task.on('state_changed', function () {}, function (err) {
3029
$digestFn(function () {
3130
callback.apply(null, [err]);
3231
});
33-
return true;
34-
}, function () {});
32+
});
3533
},
3634
$complete: function $complete(callback) {
3735
task.on('state_changed', function () {}, function () {}, function () {
3836
$digestFn(function () {
3937
callback.apply(null, [unwrapStorageSnapshot(task.snapshot)]);
4038
});
41-
return true;
4239
});
4340
},
44-
$cancel: function $cancel() {
45-
return task.cancel();
46-
},
47-
$resume: function $resume() {
48-
return task.resume();
49-
},
50-
$pause: function $pause() {
51-
return task.pause();
52-
},
53-
then: function then() {
54-
return task.then();
55-
},
56-
catch: function _catch() {
57-
return task.catch();
58-
},
59-
_task: function _task() {
60-
return task;
61-
}
41+
$cancel: task.cancel,
42+
$resume: task.resume,
43+
$pause: task.pause,
44+
then: task.then,
45+
catch: task.catch,
46+
_task: task
6247
};
6348
}
6449

65-
function _$getDownloadURL(storageRef, $q) {
66-
return $q.when(storageRef.getDownloadURL());
67-
}
68-
6950
function isStorageRef(value) {
7051
value = value || {};
7152
return typeof value.put === 'function';
@@ -77,54 +58,38 @@
7758
}
7859
}
7960

80-
function _$delete(storageRef, $q) {
81-
return $q.when(storageRef.delete());
82-
}
83-
84-
function _$getMetadata(storageRef, $q) {
85-
return $q.when(storageRef.getMetadata());
86-
}
87-
88-
function _$updateMetadata(storageRef, object, $q) {
89-
return $q.when(storageRef.updateMetadata(object));
90-
}
91-
9261
function FirebaseStorage($firebaseUtils, $q) {
9362

9463
var Storage = function Storage(storageRef) {
9564
_assertStorageRef(storageRef);
9665
return {
9766
$put: function $put(file) {
98-
return Storage.utils._$put(storageRef, file, $firebaseUtils.compile, $q);
67+
return Storage.utils._$put(storageRef, file, $firebaseUtils.compile);
9968
},
10069
$getDownloadURL: function $getDownloadURL() {
101-
return Storage.utils._$getDownloadURL(storageRef, $q);
70+
return $q.when(storageRef.getDownloadURL());
10271
},
10372
$delete: function $delete() {
104-
return Storage.utils._$delete(storageRef, $q);
73+
return $q.when(storageRef.delete());
10574
},
10675
$getMetadata: function $getMetadata() {
107-
return Storage.utils._$getMetadata(storageRef, $q);
76+
return $q.when(storageRef.getMetadata());
10877
},
10978
$updateMetadata: function $updateMetadata(object) {
110-
return Storage.utils._$updateMetadata(storageRef, object, $q);
79+
return $q.when(storageRef.updateMetadata(object));
11180
}
11281
};
11382
};
11483

11584
Storage.utils = {
11685
_unwrapStorageSnapshot: unwrapStorageSnapshot,
11786
_$put: _$put,
118-
_$getDownloadURL: _$getDownloadURL,
11987
_isStorageRef: isStorageRef,
120-
_assertStorageRef: _assertStorageRef,
121-
_$delete: _$delete,
122-
_$getMetadata: _$getMetadata,
123-
_$updateMetadata: _$updateMetadata
124-
};
125-
88+
_assertStorageRef: _assertStorageRef
89+
};
90+
12691
return Storage;
127-
}
92+
}
12893

12994
angular.module('firebase.storage')
13095
.factory('$firebaseStorage', ["$firebaseUtils", "$q", FirebaseStorage]);

src/storage/FirebaseStorageDirective.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* istanbul ignore next */g
12
(function () {
23
"use strict";
34

@@ -7,11 +8,11 @@
78
priority: 99, // run after the attributes are interpolated
89
scope: {},
910
link: function (scope, element, attrs) {
10-
// $observe is like $watch but it waits for interpolation
11-
// Ex: <img firebase-src="{{ myUrl }}"/>
12-
attrs.$observe('firebaseSrc', function (newVal) {
13-
if (newVal !== '' && newVal !== null && newVal !== undefined) {
14-
var storageRef = firebase.storage().ref().child(attrs.firebaseSrc);
11+
// $observe is like $watch but it waits for interpolation
12+
// Ex: <img firebase-src="{{ myUrl }}"/>
13+
attrs.$observe('firebaseSrc', function (newFirebaseSrcVal) {
14+
if (newFirebaseSrcVal !== '' && newFirebaseSrcVal !== null && newFirebaseSrcVal !== undefined) {
15+
var storageRef = firebase.storage().ref(newFirebaseSrcVal);
1516
var storage = $firebaseStorage(storageRef);
1617
storage.$getDownloadURL().then(function getDownloadURL(url) {
1718
element[0].src = url;

tests/automatic_karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(config) {
1010
singleRun: true,
1111

1212
preprocessors: {
13-
"../src/!(lib)/**/!(FirebaseStorageDirective)*.js": "coverage",
13+
"../src/!(lib)/**/*.js": "coverage",
1414
"./fixtures/**/*.json": "html2js"
1515
},
1616

tests/protractor/upload/upload.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ app.controller('UploadCtrl', function Upload($scope, $firebaseStorage, $timeout)
3434
$scope.metadata = metadata;
3535
});
3636

37-
// meta data
38-
//storageFire.$getMetadata(metadata => console.log(metadata));
39-
// storageFire.$uploadMetadata({
40-
// cacheControl: 'public,max-age=300',
41-
// contentType: 'image/jpeg'
42-
// });
4337
}
4438

45-
46-
// // Get the possible download URL
47-
// storageFire.$getDownloadURL().then(url => {
48-
//
49-
// });
5039
});

0 commit comments

Comments
 (0)