mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #6003
This commit is contained in:
@@ -37,6 +37,9 @@ uploadsController.upload = function (req, res, filesIterator) {
|
||||
|
||||
uploadsController.uploadPost = function (req, res, next) {
|
||||
uploadsController.upload(req, res, function (uploadedFile, next) {
|
||||
if (!parseInt(req.body.cid, 10)) {
|
||||
return next(new Error('[[error:category-not-selected]]'));
|
||||
}
|
||||
var isImage = uploadedFile.type.match(/image./);
|
||||
if (isImage) {
|
||||
uploadAsImage(req, uploadedFile, next);
|
||||
|
||||
@@ -77,6 +77,14 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to upload an image to a post with invalid cid', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), { cid: '0' }, jar, csrf_token, function (err, res, body) {
|
||||
assert.equal(res.statusCode, 500);
|
||||
assert.equal(body.error, '[[error:category-not-selected]]')
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should upload an image to a post', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
Reference in New Issue
Block a user