mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	fix: added back missing topic thumb tests that were removed in last commit
This commit is contained in:
		| @@ -470,6 +470,11 @@ helpers.generateError = (statusCode, message) => { | ||||
| 			payload.status.code = 'not-implemented'; | ||||
| 			payload.status.message = message || 'The route you are trying to call is not implemented yet, please try again tomorrow'; | ||||
| 			break; | ||||
|  | ||||
| 		case 503: | ||||
| 			payload.status.code = 'service-unavailable'; | ||||
| 			payload.status.message = message || 'The route you are trying to call is not currently available due to a server configuration'; | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| 	return payload; | ||||
|   | ||||
| @@ -109,10 +109,10 @@ async function resizeImage(fileObj) { | ||||
| 	return fileObj; | ||||
| } | ||||
|  | ||||
| uploadsController.uploadThumb = async function (req, res, next) { | ||||
| uploadsController.uploadThumb = async function (req, res) { | ||||
| 	if (!meta.config.allowTopicsThumbnail) { | ||||
| 		deleteTempFiles(req.files.files); | ||||
| 		return next(new Error('[[error:topic-thumbnails-are-disabled]]')); | ||||
| 		return helpers.formatApiResponse(503, res, new Error('[[error:topic-thumbnails-are-disabled]]')); | ||||
| 	} | ||||
|  | ||||
| 	return await uploadsController.upload(req, res, async function (uploadedFile) { | ||||
|   | ||||
| @@ -94,13 +94,13 @@ Topics.getThumbs = async (req, res) => { | ||||
| 	helpers.formatApiResponse(200, res, await topics.thumbs.get(req.params.tid)); | ||||
| }; | ||||
|  | ||||
| Topics.addThumb = async (req, res, next) => { | ||||
| Topics.addThumb = async (req, res) => { | ||||
| 	await checkThumbPrivileges({ tid: req.params.tid, uid: req.user.uid, res }); | ||||
| 	if (res.headersSent) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	const files = await uploadsController.uploadThumb(req, res, next);	// response is handled here | ||||
| 	const files = await uploadsController.uploadThumb(req, res);	// response is handled here | ||||
|  | ||||
| 	// Add uploaded files to topic zset | ||||
| 	if (files && files.length) { | ||||
|   | ||||
| @@ -193,5 +193,30 @@ describe('Topic thumbs', () => { | ||||
| 				done(); | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		it('should fail if thumbnails are not enabled', (done) => { | ||||
| 			meta.config.allowTopicsThumbnail = 0; | ||||
|  | ||||
| 			helpers.uploadFile(`${nconf.get('url')}/api/v3/topics/${uuid}/thumbs`, path.join(__dirname, '../files/test.png'), {}, adminJar, adminCSRF, function (err, res, body) { | ||||
| 				assert.ifError(err); | ||||
| 				assert.strictEqual(res.statusCode, 503); | ||||
| 				assert(body && body.status); | ||||
| 				assert.strictEqual(body.status.message, '[[error:topic-thumbnails-are-disabled]]'); | ||||
| 				done(); | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		it('should fail if file is not image', function (done) { | ||||
| 			meta.config.allowTopicsThumbnail = 1; | ||||
|  | ||||
| 			helpers.uploadFile(`${nconf.get('url')}/api/v3/topics/${uuid}/thumbs`, path.join(__dirname, '../files/503.html'), {}, adminJar, adminCSRF, function (err, res, body) { | ||||
| 				assert.ifError(err); | ||||
| 				console.log(body); | ||||
| 				assert.strictEqual(res.statusCode, 500); | ||||
| 				assert(body && body.status); | ||||
| 				assert.strictEqual(body.status.message, '[[error:invalid-file]]'); | ||||
| 				done(); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user