mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 19:15:28 +02:00
test: additional tests for topic thumbs
This commit is contained in:
@@ -67,7 +67,7 @@ async function getThumbs(set) {
|
|||||||
return thumbs.slice();
|
return thumbs.slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thumbs.associate = async function ({ id, path }) {
|
Thumbs.associate = async function ({ id, path, score }) {
|
||||||
// Associates a newly uploaded file as a thumb to the passed-in draft or topic
|
// Associates a newly uploaded file as a thumb to the passed-in draft or topic
|
||||||
const isDraft = validator.isUUID(String(id));
|
const isDraft = validator.isUUID(String(id));
|
||||||
const isLocal = !path.startsWith('http');
|
const isLocal = !path.startsWith('http');
|
||||||
@@ -79,7 +79,7 @@ Thumbs.associate = async function ({ id, path }) {
|
|||||||
path = path.replace(nconf.get('upload_path'), '');
|
path = path.replace(nconf.get('upload_path'), '');
|
||||||
}
|
}
|
||||||
const topics = require('.');
|
const topics = require('.');
|
||||||
await db.sortedSetAdd(set, numThumbs, path);
|
await db.sortedSetAdd(set, score || numThumbs, path);
|
||||||
if (!isDraft) {
|
if (!isDraft) {
|
||||||
const numThumbs = await db.sortedSetCard(set);
|
const numThumbs = await db.sortedSetCard(set);
|
||||||
await topics.setTopicField(id, 'numThumbs', numThumbs);
|
await topics.setTopicField(id, 'numThumbs', numThumbs);
|
||||||
@@ -96,8 +96,12 @@ Thumbs.associate = async function ({ id, path }) {
|
|||||||
Thumbs.migrate = async function (uuid, id) {
|
Thumbs.migrate = async function (uuid, id) {
|
||||||
// Converts the draft thumb zset to the topic zset (combines thumbs if applicable)
|
// Converts the draft thumb zset to the topic zset (combines thumbs if applicable)
|
||||||
const set = `draft:${uuid}:thumbs`;
|
const set = `draft:${uuid}:thumbs`;
|
||||||
const thumbs = await db.getSortedSetRange(set, 0, -1);
|
const thumbs = await db.getSortedSetRangeWithScores(set, 0, -1);
|
||||||
await Promise.all(thumbs.map(async path => await Thumbs.associate({ id, path })));
|
await Promise.all(thumbs.map(async thumb => await Thumbs.associate({
|
||||||
|
id,
|
||||||
|
path: thumb.value,
|
||||||
|
score: thumb.score,
|
||||||
|
})));
|
||||||
await db.delete(set);
|
await db.delete(set);
|
||||||
cache.del(set);
|
cache.del(set);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -157,6 +157,16 @@ describe('Topic thumbs', () => {
|
|||||||
assert(exists);
|
assert(exists);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a score equal to the number of thumbs prior to addition', async () => {
|
||||||
|
const scores = await db.sortedSetScores('topic:2:thumbs', [relativeThumbPaths[0], relativeThumbPaths[2]]);
|
||||||
|
assert.deepStrictEqual(scores, [0, 1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update the relevant topic hash with the number of thumbnails', async () => {
|
||||||
|
const numThumbs = await topics.getTopicField(2, 'numThumbs');
|
||||||
|
assert.strictEqual(parseInt(numThumbs, 10), 2);
|
||||||
|
});
|
||||||
|
|
||||||
it('should associate the thumbnail with that topic\'s main pid\'s uploads', async () => {
|
it('should associate the thumbnail with that topic\'s main pid\'s uploads', async () => {
|
||||||
const uploads = await posts.uploads.list(mainPid);
|
const uploads = await posts.uploads.list(mainPid);
|
||||||
assert(uploads.includes(path.basename(relativeThumbPaths[0])));
|
assert(uploads.includes(path.basename(relativeThumbPaths[0])));
|
||||||
|
|||||||
Reference in New Issue
Block a user