Skip to content

Commit

Permalink
fixed a bug in the unit-tests for the chunked-upload-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
supernomad committed Jun 25, 2015
1 parent 320c155 commit 3a1dcbf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
9 changes: 5 additions & 4 deletions routes/chunked-download-routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global Buffer */
var apiModels = require.main.require('libs/models/apiModels'),
var async = require('async'),
apiModels = require.main.require('libs/models/apiModels'),
errorModels = require.main.require('libs/models/errorModels'),
guidHelper = require.main.require('libs/helpers/guidHelper'),
errorHelper = require.main.require('libs/helpers/errorHelper'),
Expand All @@ -15,7 +16,7 @@ var debug = false,
dataCache = null;

var routes = {
"get": new apiModels.RouteHandler(routePrefix + "/:downloadId/:index", function (req, res) {
"get": new apiModels.RouteHandler(routePrefix + "/:downloadId/:index", function (req, res, next) {
var index = parseInt(req.params.index);
if (!guidHelper.isGuid(req.params.downloadId)){
throw errorModels.ValidationError("The supplied downloadId is not a valid v4 GUID");
Expand Down Expand Up @@ -48,7 +49,7 @@ var routes = {
}
});
}),
"post": new apiModels.RouteHandler(routePrefix, function (req, res) {
"post": new apiModels.RouteHandler(routePrefix, function (req, res, next) {
var valid = validators.validateDownloadRequest(req.body);
if(valid !== validators.valid) {
throw errorModels.ValidationError(valid);
Expand All @@ -68,7 +69,7 @@ var routes = {
});
});
}),
"delete": new apiModels.RouteHandler(routePrefix + "/:downloadId", function (req, res) {
"delete": new apiModels.RouteHandler(routePrefix + "/:downloadId", function (req, res, next) {
if (!guidHelper.isGuid(req.params.downloadId)){
throw errorModels.ValidationError("The supplied downloadId is not a valid v4 GUID");
}
Expand Down
42 changes: 21 additions & 21 deletions test/routes/chunked-upload-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ describe("chunked-upload-routes.js", function() {
routes.put.handler.should.be.a.Function;
});

it('should handle an error thrown by the cache updating an upload', function() {
cache_mock.setReturnErrorOnCreate(true);
routes.put.handler({
params: {
uploadId: uploadId,
index: 0
},
files: {
testFile: {
path: "random/path/to/nothing"
}
}
}, {
json: function(data) {
}
}, function(error) {
should.exist(error);
error.should.be.an.instanceOf(Error);
});
});

it('should throw a ServerError when the specified uploadId does not exist', function() {
cache_mock.setReturnValue(false);
routes.put.handler({
Expand Down Expand Up @@ -353,27 +374,6 @@ describe("chunked-upload-routes.js", function() {
error.should.be.an.instanceOf(Error);
});
});

it('should handle an error thrown by the cache updating an upload', function() {
cache_mock.setReturnErrorOnCreate(true);
routes.put.handler({
params: {
uploadId: guidHelper.newGuid(),
index: 0
},
files: {
testFile: {
path: "random/path/to/nothing"
}
}
}, {
json: function(data) {
}
}, function(error) {
should.exist(error);
error.should.be.an.instanceOf(Error);
});
});
});

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

0 comments on commit 3a1dcbf

Please sign in to comment.