ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

Update mocks for download/upload #816

Closed Heshyo closed 8 years ago

Heshyo commented 9 years ago

There is no mock for $cordovaFileTransfer.upload nor download, but there is still a mock for $cordovaFile.uploadFile and downloadFile, even if those functions are not part of $cordovaFile anymore.

Following the existing mock for $cordovaFile, we could have something like:

ngCordovaMocks.factory('$cordovaFileTransfer', ['$q', function($q) {
    var throwsError = false;

    var mockIt = function(errorMessage) {
        var defer = $q.defer();
        if (this.throwsError) {
            defer.reject(errorMessage);
        } else {
            defer.resolve();
        }
        return defer.promise;
    };

    return {
    /**
         * @ngdoc property
         * @name throwsError
         * @propertyOf ngCordovaMocks.cordovaFile
         *
         * @description
         * A flag that signals whether a promise should be rejected or not.
         * This property should only be used in automated tests.
         **/
        throwsError: throwsError,

        download: function(source, filePath, trust, options) {
            return mockIt.call(this, 'There was an error downloading the file.');
        },

        upload: function(server, filePath, options) {
            return mockIt.call(this, 'There was an error uploading the file.'); 
        }       
    };
}]);
gortok commented 9 years ago

If you write a PR that has this fix in it, I'd be happy to take a look and merge it in!

Heshyo commented 9 years ago

See https://github.com/driftyco/ng-cordova/pull/903 (I did a previous PR a few minutes ago but there were conflicts with spaces so I removed it).