additional functionality, integration, and testing for #6455

v1.18.x
Julian Lam 7 years ago
parent 5943389b7a
commit 850f59a1ae

@ -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);
});

@ -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;

@ -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);
});
});
};

@ -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();
});
});
});
});

Loading…
Cancel
Save