Skip to content

Commit

Permalink
Fixed up some more in the chunked-upload-routes and requisite tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supernomad committed Jun 21, 2015
1 parent 41f7414 commit 13dfb37
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
27 changes: 11 additions & 16 deletions routes/chunked-upload-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var routes = {

dataCache.restore(req.params.uploadId, function name(error, upload) {
errorHelper.genericErrorHandler(error, debug);
if(typeHelper.doesExist(upload)){
if(typeHelper.doesExist(upload.value)){
res.json(new apiModels.ApiResponse(routePrefix, {}, upload.value));
} else {
throw errorModels.MissingCacheItem();
Expand Down Expand Up @@ -122,21 +122,16 @@ var routes = {

dataCache.restore(req.params.uploadId, function name(error, upload) {
errorHelper.genericErrorHandler(error, debug);
if(typeHelper.doesExist(upload)){
dataCache.delete(upload.id, function (error, count) {
errorHelper.genericErrorHandler(error);
if(count === 1) {
io.DeleteFile(upload.tempPath, function(deleteError) {
errorHelper.genericErrorHandler(deleteError);
res.json(new apiModels.ApiResponse(routePrefix, {}, "Upload: " + req.params.uploadId + ", deleted successfuly."));
});
} else {
throw errorModels.MissingCacheItem();
}
});
} else {
throw errorModels.MissingCacheItem();
}

dataCache.delete(upload.id, function (error, count) {
errorHelper.genericErrorHandler(error);
if(count === 1) {
io.DeleteFile(upload.tempPath, function(deleteError) {
errorHelper.genericErrorHandler(deleteError);
res.json(new apiModels.ApiResponse(routePrefix, {}, "Upload: " + req.params.uploadId + ", deleted successfuly."));
});
}
});
});
}),
"error": new apiModels.ErrorHandler(function (error, req, res, next) {
Expand Down
48 changes: 47 additions & 1 deletion test/routes/chunked-upload-routes-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global describe, it */
var should = require('should'),
errorModels = require.main.require('libs/models/errorModels');
errorModels = require.main.require('libs/models/errorModels'),
guidHelper = require.main.require('libs/helpers/guidHelper');

describe("chunked-upload-routes.js", function() {
var io_mock = require.main.require('mocks/libs/io'),
Expand Down Expand Up @@ -96,6 +97,19 @@ describe("chunked-upload-routes.js", function() {
});
}).should.throw();
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
(function() {
routes.get.handler({
params: {
uploadId: guidHelper.newGuid()
}
}, {
json: function(data) {
}
});
}).should.throw();
});
});

describe("#PUT", function() {
Expand Down Expand Up @@ -185,6 +199,25 @@ describe("chunked-upload-routes.js", function() {
});
}).should.throw();
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
(function() {
routes.put.handler({
params: {
uploadId: guidHelper.newGuid(),
index: "woot"
},
files: {
testFile: {
path: "random/path/to/nothing"
}
}
}, {
json: function(data) {
}
});
}).should.throw();
});
});

describe("#DELETE", function() {
Expand Down Expand Up @@ -226,6 +259,19 @@ describe("chunked-upload-routes.js", function() {
});
}).should.throw();
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
(function() {
routes.delete.handler({
params: {
uploadId: "uploadId"
}
}, {
json: function(data) {
}
});
}).should.throw();
});
});

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

0 comments on commit 13dfb37

Please sign in to comment.