Skip to content

Node.js based forum software built for the modern web

additional functionality, integration, and testing for #6455

Julian Lam850f59a1aeb3
diff --git a/src/posts/create.js b/src/posts/create.js
index cbfd9de214..dc6f1a9224 100644
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@ -101,6 +101,7 @@ module.exports = function (Posts) {
function (next) {
db.incrObjectField('global', 'postCount', next);
},
+ async.apply(Posts.uploads.sync, postData.pid),
], function (err) {
next(err);
});
diff --git a/src/posts/edit.js b/src/posts/edit.js
index 1f9ffcf5ad..37c92563d3 100644
--- a/src/posts/edit.js
+++ b/src/posts/edit.js
@@ -73,6 +73,7 @@ module.exports = function (Posts) {
Posts.diffs.save(data.pid, oldContent, data.content, next);
},
+ async.apply(Posts.uploads.sync, data.pid),
function (next) {
postData.cid = results.topic.cid;
postData.topic = results.topic;
diff --git a/src/posts/uploads.js b/src/posts/uploads.js
index 610296beec..5a78e2e1df 100644
--- a/src/posts/uploads.js
+++ b/src/posts/uploads.js
@@ -34,7 +34,10 @@ module.exports = function (Posts) {
async.parallel([
async.apply(Posts.uploads.associate, pid, add),
async.apply(Posts.uploads.dissociate, pid, remove),
- ], callback);
+ ], function (err) {
+ // Strictly return only err
+ callback(err);
+ });
});
};
diff --git a/test/posts.js b/test/posts.js
index db79a401cf..6566798657 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -948,7 +948,7 @@ describe('Post\'s', function () {
], function (err, uploads) {
assert.ifError(err);
assert.strictEqual(2, uploads.length);
- assert.strictEqual('whoa.gif', uploads[1]);
+ assert.strictEqual(true, uploads.includes('whoa.gif'));
done();
});
});
@@ -960,8 +960,8 @@ describe('Post\'s', function () {
], function (err, uploads) {
assert.ifError(err);
assert.strictEqual(4, uploads.length);
- assert.strictEqual('amazeballs.jpg', uploads[2]);
- assert.strictEqual('wut.txt', uploads[3]);
+ assert.strictEqual(true, uploads.includes('amazeballs.jpg'));
+ assert.strictEqual(true, uploads.includes('wut.txt'));
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();
+ });
+ });
+ });
});