Skip to content

Commit

Permalink
Added ReadFileChunk to the io-mock and added more unit-tests around c…
Browse files Browse the repository at this point in the history
…hunked-download-routes
  • Loading branch information
supernomad committed Jun 21, 2015
1 parent 2ec0c06 commit 1dadc48
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mocks/libs/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ function renameFile(path, newPath, callback) {
callback(null);
}

function readFileChunk(path, buffer, offset, length, position, callback) {
callback(null, buffer.length, buffer);
}

module.exports = {
GetFileStats: getFileStats,
CreateFile: createFile,
WriteFileChunk: writeFileChunk,
DeleteFile: deleteFile,
ReadFile: readFile,
ReadFileChunk: readFileChunk,
RenameFile: renameFile
};
45 changes: 44 additions & 1 deletion test/routes/chunked-download-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var should = require('should'),
describe("chunked-upload-routes.js", function() {
var io_mock = require.main.require('mocks/libs/io'),
cache_mock = require.main.require('mocks/libs/caching/localCache'),
routes = require.main.require('routes/chunked-download-routes')(cache_mock, io_mock, {debug:true, routePrefix:"/chunked/download"}),
routes = require.main.require('routes/chunked-download-routes')(cache_mock, io_mock, {debug:true, routePrefix:"/chunked/download", chunkSize: 1024}),
downloadId = null;

afterEach('reset the cache_mock', function() {
Expand Down Expand Up @@ -85,6 +85,49 @@ describe("chunked-upload-routes.js", function() {
should.exist(routes.get.handler);
routes.get.handler.should.be.a.Function;
});

it('should get the specified chunk from the specified download file', function(done) {
routes.get.handler({
params: {
downloadId: downloadId,
index: 0
}
}, {
send: function(buffer) {
should.exist(buffer);
buffer.should.be.an.Buffer;
done();
}
});
});

it('should throw a ValidationError if the supplied downloadId is not a valid v4 GUID', function() {
(function() {
routes.get.handler({
params: {
downloadId: "downloadId",
index: 0
}
}, {
send: function(buffer) {
}
});
}).should.throw(errorModels.GenericError);
});

it('should throw a ValidationError if the supplied index is not a valid number >= 0', function() {
(function() {
routes.get.handler({
params: {
downloadId: downloadId,
index: ""
}
}, {
send: function(buffer) {
}
});
}).should.throw(errorModels.GenericError);
});
});

describe("#DELETE", function() {
Expand Down

0 comments on commit 1dadc48

Please sign in to comment.