Node.js based forum software built for the modern web
more tag tests
barisusakli975141bc9b03
diff --git a/src/topics/tags.js b/src/topics/tags.jsindex 352635cd04..db1be50fbe 100644--- a/src/topics/tags.js+++ b/src/topics/tags.js@@ -104,14 +104,16 @@ module.exports = function (Topics) {function updateTagCount(tag, callback) {callback = callback || function () {};- Topics.getTagTopicCount(tag, function (err, count) {- if (err) {- return callback(err);- }- count = count || 0;+ async.waterfall([+ function (next) {+ Topics.getTagTopicCount(tag, next);+ },+ function (count, next) {+ count = count || 0;- db.sortedSetAdd('tags:topic:count', count, tag, callback);- });+ db.sortedSetAdd('tags:topic:count', count, tag, next);+ }+ ], callback);}Topics.getTagTids = function (tag, start, stop, callback) {@@ -163,19 +165,19 @@ module.exports = function (Topics) {}, callback);}- Topics.deleteTag = function (tag) {- db.delete('tag:' + tag + ':topics');- db.sortedSetRemove('tags:topic:count', tag);+ Topics.deleteTag = function (tag, callback) {+ Topics.deleteTags([tag], callback);};Topics.getTags = function (start, stop, callback) {- db.getSortedSetRevRangeWithScores('tags:topic:count', start, stop, function (err, tags) {- if (err) {- return callback(err);+ async.waterfall([+ function (next) {+ db.getSortedSetRevRangeWithScores('tags:topic:count', start, stop, next);+ },+ function (tags, next) {+ Topics.getTagData(tags, next);}-- Topics.getTagData(tags, callback);- });+ ], callback);};Topics.getTagData = function (tags, callback) {@@ -183,17 +185,18 @@ module.exports = function (Topics) {return 'tag:' + tag.value;});- db.getObjects(keys, function (err, tagData) {- if (err) {- return callback(err);+ async.waterfall([+ function (next) {+ db.getObjects(keys, next);+ },+ function (tagData, next) {+ tags.forEach(function (tag, index) {+ tag.color = tagData[index] ? tagData[index].color : '';+ tag.bgColor = tagData[index] ? tagData[index].bgColor : '';+ });+ next(null, tags);}-- tags.forEach(function (tag, index) {- tag.color = tagData[index] ? tagData[index].color : '';- tag.bgColor = tagData[index] ? tagData[index].bgColor : '';- });- callback(null, tags);- });+ ], callback);};Topics.getTopicTags = function (tid, callback) {diff --git a/test/topics.js b/test/topics.jsindex a48a2d17a5..27c30599cd 100644--- a/test/topics.js+++ b/test/topics.js@@ -1046,6 +1046,21 @@ describe('Topic\'s', function () {});});+ it('should return related topics', function (done) {+ var meta = require('../src/meta');+ meta.config.maximumRelatedTopics = 2;+ var topicData = {+ tags: [{value: 'javascript'}]+ };+ topics.getRelatedTopics(topicData, 0, function (err, data) {+ assert.ifError(err);+ assert(Array.isArray(data));+ assert.equal(data[0].title, 'topic title 2');+ meta.config.maximumRelatedTopics = 0;+ done();+ });+ });+it('should return error with invalid data', function (done) {socketAdmin.tags.deleteTags({uid: adminUid}, null, function (err) {assert.equal(err.message, '[[error:invalid-data]]');@@ -1063,7 +1078,7 @@ describe('Topic\'s', function () {it('should delete tags', function (done) {socketAdmin.tags.create({uid: adminUid}, {tag: 'emptytag2'}, function (err) {assert.ifError(err);- socketAdmin.tags.deleteTags({uid: adminUid}, {tags: ['emptytag', 'emptytag2']}, function (err) {+ socketAdmin.tags.deleteTags({uid: adminUid}, {tags: ['emptytag', 'emptytag2', 'nodebb', 'nodejs']}, function (err) {assert.ifError(err);db.getObjects(['tag:emptytag', 'tag:emptytag2'], function (err, data) {assert.ifError(err);@@ -1074,6 +1089,19 @@ describe('Topic\'s', function () {});});});++ it('should delete tag', function (done) {+ topics.deleteTag('javascript', function (err) {+ assert.ifError(err);+ db.getObject('tag:javascript', function (err, data) {+ assert.ifError(err);+ assert(!data);+ done();+ });+ });+ });++});