Skip to content

Commit

Permalink
chore(tests): Refactor from Jacob's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davideast committed Jan 6, 2017
1 parent 8621d25 commit 3cdc6e2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 207 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ script:
- sh ./tests/travis.sh
before_script:
- grunt install
script:
- sh ./tests/travis.sh
after_script:
- cat ./tests/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
env:
Expand Down
71 changes: 18 additions & 53 deletions src/storage/FirebaseStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
totalBytes: storageSnapshot.totalBytes
};
}

function _$put(storageRef, file, $digestFn) {
var task = storageRef.put(file);

Expand All @@ -22,50 +22,31 @@
$digestFn(function () {
callback.apply(null, [unwrapStorageSnapshot(task.snapshot)]);
});
return true;
}, function () {}, function () {});
});
},
$error: function $error(callback) {
task.on('state_changed', function () {}, function (err) {
$digestFn(function () {
callback.apply(null, [err]);
});
return true;
}, function () {});
});
},
$complete: function $complete(callback) {
task.on('state_changed', function () {}, function () {}, function () {
$digestFn(function () {
callback.apply(null, [unwrapStorageSnapshot(task.snapshot)]);
});
return true;
});
},
$cancel: function $cancel() {
return task.cancel();
},
$resume: function $resume() {
return task.resume();
},
$pause: function $pause() {
return task.pause();
},
then: function then() {
return task.then();
},
catch: function _catch() {
return task.catch();
},
_task: function _task() {
return task;
}
$cancel: task.cancel,
$resume: task.resume,
$pause: task.pause,
then: task.then,
catch: task.catch,
_task: task
};
}

function _$getDownloadURL(storageRef, $q) {
return $q.when(storageRef.getDownloadURL());
}

function isStorageRef(value) {
value = value || {};
return typeof value.put === 'function';
Expand All @@ -77,54 +58,38 @@
}
}

function _$delete(storageRef, $q) {
return $q.when(storageRef.delete());
}

function _$getMetadata(storageRef, $q) {
return $q.when(storageRef.getMetadata());
}

function _$updateMetadata(storageRef, object, $q) {
return $q.when(storageRef.updateMetadata(object));
}

function FirebaseStorage($firebaseUtils, $q) {

var Storage = function Storage(storageRef) {
_assertStorageRef(storageRef);
return {
$put: function $put(file) {
return Storage.utils._$put(storageRef, file, $firebaseUtils.compile, $q);
return Storage.utils._$put(storageRef, file, $firebaseUtils.compile);
},
$getDownloadURL: function $getDownloadURL() {
return Storage.utils._$getDownloadURL(storageRef, $q);
return $q.when(storageRef.getDownloadURL());
},
$delete: function $delete() {
return Storage.utils._$delete(storageRef, $q);
return $q.when(storageRef.delete());
},
$getMetadata: function $getMetadata() {
return Storage.utils._$getMetadata(storageRef, $q);
return $q.when(storageRef.getMetadata());
},
$updateMetadata: function $updateMetadata(object) {
return Storage.utils._$updateMetadata(storageRef, object, $q);
return $q.when(storageRef.updateMetadata(object));
}
};
};

Storage.utils = {
_unwrapStorageSnapshot: unwrapStorageSnapshot,
_$put: _$put,
_$getDownloadURL: _$getDownloadURL,
_isStorageRef: isStorageRef,
_assertStorageRef: _assertStorageRef,
_$delete: _$delete,
_$getMetadata: _$getMetadata,
_$updateMetadata: _$updateMetadata
};

_assertStorageRef: _assertStorageRef
};

return Storage;
}
}

angular.module('firebase.storage')
.factory('$firebaseStorage', ["$firebaseUtils", "$q", FirebaseStorage]);
Expand Down
11 changes: 6 additions & 5 deletions src/storage/FirebaseStorageDirective.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore next */g
(function () {
"use strict";

Expand All @@ -7,11 +8,11 @@
priority: 99, // run after the attributes are interpolated
scope: {},
link: function (scope, element, attrs) {
// $observe is like $watch but it waits for interpolation
// Ex: <img firebase-src="{{ myUrl }}"/>
attrs.$observe('firebaseSrc', function (newVal) {
if (newVal !== '' && newVal !== null && newVal !== undefined) {
var storageRef = firebase.storage().ref().child(attrs.firebaseSrc);
// $observe is like $watch but it waits for interpolation
// Ex: <img firebase-src="{{ myUrl }}"/>
attrs.$observe('firebaseSrc', function (newFirebaseSrcVal) {
if (newFirebaseSrcVal !== '' && newFirebaseSrcVal !== null && newFirebaseSrcVal !== undefined) {
var storageRef = firebase.storage().ref(newFirebaseSrcVal);
var storage = $firebaseStorage(storageRef);
storage.$getDownloadURL().then(function getDownloadURL(url) {
element[0].src = url;
Expand Down
2 changes: 1 addition & 1 deletion tests/automatic_karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(config) {
singleRun: true,

preprocessors: {
"../src/!(lib)/**/!(FirebaseStorageDirective)*.js": "coverage",
"../src/!(lib)/**/*.js": "coverage",
"./fixtures/**/*.json": "html2js"
},

Expand Down
11 changes: 0 additions & 11 deletions tests/protractor/upload/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ app.controller('UploadCtrl', function Upload($scope, $firebaseStorage, $timeout)
$scope.metadata = metadata;
});

// meta data
//storageFire.$getMetadata(metadata => console.log(metadata));
// storageFire.$uploadMetadata({
// cacheControl: 'public,max-age=300',
// contentType: 'image/jpeg'
// });
}


// // Get the possible download URL
// storageFire.$getDownloadURL().then(url => {
//
// });
});
Loading

0 comments on commit 3cdc6e2

Please sign in to comment.