Skip to content

Commit

Permalink
Fixed up some of the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supernomad committed Jun 28, 2015
1 parent 60fc9cd commit e5490c4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
12 changes: 9 additions & 3 deletions mocks/libs/io.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/* global Buffer */
function getFileStats(path, callback) {
callback(null, {
size: 1024
});
if(path.indexOf('chunksize') !== -1) {
callback(null, {
size: 1025
});
} else {
callback(null, {
size: 1024
});
}
}

function createFile(path, buffer, offset, length, callback) {
Expand Down
13 changes: 13 additions & 0 deletions test/libs/validators/chunked-upload-validators-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ describe('chunked-upload-validators.js', function () {
valid.should.equal('Upload count missing, or does not match computed value, check upload file size and chunkSize.');
});

it('should NOT return the signifier of a valid call for an uploadRequest with a count that does not match the fileSize / chunkSize + (fileSize % chunkSize > 0 ? 1 : 0)', function() {
var valid = validators.validateUploadRequest({
fileName: 'woot.txt',
fileSize: 1025,
chunkSize: 1024,
count: 3,
destination: '/i/am/a/path/to/a/destination'
}, 1025);
should.exist(valid);
valid.should.be.a.String();
valid.should.equal('Upload count missing, or does not match computed value, check upload file size and chunkSize.');
})

it('should NOT return the signifier of a valid call for an uploadRequest with improper parameter typing', function() {
var valid = validators.validateUploadRequest({
fileName: 'woot.txt',
Expand Down
21 changes: 21 additions & 0 deletions test/routes/chunked-download-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ describe('chunked-download-routes.js', function() {
});
});

it('should create a new download if the request object is considered valid', function(done) {
routes.post.handler({
body: {
path: '/i/am/a/path/to/a/chunksize'
}
}, {
json: function(data) {
should.exist(data);
should.exist(data.data);
data.data.should.be.a.Object();
data.data.count.should.be.a.Number();
data.data.chunkSize.should.be.a.Number();
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[8,9,a,b][0-9a-f]{3}-[0-9a-f]{12}$/ig.test(data.data.id).should.be.true();
downloadId = data.data.id;
done();
}
}, function() {
should.fail();
});
});

it('should throw a ServerError if the cache fails to store the download data', function(done) {
cache_mock.setReturnValue(false);
routes.post.handler({
Expand Down
25 changes: 23 additions & 2 deletions test/routes/chunked-upload-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,31 +405,52 @@ describe('chunked-upload-routes.js', function() {
});
});

it('should throw a ValidationError if the supplied uploadId is considered invalid', function() {
it('should throw a ValidationError if the supplied uploadId is considered invalid', function(done) {
routes.delete.handler({
params: {
uploadId: 'uploadId'
}
}, {
json: function() {
should.fail();
}
}, function(error) {
should.exist(error);
error.should.be.an.instanceOf(errorModels.GenericError);
done();
});
});

it('should throw a UploadMissing error if the supplied uploadId does not exist', function() {
it('should throw a UploadMissing error if the supplied uploadId does not exist', function(done) {
routes.delete.handler({
params: {
uploadId: 'uploadId'
}
}, {
json: function() {
should.fail();
}
}, function(error) {
should.exist(error);
error.should.be.an.instanceOf(errorModels.GenericError);
done();
});
});

it('should throw a ServerError if the cache fails to restore an existing upload', function(done) {
cache_mock.setReturnErrorOnDelete(true);
routes.delete.handler({
params: {
uploadId: uploadId
}
}, {
json: function() {
should.fail();
}
}, function(error) {
should.exist(error);
error.should.be.an.Error();
done();
});
});
});
Expand Down

0 comments on commit e5490c4

Please sign in to comment.