mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-30 18:46:01 +01:00 
			
		
		
		
	additional functionality, integration, and testing for #6455
This commit is contained in:
		| @@ -101,6 +101,7 @@ module.exports = function (Posts) { | |||||||
| 					function (next) { | 					function (next) { | ||||||
| 						db.incrObjectField('global', 'postCount', next); | 						db.incrObjectField('global', 'postCount', next); | ||||||
| 					}, | 					}, | ||||||
|  | 					async.apply(Posts.uploads.sync, postData.pid), | ||||||
| 				], function (err) { | 				], function (err) { | ||||||
| 					next(err); | 					next(err); | ||||||
| 				}); | 				}); | ||||||
|   | |||||||
| @@ -73,6 +73,7 @@ module.exports = function (Posts) { | |||||||
|  |  | ||||||
| 				Posts.diffs.save(data.pid, oldContent, data.content, next); | 				Posts.diffs.save(data.pid, oldContent, data.content, next); | ||||||
| 			}, | 			}, | ||||||
|  | 			async.apply(Posts.uploads.sync, data.pid), | ||||||
| 			function (next) { | 			function (next) { | ||||||
| 				postData.cid = results.topic.cid; | 				postData.cid = results.topic.cid; | ||||||
| 				postData.topic = results.topic; | 				postData.topic = results.topic; | ||||||
|   | |||||||
| @@ -34,7 +34,10 @@ module.exports = function (Posts) { | |||||||
| 			async.parallel([ | 			async.parallel([ | ||||||
| 				async.apply(Posts.uploads.associate, pid, add), | 				async.apply(Posts.uploads.associate, pid, add), | ||||||
| 				async.apply(Posts.uploads.dissociate, pid, remove), | 				async.apply(Posts.uploads.dissociate, pid, remove), | ||||||
| 			], callback); | 			], function (err) { | ||||||
|  | 				// Strictly return only err | ||||||
|  | 				callback(err); | ||||||
|  | 			}); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -948,7 +948,7 @@ describe('Post\'s', function () { | |||||||
| 				], function (err, uploads) { | 				], function (err, uploads) { | ||||||
| 					assert.ifError(err); | 					assert.ifError(err); | ||||||
| 					assert.strictEqual(2, uploads.length); | 					assert.strictEqual(2, uploads.length); | ||||||
| 					assert.strictEqual('whoa.gif', uploads[1]); | 					assert.strictEqual(true, uploads.includes('whoa.gif')); | ||||||
| 					done(); | 					done(); | ||||||
| 				}); | 				}); | ||||||
| 			}); | 			}); | ||||||
| @@ -960,8 +960,8 @@ describe('Post\'s', function () { | |||||||
| 				], function (err, uploads) { | 				], function (err, uploads) { | ||||||
| 					assert.ifError(err); | 					assert.ifError(err); | ||||||
| 					assert.strictEqual(4, uploads.length); | 					assert.strictEqual(4, uploads.length); | ||||||
| 					assert.strictEqual('amazeballs.jpg', uploads[2]); | 					assert.strictEqual(true, uploads.includes('amazeballs.jpg')); | ||||||
| 					assert.strictEqual('wut.txt', uploads[3]); | 					assert.strictEqual(true, uploads.includes('wut.txt')); | ||||||
| 					done(); | 					done(); | ||||||
| 				}); | 				}); | ||||||
| 			}); | 			}); | ||||||
| @@ -994,4 +994,57 @@ describe('Post\'s', function () { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|  | 	describe('post uploads management', function () { | ||||||
|  | 		let topic; | ||||||
|  | 		let reply; | ||||||
|  | 		before(function (done) { | ||||||
|  | 			topics.post({ | ||||||
|  | 				uid: 1, | ||||||
|  | 				cid: cid, | ||||||
|  | 				title: 'topic to test uploads with', | ||||||
|  | 				content: '[abcdef](/assets/uploads/files/abracadabra.png)', | ||||||
|  | 			}, function (err, topicPostData) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				topics.reply({ | ||||||
|  | 					uid: 1, | ||||||
|  | 					tid: topicPostData.topicData.tid, | ||||||
|  | 					timestamp: Date.now(), | ||||||
|  | 					content: '[abcdef](/assets/uploads/files/shazam.png)', | ||||||
|  | 				}, function (err, replyData) { | ||||||
|  | 					assert.ifError(err); | ||||||
|  | 					topic = topicPostData; | ||||||
|  | 					reply = replyData; | ||||||
|  | 					done(); | ||||||
|  | 				}); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		it('should automatically sync uploads on topic create and reply', function (done) { | ||||||
|  | 			db.sortedSetsCard(['post:' + topic.topicData.mainPid + ':uploads', 'post:' + reply.pid + ':uploads'], function (err, lengths) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				assert.strictEqual(1, lengths[0]); | ||||||
|  | 				assert.strictEqual(1, lengths[1]); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		it('should automatically sync uploads on post edit', function (done) { | ||||||
|  | 			async.waterfall([ | ||||||
|  | 				async.apply(posts.edit, { | ||||||
|  | 					pid: reply.pid, | ||||||
|  | 					uid: 1, | ||||||
|  | 					content: 'no uploads', | ||||||
|  | 				}), | ||||||
|  | 				function (postData, next) { | ||||||
|  | 					posts.uploads.list(reply.pid, next); | ||||||
|  | 				}, | ||||||
|  | 			], function (err, uploads) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				assert.strictEqual(true, Array.isArray(uploads)); | ||||||
|  | 				assert.strictEqual(0, uploads.length); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  | 	}); | ||||||
| }); | }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user