Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Nov 7, 2014
1 parent 52cb727 commit e55b839
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ describe('File', function() {
};
var bucket = new Bucket(options, 'bucket-name');
var file;
var directoryFile;

beforeEach(function() {
file = new File(bucket, FILE_NAME);
file.makeReq_ = util.noop;

directoryFile = new File(bucket, 'directory/file.jpg');
directoryFile.makeReq_ = util.noop;
});

describe('initialization', function() {
Expand Down Expand Up @@ -111,6 +115,24 @@ describe('File', function() {
}, /should have a name/);
});

it('should URI encode file names', function(done) {
var newFile = new File(bucket, 'nested/file.jpg');

var expectedPath =
util.format('/o/{srcName}/copyTo/b/{destBucket}/o/{destName}', {
srcName: encodeURIComponent(directoryFile.name),
destBucket: file.bucket.name,
destName: encodeURIComponent(newFile.name)
});

directoryFile.makeReq_ = function(method, path, query, body, callback) {
assert.equal(path, expectedPath);
done();
};

directoryFile.copy(newFile);
});

describe('destination types', function() {
function assertPathEquals(file, expectedPath, callback) {
file.makeReq_ = function(method, path) {
Expand Down Expand Up @@ -335,6 +357,15 @@ describe('File', function() {
file.delete();
});

it('should URI encode file names', function(done) {
directoryFile.makeReq_ = function(method, path) {
assert.equal(path, '/o/' + encodeURIComponent(directoryFile.name));
done();
};

directoryFile.delete();
});

it('should execute callback', function(done) {
file.makeReq_ = function(method, path, query, body, callback) {
callback();
Expand All @@ -357,6 +388,15 @@ describe('File', function() {
file.getMetadata();
});

it('should URI encode file names', function(done) {
directoryFile.makeReq_ = function(method, path) {
assert.equal(path, '/o/' + encodeURIComponent(directoryFile.name));
done();
};

directoryFile.getMetadata();
});

it('should execute callback', function(done) {
file.makeReq_ = function(method, path, query, body, callback) {
callback();
Expand Down Expand Up @@ -407,6 +447,16 @@ describe('File', function() {
});
});

it('should URI encode file names', function(done) {
directoryFile.getSignedUrl({
action: 'read',
expires: Math.round(Date.now() / 1000) + 5
}, function(err, signedUrl) {
assert(signedUrl.indexOf(encodeURIComponent(directoryFile.name)) > -1);
done();
});
});

describe('expires', function() {
var nowInSeconds = Math.floor(Date.now() / 1000);

Expand Down Expand Up @@ -448,6 +498,15 @@ describe('File', function() {
file.setMetadata(metadata);
});

it('should URI encode file names', function(done) {
directoryFile.makeReq_ = function(method, path) {
assert.equal(path, '/o/' + encodeURIComponent(directoryFile.name));
done();
};

directoryFile.setMetadata();
});

it('should execute callback', function(done) {
file.makeReq_ = function(method, path, query, body, callback) {
callback();
Expand Down

0 comments on commit e55b839

Please sign in to comment.