mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	* chore: up deps * chore: up composer * fix(deps): bump 2factor to v7 * chore: up harmony * chore: up harmony * fix: missing await * feat: allow middlewares to pass in template values via res.locals * feat: buildAccountData middleware automatically added ot all account routes * fix: properly allow values in res.locals.templateValues to be added to the template data * refactor: user/blocks * refactor(accounts): categories and consent * feat: automatically 404 if exposeUid or exposeGroupName come up empty * refactor: remove calls to getUserDataByUserSlug for most account routes, since it is populated via middleware now * fix: allow exposeUid and exposeGroupName to work with slugs with mixed capitalization * fix: move reputation removal check to accountHelpers method * test: skip i18n tests if ref branch when present is not develop * fix(deps): bump theme versions * fix(deps): bump ntfy and 2factor * chore: up harmony * fix: add missing return * fix: #11191, only focus on search input on md environments and up * feat: allow file uploads on mobile chat closes https://github.com/NodeBB/NodeBB/issues/11217 * chore: up themes * chore: add lang string * fix(deps): bump ntfy to 1.0.15 * refactor: use new if/each syntax * chore: up composer * fix: regression from user helper refactor * chore: up harmony * chore: up composer * chore: up harmony * chore: up harmony * chore: up harmony * chore: fix composer version * feat: add increment helper * chore: up harmony * fix: #11228 no timestamps in future ⌛ * chore: up harmony * check config.theme as well fire action:posts.loaded after processing dom * chore: up harmony * chore: up harmony * chore: up harmony * chore: up themes * chore: up harmony * remove extra class * refactor: move these to core from harmony * chore: up widgets * chore: up widgets * height auto * fix: closes #11238 * dont focus inputs, annoying on mobile * fix: dont focus twice, only focus on chat input on desktop dont wrap widget footer in row * chore: up harmony * chore: up harmony * update chat window * chore: up themes * fix cache buster for skins * chat fixes * chore: up harmony * chore: up composer * refactor: change hook logs to debug * fix: scroll to post right after adding to dom * fix: hash scrolling and highlighting correct post * test: re-enable read API schema tests * fix: add back schema changes for179faa2270andc3920ccb10* fix: schema changes from488f0978a4* fix: schema changes forf4cf482a87* fix: schema update forbe6bbabd0e* fix: schema changes for69c96078ea* fix: schema changes ford1364c3130* fix: schema changes for84ff1152f7* fix: schema changes forb860c2605c* fix: schema changes for23cb67a112* fix: schema changes forb916e42f40* fix: schema change fora9bbb586fc* fix: schema changes for4b738c8cd3* fix: schema changes for58b5781cea* fix: schema changes for794bf01b21* fix: schema changes for80ea12c1c1,e368feef51, and52ead114be* fix: composer-default object in config? * fix: schema changes for9acdc6808cand0930934200* fix: schema changes forc0a52924f1* fix: schema change foraba420a3f3, move loggedInUser to optional props * fix: schema changes for8c67031609* fix: schema changes for27e53b42f3* fix: schema changes for2835966518* fix: breaking test for email confirmation API call * fix: schema changes for refactored search page * fix: schema changes for user object * fix: schema changes for9f531f957e* fix: schema changes forc4042c70deand23175110a2* fix: schema changes for9b3616b103* fix: schema changes for5afd5de07d* fix: schema change for1d7baf1217* fix: schema changes for57bfb37c55andbe6bbabd0e* fix: schema changes for6e86b4afa2and3efad2e13band68f66223e7* fix: allowing optional qs prop in pagination keys (not sure why this didn't break before) * fix: re-login on email change * fix: schema changes forc926358d73* fix: schema changes for388a8270c9* fix: schema change for2658bcc821* fix: no need to call account middlewares for chats routes * fix: schema changes for71743affc3* fix: final schema changes * test: support for anyOf and oneOf * fix: check thumb * dont scroll to top on back press * remove group log * fix: add top margin to merged and deleted alerts * chore: up widgets * fix: improve fix-lists mixin * chore: up harmony/composer * feat: allow hiding quicksearch results during search * dont record searches made by composer * chore: up 54 * chore: up spam be gone * feat: add prev/next page and page count into mobile paginator * chore: up harmony * chore: up harmony * use old style for IS * fix: hide entire toolbar row if no posts or not singlePost * fix: updated messaging for post-queue template, #11206 * fix: btn-sm on post queue back button * fix: bump harmony, closes #11206 * fix: remove unused alert module import * fix: bump harmony * fix: bump harmony * chore: up harmony * refactor: IS scrolltop * fix: update users:search-user-for-chat source string * feat: support for mark-read toggle on chats dropdown and recent chats list * feat: api v3 calls to mark chat read/unread * feat: send event:chats.mark socket event on mark read or unread * refactor: allow frontend to mark chats as unread, use new API v3 routes instead of socket calls, better frontend event handling * docs: openapi schema updates for chat marking * fix: allow unread state toggling in chats dropdown too * fix: issue where repeated openings of the chats dropdown would continually add events for mark-read/unread * fix: debug log * refactor: move userSearch filter to a module * feat(routes): allow remounting /categories (#11230) * feat: send flags count to frontend on flags list page * refactor: filter form client-side js to extract out some logic * fix: applyFilters to not take any arguments, update selectedCids in updateButton instead of onHidden * fix: use userFilter module for assignee, reporterId, targetUid * fix(openapi): schema changes for updated flags page * fix: dont allow adding duplicates to userFilter * use same var * remove log * fix: closes #11282 * feat: lang key for x-topics * chore: up harmony * chore: up emoji * chore: up harmony * fix: update userFilter to allow new option `selectedBlock` * fix: wrong block name passed to userFilter * fix: https://github.com/NodeBB/NodeBB/issues/11283 * fix: chats, allow multiple dropdowns like in harmony * chore: up harmony * refactor: flag note adding/editing, closes #11285 * fix: remove old prepareEdit logic * chore: add caveat about hacky code block in userFilter module * fix: placeholders for userFilter module * refactor: navigator so it works with multiple thumbs/navigators * chore: up harmony * fix: closes #11287, destroy quick reply autocomplete on navigation * fix: filter disabled categories on user categories page count * chore: up harmony * docs: update openapi spec to include info about passing in timestamps for topic creation, removing timestamp as valid request param for topic replying * fix: send back null values on ACP search dashboard for startDate and endDate if not expicitly passed in, fix tests * fix: tweak table order in ACP dash searches * fix: only invoke navigator click drag on left mouse button * feat: add back unread indicator to navigator * clear bookmark on mark unread * fix: navigator crash on ajaxify * better thumb top calculation * fix: reset user bookmark when topic is marked unread * Revert "fix: reset user bookmark when topic is marked unread" This reverts commit9bcd85c2c6. * fix: update unread indicator on scroll, add unread count * chore: bump harmony * fix: crash on navigator unread update when backing out of a topic * fix: closes #11183 * fix: update topics:recent zset when rescheduling a topic * fix: dupe quote button, increase delay, hide immediately on empty selection * fix: navigator not showing up on first load * refactor: remove glance assorted fixes to navigator dont reduce remaning count if user scrolls down and up quickly only call topic.navigatorCallback when index changes * more sanity checks for bookmark dont allow setting bookmark higher than topic postcount * closes #11218, 🚋 * Revert "fix: update topics:recent zset when rescheduling a topic" This reverts commit737973cca9. * fix: #11306, show proper error if queued post doesn't exist was showing no-privileges if someone else accepted the post * https://github.com/NodeBB/NodeBB/issues/11307 dont use li * chore: up harmony * chore: bump version string * fix: copy paste fail * feat: closes #7382, tag filtering add client side support for filtering by tags on /category, /recent and /unread * chore: up harmony * chore: up harmony * Revert "fix: add back req.query fallback for backwards compatibility" [breaking] This reverts commitcf6cc2c454. This commit is no longer required as passing in a CSRF token via query parameter is no longer supported as of NodeBB v3.x This is a breaking change. * fix: pass csrf token in form data, re: NodeBB/NodeBB#11309 * chore: up deps * fix: tests, use x-csrf-token query param removed * test: fix csrf_token * lint: remove unused * feat: add itemprop="image" to avatar helper * fix: get chat upload button in chat modal * breaking: remove deprecated socket.io methods * test: update messaging tests to not use sockets * fix: parent post links * fix: prevent post tooltip if mouse leaves before data/tpl is loaded * chore: up harmony * chore: up harmony * chore: up harmony * chore: up harmony * fix: nested replies indices * fix(deps): bump 2factor * feat: add loggedIn user to all api routes * chore: up themes * refactor: audit admin v3 write api routes as per #11321 * refactor: audit category v3 write api routes as per #11321 [breaking] docs: fix open api spec for #11321 * refactor: audit chat v3 write api routes as per #11321 * refactor: audit files v3 write api routes as per #11321 * refactor: audit flags v3 write api routes as per #11321 * refactor: audit posts v3 write api routes as per #11321 * refactor: audit topics v3 write api routes as per #11321 * refactor: audit users v3 write api routes as per #11321 * fix: lang string * remove min height * fix: empty topic/labels taking up space * fix: tag filtering when changing filter to watched topics or changing popular time limit to month * chore: up harmony * fix: closes #11354, show no post error if queued post already accepted/rejected * test: #11354 * test: #11354 * fix(deps): bump 2factor * fix: #11357 clear cache on thumb remove * fix: thumb remove on windows, closes #11357 * test: openapi for thumbs * test: fix openapi --------- Co-authored-by: Julian Lam <julian@nodebb.org> Co-authored-by: Opliko <opliko.reg@protonmail.com>
		
			
				
	
	
		
			930 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			930 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| 
 | |
