From 28b30134249e919f07b93ecbfa9a83fba17aea89 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 3 Feb 2021 16:34:39 -0500 Subject: [PATCH] test: added more topic thumbnail tests ... to test for post upload tracking logic --- test/topicThumbs.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/test/topicThumbs.js b/test/topicThumbs.js index bc952139d3..e85e1de16d 100644 --- a/test/topicThumbs.js +++ b/test/topicThumbs.js @@ -12,6 +12,7 @@ const meta = require('../src/meta'); const user = require('../src/user'); const groups = require('../src/groups'); const topics = require('../src/topics'); +const posts = require('../src/posts'); const categories = require('../src/categories'); const plugins = require('../src/plugins'); const file = require('../src/file'); @@ -112,10 +113,22 @@ describe('Topic thumbs', () => { }); describe('.associate()', () => { + let tid; + + before(async () => { + topicObj = await topics.post({ + uid: adminUid, + cid: categoryObj.cid, + title: 'Test Topic Title', + content: 'The content of test topic', + }); + tid = topicObj.topicData.tid; + }); + it('should add an uploaded file to a zset', async () => { await topics.thumbs.associate({ - id: 2, - path: thumbPaths[0], + id: tid, + path: relativeThumbPaths[0], }); const exists = await db.isSortedSetMember(`topic:2:thumbs`, relativeThumbPaths[0]); @@ -125,7 +138,7 @@ describe('Topic thumbs', () => { it('should also work with UUIDs', async () => { await topics.thumbs.associate({ id: uuid, - path: thumbPaths[1], + path: relativeThumbPaths[1], }); const exists = await db.isSortedSetMember(`draft:${uuid}:thumbs`, relativeThumbPaths[1]); @@ -134,13 +147,19 @@ describe('Topic thumbs', () => { it('should also work with a URL', async () => { await topics.thumbs.associate({ - id: 2, - path: thumbPaths[2], + id: tid, + path: relativeThumbPaths[2], }); const exists = await db.isSortedSetMember(`topic:2:thumbs`, relativeThumbPaths[2]); assert(exists); }); + + it('should associate the thumbnail with that topic\'s main pid\'s uploads', async () => { + const mainPid = (await topics.getMainPids([tid]))[0]; + const uploads = await posts.uploads.list(mainPid); + assert(uploads.includes(path.basename(relativeThumbPaths[0]))); + }); }); describe('.migrate()', () => { @@ -181,6 +200,12 @@ describe('Topic thumbs', () => { assert.strictEqual(await file.exists(thumbPaths[0]), false); }); + it('should no longer be associated with that topic\'s main pid\'s uploads', async () => { + const mainPid = (await topics.getMainPids([1]))[0]; + const uploads = await posts.uploads.list(mainPid); + assert(!uploads.includes(path.basename(relativeThumbPaths[0]))); + }); + it('should also work with UUIDs', async () => { await topics.thumbs.associate({ id: uuid, @@ -252,7 +277,7 @@ describe('Topic thumbs', () => { }); it('should fail with a non-existant tid', (done) => { - helpers.uploadFile(`${nconf.get('url')}/api/v3/topics/2/thumbs`, path.join(__dirname, './files/test.png'), {}, adminJar, adminCSRF, function (err, res, body) { + helpers.uploadFile(`${nconf.get('url')}/api/v3/topics/3/thumbs`, path.join(__dirname, './files/test.png'), {}, adminJar, adminCSRF, function (err, res, body) { assert.ifError(err); assert.strictEqual(res.statusCode, 404); done();