Node.js based forum software built for the modern web
change flag tests so they use socket methods as well
barisusaklif2e4d9ce5389
diff --git a/src/socket.io/posts/flag.js b/src/socket.io/posts/flag.jsindex 42c789eb54..077b88bfc9 100644--- a/src/socket.io/posts/flag.js+++ b/src/socket.io/posts/flag.js@@ -11,6 +11,7 @@ var privileges = require('../../privileges');var notifications = require('../../notifications');var plugins = require('../../plugins');var meta = require('../../meta');+var utils = require('../../../public/src/utils');module.exports = function (SocketPosts) {@@ -51,7 +52,8 @@ module.exports = function (SocketPosts) {}, next);},function (user, next) {- if (!user.isAdminOrMod && parseInt(user.userData.reputation, 10) < parseInt(meta.config['privileges:flag'] || 1, 10)) {+ var minimumReputation = utils.isNumber(meta.config['privileges:flag']) ? parseInt(meta.config['privileges:flag'], 10) : 1;+ if (!user.isAdminOrMod && parseInt(user.userData.reputation, 10) < minimumReputation) {return next(new Error('[[error:not-enough-reputation-to-flag]]'));}@@ -163,9 +165,8 @@ module.exports = function (SocketPosts) {return memo;}, payload);- next(null, socket.uid, data.pid, payload);- },- async.apply(posts.updateFlagData)+ posts.updateFlagData(socket.uid, data.pid, payload, next);+ }], callback);};};diff --git a/test/posts.js b/test/posts.jsindex 621a45e018..506945526e 100644--- a/test/posts.js+++ b/test/posts.js@@ -317,7 +317,17 @@ describe('Post\'s', function () {});describe('flagging a post', function () {+ var socketPosts = require('../src/socket.io/posts');+ it('should fail to flag a post due to low reputation', function (done) {+ flagPost(function (err) {+ assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]');+ done();+ });+ });+it('should flag a post', function (done) {+ var meta = require('../src/meta');+ meta.config['privileges:flag'] = -1;flagPost(function (err) {assert.ifError(err);done();@@ -325,32 +335,33 @@ describe('Post\'s', function () {});it('should return nothing without a uid or a reason', function (done) {- posts.flag(postData, null, "reason", function () {- assert.equal(arguments.length, 0);- posts.flag(postData, voteeUid, null, function () {- assert.equal(arguments.length, 0);+ socketPosts.flag({uid: 0}, {pid: postData.pid, reason: 'reason'}, function (err) {+ assert.equal(err.message, '[[error:not-logged-in]]');+ socketPosts.flag({uid: voteeUid}, {}, function (err) {+ assert.equal(err.message, '[[error:invalid-data]]');done();});});});it('should return an error without an existing post', function (done) {- posts.flag({}, voteeUid, "reason", function (err) {- assert.ifError(!err);+ socketPosts.flag({uid: voteeUid}, {pid: 12312312, reason: 'reason'}, function (err) {+ assert.equal(err.message, '[[error:no-post]]');done();});});it('should return an error if the flag already exists', function (done) {- posts.flag(postData, voteeUid, "reason", function (err) {- assert.ifError(!err);+ socketPosts.flag({uid: voteeUid}, {pid: postData.pid, reason: 'reason'}, function (err) {+ assert.equal(err.message, '[[error:already-flagged]]');done();});});});function flagPost(next) {- posts.flag(postData, voteeUid, "reason", next);+ var socketPosts = require('../src/socket.io/posts');+ socketPosts.flag({uid: voteeUid}, {pid: postData.pid, reason: 'reason'}, next);}describe('get flag data', function () {@@ -380,12 +391,22 @@ describe('Post\'s', function () {});describe('updating a flag', function () {+ var socketPosts = require('../src/socket.io/posts');+ var groups = require('../src/groups');++ before(function (done) {+ groups.join('Global Moderators', voteeUid, done);+ });+it('should update a flag', function (done) {async.waterfall([function (next) {- posts.updateFlagData(voteeUid, postData.pid, {- assignee: `${voteeUid}`,- notes: 'notes'+ socketPosts.updateFlag({uid: voteeUid}, {+ pid: postData.pid,+ data: [+ {name: 'assignee', value: `${voteeUid}`},+ {name: 'notes', value: 'notes'}+ ]}, function (err) {assert.ifError(err);posts.getFlags('posts:flagged', cid, voteeUid, 0, -1, function (err, flagData) {@@ -469,8 +490,10 @@ describe('Post\'s', function () {});describe('dismissing a flag', function () {+ var socketPosts = require('../src/socket.io/posts');+it('should dismiss a flag', function (done) {- posts.dismissFlag(postData.pid, function (err) {+ socketPosts.dismissFlag({uid: voteeUid}, postData.pid, function (err) {assert.ifError(err);posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {assert.ifError(err);@@ -498,7 +521,7 @@ describe('Post\'s', function () {});it('should dismiss all flags', function (done) {- posts.dismissAllFlags(function (err) {+ socketPosts.dismissAllFlags({uid: voteeUid}, {}, function (err) {assert.ifError(err);posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {assert.ifError(err);