| const async = require('async');
 | |
| const assert = require('assert');
 | |
| const nconf = require('nconf');
 | |
| const request = require('request');
 | |
| 
 | |
| const db = require('./mocks/databasemock');
 | |
| const Categories = require('../src/categories');
 | |
| const Topics = require('../src/topics');
 | |
| const User = require('../src/user');
 | |
| const groups = require('../src/groups');
 | |
| const privileges = require('../src/privileges');
 | |
| 
 | |
| describe('Categories', () => {
 | |
| 	let categoryObj;
 | |
| 	let posterUid;
 | |
| 	let adminUid;
 | |
| 
 | |
| 	before((done) => {
 | |
| 		async.series({
 | |
| 			posterUid: function (next) {
 | |
| 				User.create({ username: 'poster' }, next);
 | |
| 			},
 | |
| 			adminUid: function (next) {
 | |
| 				User.create({ username: 'admin' }, next);
 | |
| 			},
 | |
| 		}, (err, results) => {
 | |
| 			assert.ifError(err);
 | |
| 			posterUid = results.posterUid;
 | |
| 			adminUid = results.adminUid;
 | |
| 			groups.join('administrators', adminUid, done);
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 
 | |
| 	it('should create a new category', (done) => {
 | |
| 		Categories.create({
 | |
| 			name: 'Test Category & NodeBB',
 | |
| 			description: 'Test category created by testing script',
 | |
| 			icon: 'fa-check',
 | |
| 			blockclass: 'category-blue',
 | |
| 			order: '5',
 | |
| 		}, (err, category) => {
 | |
| 			assert.ifError(err);
 | |
| 
 | |
| 			categoryObj = category;
 | |
| 			done();
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should retrieve a newly created category by its ID', (done) => {
 | |
| 		Categories.getCategoryById({
 | |
| 			cid: categoryObj.cid,
 | |
| 			start: 0,
 | |
| 			stop: -1,
 | |
| 			uid: 0,
 | |
| 		}, (err, categoryData) => {
 | |
| 			assert.ifError(err);
 | |
| 
 | |
| 			assert(categoryData);
 | |
| 			assert.equal('Test Category & NodeBB', categoryData.name);
 | |
| 			assert.equal(categoryObj.description, categoryData.description);
 | |
| 			assert.strictEqual(categoryObj.disabled, 0);
 | |
| 			done();
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should return null if category does not exist', (done) => {
 | |
| 		Categories.getCategoryById({
 | |
| 			cid: 123123123,
 | |
| 			start: 0,
 | |
| 			stop: -1,
 | |
| 		}, (err, categoryData) => {
 | |
| 			assert.ifError(err);
 | |
| 			assert.strictEqual(categoryData, null);
 | |
| 			done();
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should get all categories', (done) => {
 | |
| 		Categories.getAllCategories(1, (err, data) => {
 | |
| 			assert.ifError(err);
 | |
| 			assert(Array.isArray(data));
 | |
| 			assert.equal(data[0].cid, categoryObj.cid);
 | |
| 			done();
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should load a category route', (done) => {
 | |
| 		request(`${nconf.get('url')}/api/category/${categoryObj.cid}/test-category`, { json: true }, (err, response, body) => {
 | |
| 			assert.ifError(err);
 | |
| 			assert.equal(response.statusCode, 200);
 | |
| 			assert.equal(body.name, 'Test Category & NodeBB');
 | |
| 			assert(body);
 | |
| 			done();
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('Categories.getRecentTopicReplies', () => {
 | |
| 		it('should not throw', (done) => {
 | |
| 			Categories.getCategoryById({
 | |
| 				cid: categoryObj.cid,
 | |
| 				set: `cid:${categoryObj.cid}:tids`,
 | |
| 				reverse: true,
 | |
| 				start: 0,
 | |
| 				stop: -1,
 | |
| 				uid: 0,
 | |
| 			}, (err, categoryData) => {
 | |
| 				assert.ifError(err);
 | |
| 				Categories.getRecentTopicReplies(categoryData, 0, {}, (err) => {
 | |
| 					assert.ifError(err);
 | |
| 					done();
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('.getCategoryTopics', () => {
 | |
| 		it('should return a list of topics', (done) => {
 | |
| 			Categories.getCategoryTopics({
 | |
| 				cid: categoryObj.cid,
 | |
| 				start: 0,
 | |
| 				stop: 10,
 | |
| 				uid: 0,
 | |
| 				sort: 'oldest_to_newest',
 | |
| 			}, (err, result) => {
 | |
| 				assert.equal(err, null);
 | |
| 
 | |
| 				assert(Array.isArray(result.topics));
 | |
| 				assert(result.topics.every(topic => topic instanceof Object));
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should return a list of topics by a specific user', (done) => {
 | |
| 			Categories.getCategoryTopics({
 | |
| 				cid: categoryObj.cid,
 | |
| 				start: 0,
 | |
| 				stop: 10,
 | |
| 				uid: 0,
 | |
| 				targetUid: 1,
 | |
| 				sort: 'oldest_to_newest',
 | |
| 			}, (err, result) => {
 | |
| 				assert.equal(err, null);
 | |
| 				assert(Array.isArray(result.topics));
 | |
| 				assert(result.topics.every(topic => topic instanceof Object && topic.uid === '1'));
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('Categories.moveRecentReplies', () => {
 | |
| 		let moveCid;
 | |
| 		let moveTid;
 | |
| 		before((done) => {
 | |
| 			async.parallel({
 | |
| 				category: function (next) {
 | |
| 					Categories.create({
 | |
| 						name: 'Test Category 2',
 | |
| 						description: 'Test category created by testing script',
 | |
| 					}, next);
 | |
| 				},
 | |
| 				topic: function (next) {
 | |
| 					Topics.post({
 | |
| 						uid: posterUid,
 | |
| 						cid: categoryObj.cid,
 | |
| 						title: 'Test Topic Title',
 | |
| 						content: 'The content of test topic',
 | |
| 					}, next);
 | |
| 				},
 | |
| 			}, (err, results) => {
 | |
| 				if (err) {
 | |
| 					return done(err);
 | |
| 				}
 | |
| 				moveCid = results.category.cid;
 | |
| 				moveTid = results.topic.topicData.tid;
 | |
| 				Topics.reply({ uid: posterUid, content: 'test post', tid: moveTid }, (err) => {
 | |
| 					done(err);
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should move posts from one category to another', (done) => {
 | |
| 			Categories.moveRecentReplies(moveTid, categoryObj.cid, moveCid, (err) => {
 | |
| 				assert.ifError(err);
 | |
| 				db.getSortedSetRange(`cid:${categoryObj.cid}:pids`, 0, -1, (err, pids) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.equal(pids.length, 0);
 | |
| 					db.getSortedSetRange(`cid:${moveCid}:pids`, 0, -1, (err, pids) => {
 | |
| 						assert.ifError(err);
 | |
| 						assert.equal(pids.length, 2);
 | |
| 						done();
 | |
| 					});
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('api/socket methods', () => {
 | |
| 		const socketCategories = require('../src/socket.io/categories');
 | |
| 		const apiCategories = require('../src/api/categories');
 | |
| 		before(async () => {
 | |
| 			await Topics.post({
 | |
| 				uid: posterUid,
 | |
| 				cid: categoryObj.cid,
 | |
| 				title: 'Test Topic Title',
 | |
| 				content: 'The content of test topic',
 | |
| 				tags: ['nodebb'],
 | |
| 			});
 | |
| 			const data = await Topics.post({
 | |
| 				uid: posterUid,
 | |
| 				cid: categoryObj.cid,
 | |
| 				title: 'will delete',
 | |
| 				content: 'The content of deleted topic',
 | |
| 			});
 | |
| 			await Topics.delete(data.topicData.tid, adminUid);
 | |
| 		});
 | |
| 
 | |
| 		it('should get recent replies in category', (done) => {
 | |
| 			socketCategories.getRecentReplies({ uid: posterUid }, categoryObj.cid, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should get categories', (done) => {
 | |
| 			socketCategories.get({ uid: posterUid }, {}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should get watched categories', (done) => {
 | |
| 			socketCategories.getWatchedCategories({ uid: posterUid }, {}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load more topics', (done) => {
 | |
| 			socketCategories.loadMore({ uid: posterUid }, {
 | |
| 				cid: categoryObj.cid,
 | |
| 				after: 0,
 | |
| 				query: {
 | |
| 					author: 'poster',
 | |
| 					tag: 'nodebb',
 | |
| 				},
 | |
| 			}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data.topics));
 | |
| 				assert.equal(data.topics[0].user.username, 'poster');
 | |
| 				assert.equal(data.topics[0].tags[0].value, 'nodebb');
 | |
| 				assert.equal(data.topics[0].category.cid, categoryObj.cid);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should not show deleted topic titles', async () => {
 | |
| 			const data = await socketCategories.loadMore({ uid: 0 }, {
 | |
| 				cid: categoryObj.cid,
 | |
| 				after: 0,
 | |
| 			});
 | |
| 
 | |
| 			assert.deepStrictEqual(
 | |
| 				data.topics.map(t => t.title),
 | |
| 				['[[topic:topic_is_deleted]]', 'Test Topic Title', 'Test Topic Title'],
 | |
| 			);
 | |
| 		});
 | |
| 
 | |
| 		it('should load topic count', (done) => {
 | |
| 			socketCategories.getTopicCount({ uid: posterUid }, categoryObj.cid, (err, topicCount) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.strictEqual(topicCount, 3);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load category by privilege', (done) => {
 | |
| 			socketCategories.getCategoriesByPrivilege({ uid: posterUid }, 'find', (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should get move categories', (done) => {
 | |
| 			socketCategories.getMoveCategories({ uid: posterUid }, {}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should ignore category', (done) => {
 | |
| 			socketCategories.ignore({ uid: posterUid }, { cid: categoryObj.cid }, (err) => {
 | |
| 				assert.ifError(err);
 | |
| 				Categories.isIgnored([categoryObj.cid], posterUid, (err, isIgnored) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.equal(isIgnored[0], true);
 | |
| 					Categories.getIgnorers(categoryObj.cid, 0, -1, (err, ignorers) => {
 | |
| 						assert.ifError(err);
 | |
| 						assert.deepEqual(ignorers, [posterUid]);
 | |
| 						done();
 | |
| 					});
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should watch category', (done) => {
 | |
| 			socketCategories.watch({ uid: posterUid }, { cid: categoryObj.cid }, (err) => {
 | |
| 				assert.ifError(err);
 | |
| 				Categories.isIgnored([categoryObj.cid], posterUid, (err, isIgnored) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.equal(isIgnored[0], false);
 | |
| 					done();
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should error if watch state does not exist', (done) => {
 | |
| 			socketCategories.setWatchState({ uid: posterUid }, { cid: categoryObj.cid, state: 'invalid-state' }, (err) => {
 | |
| 				assert.equal(err.message, '[[error:invalid-watch-state]]');
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should check if user is moderator', (done) => {
 | |
| 			socketCategories.isModerator({ uid: posterUid }, {}, (err, isModerator) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(!isModerator);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should get category data', async () => {
 | |
| 			const data = await apiCategories.get({ uid: posterUid }, { cid: categoryObj.cid });
 | |
| 			assert.equal(categoryObj.cid, data.cid);
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('admin api/socket methods', () => {
 | |
| 		const socketCategories = require('../src/socket.io/admin/categories');
 | |
| 		const apiCategories = require('../src/api/categories');
 | |
| 		let cid;
 | |
| 		before(async () => {
 | |
| 			const category = await apiCategories.create({ uid: adminUid }, {
 | |
| 				name: 'update name',
 | |
| 				description: 'update description',
 | |
| 				parentCid: categoryObj.cid,
 | |
| 				icon: 'fa-check',
 | |
| 				order: '5',
 | |
| 			});
 | |
| 			cid = category.cid;
 | |
| 		});
 | |
| 
 | |
| 		it('should return error with invalid data', async () => {
 | |
| 			let err;
 | |
| 			try {
 | |
| 				await apiCategories.update({ uid: adminUid }, null);
 | |
| 			} catch (_err) {
 | |
| 				err = _err;
 | |
| 			}
 | |
| 			assert.strictEqual(err.message, '[[error:invalid-data]]');
 | |
| 		});
 | |
| 
 | |
| 		it('should error if you try to set parent as self', async () => {
 | |
| 			const updateData = {
 | |
| 				cid,
 | |
| 				values: {
 | |
| 					parentCid: cid,
 | |
| 				},
 | |
| 			};
 | |
| 			let err;
 | |
| 			try {
 | |
| 				await apiCategories.update({ uid: adminUid }, updateData);
 | |
| 			} catch (_err) {
 | |
| 				err = _err;
 | |
| 			}
 | |
| 			assert.strictEqual(err.message, '[[error:cant-set-self-as-parent]]');
 | |
| 		});
 | |
| 
 | |
| 		it('should error if you try to set child as parent', async () => {
 | |
| 			const parentCategory = await Categories.create({ name: 'parent 1', description: 'poor parent' });
 | |
| 			const parentCid = parentCategory.cid;
 | |
| 			const childCategory = await Categories.create({ name: 'child1', description: 'wanna be parent', parentCid: parentCid });
 | |
| 			const child1Cid = childCategory.cid;
 | |
| 			const updateData = {
 | |
| 				cid: parentCid,
 | |
| 				values: {
 | |
| 					parentCid: child1Cid,
 | |
| 				},
 | |
| 			};
 | |
| 			let err;
 | |
| 			try {
 | |
| 				await apiCategories.update({ uid: adminUid }, updateData);
 | |
| 			} catch (_err) {
 | |
| 				err = _err;
 | |
| 			}
 | |
| 			assert.strictEqual(err.message, '[[error:cant-set-child-as-parent]]');
 | |
| 		});
 | |
| 
 | |
| 		it('should update category data', async () => {
 | |
| 			const updateData = {
 | |
| 				cid,
 | |
| 				values: {
 | |
| 					name: 'new name',
 | |
| 					description: 'new description',
 | |
| 					parentCid: 0,
 | |
| 					order: 3,
 | |
| 					icon: 'fa-hammer',
 | |
| 				},
 | |
| 			};
 | |
| 			await apiCategories.update({ uid: adminUid }, updateData);
 | |
| 
 | |
| 			const data = await Categories.getCategoryData(cid);
 | |
| 			assert.equal(data.name, updateData.values.name);
 | |
| 			assert.equal(data.description, updateData.values.description);
 | |
| 			assert.equal(data.parentCid, updateData.values.parentCid);
 | |
| 			assert.equal(data.order, updateData.values.order);
 | |
| 			assert.equal(data.icon, updateData.values.icon);
 | |
| 		});
 | |
| 
 | |
| 		it('should properly order categories', async () => {
 | |
| 			const p1 = await Categories.create({ name: 'p1', description: 'd', parentCid: 0, order: 1 });
 | |
| 			const c1 = await Categories.create({ name: 'c1', description: 'd1', parentCid: p1.cid, order: 1 });
 | |
| 			const c2 = await Categories.create({ name: 'c2', description: 'd2', parentCid: p1.cid, order: 2 });
 | |
| 			const c3 = await Categories.create({ name: 'c3', description: 'd3', parentCid: p1.cid, order: 3 });
 | |
| 			// move c1 to second place
 | |
| 			await apiCategories.update({ uid: adminUid }, { cid: c1.cid, values: { order: 2 } });
 | |
| 			let cids = await db.getSortedSetRange(`cid:${p1.cid}:children`, 0, -1);
 | |
| 			assert.deepStrictEqual(cids.map(Number), [c2.cid, c1.cid, c3.cid]);
 | |
| 
 | |
| 			// move c3 to front
 | |
| 			await apiCategories.update({ uid: adminUid }, { cid: c3.cid, values: { order: 1 } });
 | |
| 			cids = await db.getSortedSetRange(`cid:${p1.cid}:children`, 0, -1);
 | |
| 			assert.deepStrictEqual(cids.map(Number), [c3.cid, c2.cid, c1.cid]);
 | |
| 		});
 | |
| 
 | |
| 		it('should not remove category from parent if parent is set again to same category', async () => {
 | |
| 			const parentCat = await Categories.create({ name: 'parent', description: 'poor parent' });
 | |
| 			const updateData = {};
 | |
| 			updateData[cid] = {
 | |
| 				parentCid: parentCat.cid,
 | |
| 			};
 | |
| 			await Categories.update(updateData);
 | |
| 			let data = await Categories.getCategoryData(cid);
 | |
| 			assert.equal(data.parentCid, updateData[cid].parentCid);
 | |
| 			let childrenCids = await db.getSortedSetRange(`cid:${parentCat.cid}:children`, 0, -1);
 | |
| 			assert(childrenCids.includes(String(cid)));
 | |
| 
 | |
| 			// update again to same parent
 | |
| 			await Categories.update(updateData);
 | |
| 			data = await Categories.getCategoryData(cid);
 | |
| 			assert.equal(data.parentCid, updateData[cid].parentCid);
 | |
| 			childrenCids = await db.getSortedSetRange(`cid:${parentCat.cid}:children`, 0, -1);
 | |
| 			assert(childrenCids.includes(String(cid)));
 | |
| 		});
 | |
| 
 | |
| 		it('should purge category', async () => {
 | |
| 			const category = await Categories.create({
 | |
| 				name: 'purge me',
 | |
| 				description: 'update description',
 | |
| 			});
 | |
| 			await Topics.post({
 | |
| 				uid: posterUid,
 | |
| 				cid: category.cid,
 | |
| 				title: 'Test Topic Title',
 | |
| 				content: 'The content of test topic',
 | |
| 			});
 | |
| 			await apiCategories.delete({ uid: adminUid }, { cid: category.cid });
 | |
| 			const data = await Categories.getCategoryById(category.cid);
 | |
| 			assert.strictEqual(data, null);
 | |
| 		});
 | |
| 
 | |
| 		it('should get all category names', (done) => {
 | |
| 			socketCategories.getNames({ uid: adminUid }, {}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(Array.isArray(data));
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should give privilege', async () => {
 | |
| 			await apiCategories.setPrivilege({ uid: adminUid }, { cid: categoryObj.cid, privilege: ['groups:topics:delete'], set: true, member: 'registered-users' });
 | |
| 			const canDeleteTopics = await privileges.categories.can('topics:delete', categoryObj.cid, posterUid);
 | |
| 			assert(canDeleteTopics);
 | |
| 		});
 | |
| 
 | |
| 		it('should remove privilege', async () => {
 | |
| 			await apiCategories.setPrivilege({ uid: adminUid }, { cid: categoryObj.cid, privilege: 'groups:topics:delete', set: false, member: 'registered-users' });
 | |
| 			const canDeleteTopics = await privileges.categories.can('topics:delete', categoryObj.cid, posterUid);
 | |
| 			assert(!canDeleteTopics);
 | |
| 		});
 | |
| 
 | |
| 		it('should get privilege settings', async () => {
 | |
| 			const data = await apiCategories.getPrivileges({ uid: adminUid }, categoryObj.cid);
 | |
| 			assert(data.labels);
 | |
| 			assert(data.labels.users);
 | |
| 			assert(data.labels.groups);
 | |
| 			assert(data.keys.users);
 | |
| 			assert(data.keys.groups);
 | |
| 			assert(data.users);
 | |
| 			assert(data.groups);
 | |
| 		});
 | |
| 
 | |
| 		it('should copy privileges to children', async () => {
 | |
| 			const parentCategory = await Categories.create({ name: 'parent' });
 | |
| 			const parentCid = parentCategory.cid;
 | |
| 			const child1 = await Categories.create({ name: 'child1', parentCid: parentCid });
 | |
| 			const child2 = await Categories.create({ name: 'child2', parentCid: child1.cid });
 | |
| 			await apiCategories.setPrivilege({ uid: adminUid }, {
 | |
| 				cid: parentCid,
 | |
| 				privilege: 'groups:topics:delete',
 | |
| 				set: true,
 | |
| 				member: 'registered-users',
 | |
| 			});
 | |
| 			await socketCategories.copyPrivilegesToChildren({ uid: adminUid }, { cid: parentCid, group: '' });
 | |
| 			const canDelete = await privileges.categories.can('topics:delete', child2.cid, posterUid);
 | |
| 			assert(canDelete);
 | |
| 		});
 | |
| 
 | |
| 		it('should create category with settings from', (done) => {
 | |
| 			let child1Cid;
 | |
| 			let parentCid;
 | |
| 			async.waterfall([
 | |
| 				function (next) {
 | |
| 					Categories.create({ name: 'copy from', description: 'copy me' }, next);
 | |
| 				},
 | |
| 				function (category, next) {
 | |
| 					parentCid = category.cid;
 | |
| 					Categories.create({ name: 'child1', description: 'will be gone', cloneFromCid: parentCid }, next);
 | |
| 				},
 | |
| 				function (category, next) {
 | |
| 					child1Cid = category.cid;
 | |
| 					assert.equal(category.description, 'copy me');
 | |
| 					next();
 | |
| 				},
 | |
| 			], done);
 | |
| 		});
 | |
| 
 | |
| 		it('should copy settings from', (done) => {
 | |
| 			let child1Cid;
 | |
| 			let parentCid;
 | |
| 			async.waterfall([
 | |
| 				function (next) {
 | |
| 					Categories.create({ name: 'parent', description: 'copy me' }, next);
 | |
| 				},
 | |
| 				function (category, next) {
 | |
| 					parentCid = category.cid;
 | |
| 					Categories.create({ name: 'child1' }, next);
 | |
| 				},
 | |
| 				function (category, next) {
 | |
| 					child1Cid = category.cid;
 | |
| 					socketCategories.copySettingsFrom(
 | |
| 						{ uid: adminUid },
 | |
| 						{ fromCid: parentCid, toCid: child1Cid, copyParent: true },
 | |
| 						next
 | |
| 					);
 | |
| 				},
 | |
| 				function (destinationCategory, next) {
 | |
| 					Categories.getCategoryField(child1Cid, 'description', next);
 | |
| 				},
 | |
| 				function (description, next) {
 | |
| 					assert.equal(description, 'copy me');
 | |
| 					next();
 | |
| 				},
 | |
| 			], done);
 | |
| 		});
 | |
| 
 | |
| 		it('should copy privileges from another category', async () => {
 | |
| 			const parent = await Categories.create({ name: 'parent', description: 'copy me' });
 | |
| 			const parentCid = parent.cid;
 | |
| 			const child1 = await Categories.create({ name: 'child1' });
 | |
| 			await apiCategories.setPrivilege({ uid: adminUid }, {
 | |
| 				cid: parentCid,
 | |
| 				privilege: 'groups:topics:delete',
 | |
| 				set: true,
 | |
| 				member: 'registered-users',
 | |
| 			});
 | |
| 			await socketCategories.copyPrivilegesFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1.cid });
 | |
| 			const canDelete = await privileges.categories.can('topics:delete', child1.cid, posterUid);
 | |
| 			assert(canDelete);
 | |
| 		});
 | |
| 
 | |
| 		it('should copy privileges from another category for a single group', async () => {
 | |
| 			const parent = await Categories.create({ name: 'parent', description: 'copy me' });
 | |
| 			const parentCid = parent.cid;
 | |
| 			const child1 = await Categories.create({ name: 'child1' });
 | |
| 			await apiCategories.setPrivilege({ uid: adminUid }, {
 | |
| 				cid: parentCid,
 | |
| 				privilege: 'groups:topics:delete',
 | |
| 				set: true,
 | |
| 				member: 'registered-users',
 | |
| 			});
 | |
| 			await socketCategories.copyPrivilegesFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1.cid, group: 'registered-users' });
 | |
| 			const canDelete = await privileges.categories.can('topics:delete', child1.cid, 0);
 | |
| 			assert(!canDelete);
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should get active users', (done) => {
 | |
| 		Categories.create({
 | |
| 			name: 'test',
 | |
| 		}, (err, category) => {
 | |
| 			assert.ifError(err);
 | |
| 			Topics.post({
 | |
| 				uid: posterUid,
 | |
| 				cid: category.cid,
 | |
| 				title: 'Test Topic Title',
 | |
| 				content: 'The content of test topic',
 | |
| 			}, (err) => {
 | |
| 				assert.ifError(err);
 | |
| 				Categories.getActiveUsers(category.cid, (err, uids) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.equal(uids[0], posterUid);
 | |
| 					done();
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	describe('tag whitelist', () => {
 | |
| 		let cid;
 | |
| 		const socketTopics = require('../src/socket.io/topics');
 | |
| 		before((done) => {
 | |
| 			Categories.create({
 | |
| 				name: 'test',
 | |
| 			}, (err, category) => {
 | |
| 				assert.ifError(err);
 | |
| 				cid = category.cid;
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should error if data is invalid', (done) => {
 | |
| 			socketTopics.isTagAllowed({ uid: posterUid }, null, (err) => {
 | |
| 				assert.equal(err.message, '[[error:invalid-data]]');
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should return true if category whitelist is empty', (done) => {
 | |
| 			socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'notallowed', cid: cid }, (err, allowed) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(allowed);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should add tags to category whitelist', (done) => {
 | |
| 			const data = {};
 | |
| 			data[cid] = {
 | |
| 				tagWhitelist: 'nodebb,jquery,javascript',
 | |
| 			};
 | |
| 			Categories.update(data, (err) => {
 | |
| 				assert.ifError(err);
 | |
| 				db.getSortedSetRange(`cid:${cid}:tag:whitelist`, 0, -1, (err, tagWhitelist) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.deepEqual(['nodebb', 'jquery', 'javascript'], tagWhitelist);
 | |
| 					done();
 | |
| 				});
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should return false if category whitelist does not have tag', (done) => {
 | |
| 			socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'notallowed', cid: cid }, (err, allowed) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(!allowed);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should return true if category whitelist has tag', (done) => {
 | |
| 			socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'nodebb', cid: cid }, (err, allowed) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert(allowed);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should post a topic with only allowed tags', (done) => {
 | |
| 			Topics.post({
 | |
| 				uid: posterUid,
 | |
| 				cid: cid,
 | |
| 				title: 'Test Topic Title',
 | |
| 				content: 'The content of test topic',
 | |
| 				tags: ['nodebb', 'jquery', 'notallowed'],
 | |
| 			}, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.equal(data.topicData.tags.length, 2);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 
 | |
| 	describe('privileges', () => {
 | |
| 		const privileges = require('../src/privileges');
 | |
| 
 | |
| 		it('should return empty array if uids is empty array', (done) => {
 | |
| 			privileges.categories.filterUids('find', categoryObj.cid, [], (err, uids) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.equal(uids.length, 0);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should filter uids by privilege', (done) => {
 | |
| 			privileges.categories.filterUids('find', categoryObj.cid, [1, 2, 3, 4], (err, uids) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(uids, [1, 2]);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load category user privileges', (done) => {
 | |
| 			privileges.categories.userPrivileges(categoryObj.cid, 1, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(data, {
 | |
| 					find: false,
 | |
| 					'posts:delete': false,
 | |
| 					read: false,
 | |
| 					'topics:reply': false,
 | |
| 					'topics:read': false,
 | |
| 					'topics:create': false,
 | |
| 					'topics:tag': false,
 | |
| 					'topics:delete': false,
 | |
| 					'topics:schedule': false,
 | |
| 					'posts:edit': false,
 | |
| 					'posts:history': false,
 | |
| 					'posts:upvote': false,
 | |
| 					'posts:downvote': false,
 | |
| 					purge: false,
 | |
| 					'posts:view_deleted': false,
 | |
| 					moderate: false,
 | |
| 				});
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load global user privileges', (done) => {
 | |
| 			privileges.global.userPrivileges(1, (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(data, {
 | |
| 					ban: false,
 | |
| 					mute: false,
 | |
| 					invite: false,
 | |
| 					chat: false,
 | |
| 					'search:content': false,
 | |
| 					'search:users': false,
 | |
| 					'search:tags': false,
 | |
| 					'view:users:info': false,
 | |
| 					'upload:post:image': false,
 | |
| 					'upload:post:file': false,
 | |
| 					signature: false,
 | |
| 					'local:login': false,
 | |
| 					'group:create': false,
 | |
| 					'view:users': false,
 | |
| 					'view:tags': false,
 | |
| 					'view:groups': false,
 | |
| 				});
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load category group privileges', (done) => {
 | |
| 			privileges.categories.groupPrivileges(categoryObj.cid, 'registered-users', (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(data, {
 | |
| 					'groups:find': true,
 | |
| 					'groups:posts:edit': true,
 | |
| 					'groups:posts:history': true,
 | |
| 					'groups:posts:upvote': true,
 | |
| 					'groups:posts:downvote': true,
 | |
| 					'groups:topics:delete': false,
 | |
| 					'groups:topics:create': true,
 | |
| 					'groups:topics:reply': true,
 | |
| 					'groups:topics:tag': true,
 | |
| 					'groups:topics:schedule': false,
 | |
| 					'groups:posts:delete': true,
 | |
| 					'groups:read': true,
 | |
| 					'groups:topics:read': true,
 | |
| 					'groups:purge': false,
 | |
| 					'groups:posts:view_deleted': false,
 | |
| 					'groups:moderate': false,
 | |
| 				});
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should load global group privileges', (done) => {
 | |
| 			privileges.global.groupPrivileges('registered-users', (err, data) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(data, {
 | |
| 					'groups:ban': false,
 | |
| 					'groups:mute': false,
 | |
| 					'groups:invite': false,
 | |
| 					'groups:chat': true,
 | |
| 					'groups:search:content': true,
 | |
| 					'groups:search:users': true,
 | |
| 					'groups:search:tags': true,
 | |
| 					'groups:view:users': true,
 | |
| 					'groups:view:users:info': false,
 | |
| 					'groups:view:tags': true,
 | |
| 					'groups:view:groups': true,
 | |
| 					'groups:upload:post:image': true,
 | |
| 					'groups:upload:post:file': false,
 | |
| 					'groups:signature': true,
 | |
| 					'groups:local:login': true,
 | |
| 					'groups:group:create': false,
 | |
| 				});
 | |
| 
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		it('should return false if cid is falsy', (done) => {
 | |
| 			privileges.categories.isUserAllowedTo('find', null, adminUid, (err, isAllowed) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.equal(isAllowed, false);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 
 | |
| 		describe('Categories.getModeratorUids', () => {
 | |
| 			let cid;
 | |
| 
 | |
| 			before(async () => {
 | |
| 				({ cid } = await Categories.create({ name: 'foobar' }));
 | |
| 				await groups.create({ name: 'testGroup' });
 | |
| 				await groups.join(`cid:${cid}:privileges:groups:moderate`, 'testGroup');
 | |
| 				await groups.join('testGroup', 1);
 | |
| 			});
 | |
| 
 | |
| 			it('should retrieve all users with moderator bit in category privilege', (done) => {
 | |
| 				Categories.getModeratorUids([cid, 2], (err, uids) => {
 | |
| 					assert.ifError(err);
 | |
| 					assert.strictEqual(uids.length, 2);
 | |
| 					assert(uids[0].includes('1'));
 | |
| 					assert.strictEqual(uids[1].length, 0);
 | |
| 					done();
 | |
| 				});
 | |
| 			});
 | |
| 
 | |
| 			it('should not fail when there are multiple groups', (done) => {
 | |
| 				async.series([
 | |
| 					async.apply(groups.create, { name: 'testGroup2' }),
 | |
| 					async.apply(groups.join, 'cid:1:privileges:groups:moderate', 'testGroup2'),
 | |
| 					async.apply(groups.join, 'testGroup2', 1),
 | |
| 					function (next) {
 | |
| 						Categories.getModeratorUids([cid, 2], (err, uids) => {
 | |
| 							assert.ifError(err);
 | |
| 							assert(uids[0].includes('1'));
 | |
| 							next();
 | |
| 						});
 | |
| 					},
 | |
| 				], done);
 | |
| 			});
 | |
| 
 | |
| 			it('should not return moderators of disabled categories', async () => {
 | |
| 				const payload = {};
 | |
| 				payload[cid] = { disabled: 1 };
 | |
| 				await Categories.update(payload);
 | |
| 				const uids = await Categories.getModeratorUids([cid, 2]);
 | |
| 				assert(!uids[0].includes('1'));
 | |
| 			});
 | |
| 
 | |
| 			after((done) => {
 | |
| 				async.series([
 | |
| 					async.apply(groups.leave, `cid:${cid}:privileges:groups:moderate`, 'testGroup'),
 | |
| 					async.apply(groups.leave, `cid:${cid}:privileges:groups:moderate`, 'testGroup2'),
 | |
| 					async.apply(groups.destroy, 'testGroup'),
 | |
| 					async.apply(groups.destroy, 'testGroup2'),
 | |
| 				], done);
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 
 | |
| 	describe('getTopicIds', () => {
 | |
| 		const plugins = require('../src/plugins');
 | |
| 		it('should get topic ids with filter', (done) => {
 | |
| 			function method(data, callback) {
 | |
| 				data.tids = [1, 2, 3];
 | |
| 				callback(null, data);
 | |
| 			}
 | |
| 
 | |
| 			plugins.hooks.register('my-test-plugin', {
 | |
| 				hook: 'filter:categories.getTopicIds',
 | |
| 				method: method,
 | |
| 			});
 | |
| 
 | |
| 			Categories.getTopicIds({
 | |
| 				cid: categoryObj.cid,
 | |
| 				start: 0,
 | |
| 				stop: 19,
 | |
| 			}, (err, tids) => {
 | |
| 				assert.ifError(err);
 | |
| 				assert.deepEqual(tids, [1, 2, 3]);
 | |
| 				plugins.hooks.unregister('my-test-plugin', 'filter:categories.getTopicIds', method);
 | |
| 				done();
 | |
| 			});
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	it('should return nested children categories', async () => {
 | |
| 		const rootCategory = await Categories.create({ name: 'root' });
 | |
| 		const child1 = await Categories.create({ name: 'child1', parentCid: rootCategory.cid });
 | |
| 		const child2 = await Categories.create({ name: 'child2', parentCid: child1.cid });
 | |
| 		const data = await Categories.getCategoryById({
 | |
| 			uid: 1,
 | |
| 			cid: rootCategory.cid,
 | |
| 			start: 0,
 | |
| 			stop: 19,
 | |
| 		});
 | |
| 		assert.strictEqual(child1.cid, data.children[0].cid);
 | |
| 		assert.strictEqual(child2.cid, data.children[0].children[0].cid);
 | |
| 	});
 | |
| });
 |