Node.js based forum software built for the modern web
test: added more topic thumbnail tests
Julian Lam28b30134249e
diff --git a/test/topicThumbs.js b/test/topicThumbs.jsindex 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();