mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-02 03:17:06 +02:00
Merge branch 'master' into develop
This commit is contained in:
8
test/.eslintrc
Normal file
8
test/.eslintrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-vars": "off"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require, before*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var nconf = require('nconf');
|
||||
@@ -12,7 +12,7 @@ describe('authentication', function () {
|
||||
var jar = request.jar();
|
||||
var regularUid;
|
||||
before(function (done) {
|
||||
user.create({username: 'regular', password: 'regularpwd', email: 'regular@nodebb.org' }, function (err, uid) {
|
||||
user.create({ username: 'regular', password: 'regularpwd', email: 'regular@nodebb.org' }, function (err, uid) {
|
||||
assert.ifError(err);
|
||||
regularUid = uid;
|
||||
done();
|
||||
@@ -23,7 +23,7 @@ describe('authentication', function () {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -36,8 +36,8 @@ describe('authentication', function () {
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
}
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
@@ -45,7 +45,7 @@ describe('authentication', function () {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/me',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
@@ -61,7 +61,7 @@ describe('authentication', function () {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -70,15 +70,15 @@ describe('authentication', function () {
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
}
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
|
||||
request({
|
||||
url: nconf.get('url') + '/api/me',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(body, 'not-authorized');
|
||||
@@ -93,7 +93,7 @@ describe('authentication', function () {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -105,8 +105,8 @@ describe('authentication', function () {
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
}
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
@@ -114,7 +114,7 @@ describe('authentication', function () {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/me',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
@@ -136,7 +136,7 @@ describe('authentication', function () {
|
||||
db.sortedSetCard('uid:' + regularUid + ':sessions', function (err, count) {
|
||||
assert.ifError(err);
|
||||
assert(count);
|
||||
socketAdmin.deleteAllSessions({uid: 1}, {}, function (err) {
|
||||
socketAdmin.deleteAllSessions({ uid: 1 }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
db.sortedSetCard('uid:' + regularUid + ':sessions', function (err, count) {
|
||||
assert.ifError(err);
|
||||
@@ -145,13 +145,11 @@ describe('authentication', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
/* global require, after, before*/
|
||||
|
||||
|
||||
var async = require('async');
|
||||
@@ -11,12 +12,11 @@ var user = require('../src/user');
|
||||
var blacklist = require('../src/meta/blacklist');
|
||||
|
||||
describe('blacklist', function () {
|
||||
|
||||
var adminUid;
|
||||
|
||||
before(function (done) {
|
||||
groups.resetCache();
|
||||
user.create({username: 'admin'}, function (err, uid) {
|
||||
user.create({ username: 'admin' }, function (err, uid) {
|
||||
assert.ifError(err);
|
||||
adminUid = uid;
|
||||
groups.join('administrators', adminUid, done);
|
||||
@@ -27,8 +27,8 @@ describe('blacklist', function () {
|
||||
var rules = '1.1.1.1\n2.2.2.2\n::ffff:0:2.2.2.2\n127.0.0.1\n192.168.100.0/22';
|
||||
|
||||
it('should validate blacklist', function (done) {
|
||||
socketBlacklist.validate({uid: adminUid}, {
|
||||
rules: rules
|
||||
socketBlacklist.validate({ uid: adminUid }, {
|
||||
rules: rules,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
@@ -36,14 +36,14 @@ describe('blacklist', function () {
|
||||
});
|
||||
|
||||
it('should error if not admin', function (done) {
|
||||
socketBlacklist.save({uid: 0}, rules, function (err) {
|
||||
socketBlacklist.save({ uid: 0 }, rules, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should save blacklist', function (done) {
|
||||
socketBlacklist.save({uid: adminUid}, rules, function (err) {
|
||||
socketBlacklist.save({ uid: adminUid }, rules, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -5,7 +5,6 @@ var assert = require('assert');
|
||||
var db = require('./mocks/databasemock');
|
||||
|
||||
describe('Build', function () {
|
||||
|
||||
it('should build all assets', function (done) {
|
||||
this.timeout(50000);
|
||||
var build = require('../src/meta/build');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
|
||||
var async = require('async');
|
||||
@@ -23,11 +22,11 @@ describe('Categories', function () {
|
||||
groups.resetCache();
|
||||
async.parallel({
|
||||
posterUid: function (next) {
|
||||
User.create({username: 'poster'}, next);
|
||||
User.create({ username: 'poster' }, next);
|
||||
},
|
||||
adminUid: function (next) {
|
||||
User.create({username: 'admin'}, next);
|
||||
}
|
||||
User.create({ username: 'admin' }, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
assert.ifError(err);
|
||||
posterUid = results.posterUid;
|
||||
@@ -38,13 +37,12 @@ describe('Categories', function () {
|
||||
|
||||
|
||||
it('should create a new category', function (done) {
|
||||
|
||||
Categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script',
|
||||
icon: 'fa-check',
|
||||
blockclass: 'category-blue',
|
||||
order: '5'
|
||||
order: '5',
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -60,7 +58,7 @@ describe('Categories', function () {
|
||||
reverse: true,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
uid: 0
|
||||
uid: 0,
|
||||
}, function (err, categoryData) {
|
||||
assert.equal(err, null);
|
||||
|
||||
@@ -90,7 +88,7 @@ describe('Categories', function () {
|
||||
reverse: true,
|
||||
start: 0,
|
||||
stop: -1,
|
||||
uid: 0
|
||||
uid: 0,
|
||||
}, function (err, categoryData) {
|
||||
assert.ifError(err);
|
||||
Categories.getRecentTopicReplies(categoryData, 0, function (err) {
|
||||
@@ -109,7 +107,7 @@ describe('Categories', function () {
|
||||
reverse: true,
|
||||
start: 0,
|
||||
stop: 10,
|
||||
uid: 0
|
||||
uid: 0,
|
||||
}, function (err, result) {
|
||||
assert.equal(err, null);
|
||||
|
||||
@@ -130,7 +128,7 @@ describe('Categories', function () {
|
||||
start: 0,
|
||||
stop: 10,
|
||||
uid: 0,
|
||||
targetUid: 1
|
||||
targetUid: 1,
|
||||
}, function (err, result) {
|
||||
assert.equal(err, null);
|
||||
assert(Array.isArray(result.topics));
|
||||
@@ -151,7 +149,7 @@ describe('Categories', function () {
|
||||
category: function (next) {
|
||||
Categories.create({
|
||||
name: 'Test Category 2',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
topic: function (next) {
|
||||
@@ -159,16 +157,16 @@ describe('Categories', function () {
|
||||
uid: posterUid,
|
||||
cid: categoryObj.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
content: 'The content of test topic',
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
}, function (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}, function (err) {
|
||||
Topics.reply({ uid: posterUid, content: 'test post', tid: moveTid }, function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
@@ -199,12 +197,12 @@ describe('Categories', function () {
|
||||
cid: categoryObj.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic',
|
||||
tags: ['nodebb']
|
||||
tags: ['nodebb'],
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should get recent replies in category', function (done) {
|
||||
socketCategories.getRecentReplies({uid: posterUid}, categoryObj.cid, function (err, data) {
|
||||
socketCategories.getRecentReplies({ uid: posterUid }, categoryObj.cid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -212,7 +210,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should get categories', function (done) {
|
||||
socketCategories.get({uid: posterUid}, {}, function (err, data) {
|
||||
socketCategories.get({ uid: posterUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -220,7 +218,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should get watched categories', function (done) {
|
||||
socketCategories.getWatchedCategories({uid: posterUid}, {}, function (err, data) {
|
||||
socketCategories.getWatchedCategories({ uid: posterUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -228,7 +226,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should load more topics', function (done) {
|
||||
socketCategories.loadMore({uid: posterUid}, {cid: categoryObj.cid, after: 0, author: 'poster', tag: 'nodebb'}, function (err, data) {
|
||||
socketCategories.loadMore({ uid: posterUid }, { cid: categoryObj.cid, after: 0, author: 'poster', tag: 'nodebb' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data.topics));
|
||||
assert.equal(data.topics[0].user.username, 'poster');
|
||||
@@ -239,7 +237,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should load page count', function (done) {
|
||||
socketCategories.getPageCount({uid: posterUid}, categoryObj.cid, function (err, pageCount) {
|
||||
socketCategories.getPageCount({ uid: posterUid }, categoryObj.cid, function (err, pageCount) {
|
||||
assert.ifError(err);
|
||||
assert.equal(pageCount, 1);
|
||||
done();
|
||||
@@ -247,7 +245,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should load page count', function (done) {
|
||||
socketCategories.getTopicCount({uid: posterUid}, categoryObj.cid, function (err, topicCount) {
|
||||
socketCategories.getTopicCount({ uid: posterUid }, categoryObj.cid, function (err, topicCount) {
|
||||
assert.ifError(err);
|
||||
assert.equal(topicCount, 2);
|
||||
done();
|
||||
@@ -255,7 +253,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should load category by privilege', function (done) {
|
||||
socketCategories.getCategoriesByPrivilege({uid: posterUid}, 'find', function (err, data) {
|
||||
socketCategories.getCategoriesByPrivilege({ uid: posterUid }, 'find', function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -263,7 +261,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should get move categories', function (done) {
|
||||
socketCategories.getMoveCategories({uid: posterUid}, {}, function (err, data) {
|
||||
socketCategories.getMoveCategories({ uid: posterUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -271,7 +269,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should ignore category', function (done) {
|
||||
socketCategories.ignore({uid: posterUid}, categoryObj.cid, function (err) {
|
||||
socketCategories.ignore({ uid: posterUid }, categoryObj.cid, function (err) {
|
||||
assert.ifError(err);
|
||||
Categories.isIgnored([categoryObj.cid], posterUid, function (err, isIgnored) {
|
||||
assert.ifError(err);
|
||||
@@ -282,7 +280,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should watch category', function (done) {
|
||||
socketCategories.watch({uid: posterUid}, categoryObj.cid, function (err) {
|
||||
socketCategories.watch({ uid: posterUid }, categoryObj.cid, function (err) {
|
||||
assert.ifError(err);
|
||||
Categories.isIgnored([categoryObj.cid], posterUid, function (err, isIgnored) {
|
||||
assert.ifError(err);
|
||||
@@ -293,15 +291,15 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should check if user is moderator', function (done) {
|
||||
socketCategories.isModerator({uid: posterUid}, {}, function (err, isModerator) {
|
||||
socketCategories.isModerator({ uid: posterUid }, {}, function (err, isModerator) {
|
||||
assert.ifError(err);
|
||||
assert(!isModerator);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get category data' , function (done) {
|
||||
socketCategories.getCategory({uid: posterUid}, categoryObj.cid, function (err, data) {
|
||||
it('should get category data', function (done) {
|
||||
socketCategories.getCategory({ uid: posterUid }, categoryObj.cid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(categoryObj.cid, data.cid);
|
||||
done();
|
||||
@@ -313,12 +311,12 @@ describe('Categories', function () {
|
||||
var socketCategories = require('../src/socket.io/admin/categories');
|
||||
var cid;
|
||||
before(function (done) {
|
||||
socketCategories.create({uid: adminUid}, {
|
||||
socketCategories.create({ uid: adminUid }, {
|
||||
name: 'update name',
|
||||
description: 'update description',
|
||||
parentCid: categoryObj.cid,
|
||||
icon: 'fa-check',
|
||||
order: '5'
|
||||
order: '5',
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -328,7 +326,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should return error with invalid data', function (done) {
|
||||
socketCategories.update({uid: adminUid}, null, function (err) {
|
||||
socketCategories.update({ uid: adminUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
@@ -337,9 +335,9 @@ describe('Categories', function () {
|
||||
it('should error if you try to set parent as self', function (done) {
|
||||
var updateData = {};
|
||||
updateData[cid] = {
|
||||
parentCid: cid
|
||||
parentCid: cid,
|
||||
};
|
||||
socketCategories.update({uid: adminUid}, updateData, function (err) {
|
||||
socketCategories.update({ uid: adminUid }, updateData, function (err) {
|
||||
assert.equal(err.message, '[[error:cant-set-self-as-parent]]');
|
||||
done();
|
||||
});
|
||||
@@ -352,9 +350,9 @@ describe('Categories', function () {
|
||||
description: 'new description',
|
||||
parentCid: 0,
|
||||
order: 3,
|
||||
icon: 'fa-hammer'
|
||||
icon: 'fa-hammer',
|
||||
};
|
||||
socketCategories.update({uid: adminUid}, updateData, function (err) {
|
||||
socketCategories.update({ uid: adminUid }, updateData, function (err) {
|
||||
assert.ifError(err);
|
||||
Categories.getCategoryData(cid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
@@ -371,34 +369,33 @@ describe('Categories', function () {
|
||||
it('should purge category', function (done) {
|
||||
Categories.create({
|
||||
name: 'purge me',
|
||||
description: 'update description'
|
||||
description: 'update description',
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
Topics.post({
|
||||
uid: posterUid,
|
||||
cid: category.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
content: 'The content of test topic',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
socketCategories.purge({uid: adminUid}, category.cid, function (err) {
|
||||
socketCategories.purge({ uid: adminUid }, category.cid, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all categories', function (done) {
|
||||
socketCategories.getAll({uid: adminUid}, {}, function (err, data) {
|
||||
socketCategories.getAll({ uid: adminUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all category names', function (done) {
|
||||
socketCategories.getNames({uid: adminUid}, {}, function (err, data) {
|
||||
socketCategories.getNames({ uid: adminUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
@@ -406,7 +403,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should give privilege', function (done) {
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: categoryObj.cid, privilege: ['groups:topics:delete'], set: true, member: 'registered-users'}, function (err) {
|
||||
socketCategories.setPrivilege({ uid: adminUid }, { cid: categoryObj.cid, privilege: ['groups:topics:delete'], set: true, member: 'registered-users' }, function (err) {
|
||||
assert.ifError(err);
|
||||
privileges.categories.can('topics:delete', categoryObj.cid, posterUid, function (err, canDeleteTopcis) {
|
||||
assert.ifError(err);
|
||||
@@ -417,7 +414,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should remove privilege', function (done) {
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: categoryObj.cid, privilege: 'groups:topics:delete', set: false, member: 'registered-users'}, function (err) {
|
||||
socketCategories.setPrivilege({ uid: adminUid }, { cid: categoryObj.cid, privilege: 'groups:topics:delete', set: false, member: 'registered-users' }, function (err) {
|
||||
assert.ifError(err);
|
||||
privileges.categories.can('topics:delete', categoryObj.cid, posterUid, function (err, canDeleteTopcis) {
|
||||
assert.ifError(err);
|
||||
@@ -428,7 +425,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should get privilege settings', function (done) {
|
||||
socketCategories.getPrivilegeSettings({uid: adminUid}, categoryObj.cid, function (err, data) {
|
||||
socketCategories.getPrivilegeSettings({ uid: adminUid }, categoryObj.cid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -441,22 +438,22 @@ describe('Categories', function () {
|
||||
var child2Cid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent'}, next);
|
||||
Categories.create({ name: 'parent' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1', parentCid: parentCid}, next);
|
||||
Categories.create({ name: 'child1', parentCid: parentCid }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
Categories.create({name: 'child2', parentCid: child1Cid}, next);
|
||||
Categories.create({ name: 'child2', parentCid: child1Cid }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child2Cid = category.cid;
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users'}, next);
|
||||
socketCategories.setPrivilege({ uid: adminUid }, { cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users' }, next);
|
||||
},
|
||||
function (next) {
|
||||
socketCategories.copyPrivilegesToChildren({uid: adminUid}, parentCid, next);
|
||||
socketCategories.copyPrivilegesToChildren({ uid: adminUid }, parentCid, next);
|
||||
},
|
||||
function (next) {
|
||||
privileges.categories.can('topics:delete', child2Cid, posterUid, next);
|
||||
@@ -464,7 +461,7 @@ describe('Categories', function () {
|
||||
function (canDelete, next) {
|
||||
assert(canDelete);
|
||||
next();
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -473,15 +470,15 @@ describe('Categories', function () {
|
||||
var parentCid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent', description: 'copy me'}, next);
|
||||
Categories.create({ name: 'parent', description: 'copy me' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1'}, next);
|
||||
Categories.create({ name: 'child1' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
socketCategories.copySettingsFrom({uid: adminUid}, {fromCid: parentCid, toCid: child1Cid}, next);
|
||||
socketCategories.copySettingsFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid }, next);
|
||||
},
|
||||
function (canDelete, next) {
|
||||
Categories.getCategoryField(child1Cid, 'description', next);
|
||||
@@ -489,7 +486,7 @@ describe('Categories', function () {
|
||||
function (description, next) {
|
||||
assert.equal(description, 'copy me');
|
||||
next();
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -498,18 +495,18 @@ describe('Categories', function () {
|
||||
var parentCid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent', description: 'copy me'}, next);
|
||||
Categories.create({ name: 'parent', description: 'copy me' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1'}, next);
|
||||
Categories.create({ name: 'child1' }, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users'}, next);
|
||||
socketCategories.setPrivilege({ uid: adminUid }, { cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users' }, next);
|
||||
},
|
||||
function (next) {
|
||||
socketCategories.copyPrivilegesFrom({uid: adminUid}, {fromCid: parentCid, toCid: child1Cid}, next);
|
||||
socketCategories.copyPrivilegesFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid }, next);
|
||||
},
|
||||
function (next) {
|
||||
privileges.categories.can('topics:delete', child1Cid, posterUid, next);
|
||||
@@ -517,21 +514,21 @@ describe('Categories', function () {
|
||||
function (canDelete, next) {
|
||||
assert(canDelete);
|
||||
next();
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should get active users', function (done) {
|
||||
Categories.create({
|
||||
name: 'test'
|
||||
name: 'test',
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
Topics.post({
|
||||
uid: posterUid,
|
||||
cid: category.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
content: 'The content of test topic',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
Categories.getActiveUsers(category.cid, function (err, uids) {
|
||||
@@ -548,7 +545,7 @@ describe('Categories', function () {
|
||||
var socketTopics = require('../src/socket.io/topics');
|
||||
before(function (done) {
|
||||
Categories.create({
|
||||
name: 'test'
|
||||
name: 'test',
|
||||
}, function (err, category) {
|
||||
assert.ifError(err);
|
||||
cid = category.cid;
|
||||
@@ -557,14 +554,14 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should error if data is invalid', function (done) {
|
||||
socketTopics.isTagAllowed({uid: posterUid}, null, function (err) {
|
||||
socketTopics.isTagAllowed({ uid: posterUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if category whitelist is empty', function (done) {
|
||||
socketTopics.isTagAllowed({uid: posterUid}, {tag: 'notallowed', cid: cid}, function (err, allowed) {
|
||||
socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'notallowed', cid: cid }, function (err, allowed) {
|
||||
assert.ifError(err);
|
||||
assert(allowed);
|
||||
done();
|
||||
@@ -574,7 +571,7 @@ describe('Categories', function () {
|
||||
it('should add tags to category whitelist', function (done) {
|
||||
var data = {};
|
||||
data[cid] = {
|
||||
tagWhitelist: 'nodebb,jquery,javascript'
|
||||
tagWhitelist: 'nodebb,jquery,javascript',
|
||||
};
|
||||
Categories.update(data, function (err) {
|
||||
assert.ifError(err);
|
||||
@@ -587,7 +584,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should return false if category whitelist does not have tag', function (done) {
|
||||
socketTopics.isTagAllowed({uid: posterUid}, {tag: 'notallowed', cid: cid}, function (err, allowed) {
|
||||
socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'notallowed', cid: cid }, function (err, allowed) {
|
||||
assert.ifError(err);
|
||||
assert(!allowed);
|
||||
done();
|
||||
@@ -595,7 +592,7 @@ describe('Categories', function () {
|
||||
});
|
||||
|
||||
it('should return true if category whitelist has tag', function (done) {
|
||||
socketTopics.isTagAllowed({uid: posterUid}, {tag: 'nodebb', cid: cid}, function (err, allowed) {
|
||||
socketTopics.isTagAllowed({ uid: posterUid }, { tag: 'nodebb', cid: cid }, function (err, allowed) {
|
||||
assert.ifError(err);
|
||||
assert(allowed);
|
||||
done();
|
||||
@@ -608,7 +605,7 @@ describe('Categories', function () {
|
||||
cid: cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic',
|
||||
tags: ['nodebb', 'jquery', 'notallowed']
|
||||
tags: ['nodebb', 'jquery', 'notallowed'],
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.topicData.tags.length, 2);
|
||||
|
||||
@@ -13,7 +13,6 @@ var groups = require('../src/groups');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
describe('Admin Controllers', function () {
|
||||
|
||||
var tid;
|
||||
var cid;
|
||||
var pid;
|
||||
@@ -26,15 +25,15 @@ describe('Admin Controllers', function () {
|
||||
category: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
adminUid: function (next) {
|
||||
user.create({username: 'admin', password: 'barbar'}, next);
|
||||
user.create({ username: 'admin', password: 'barbar' }, next);
|
||||
},
|
||||
regularUid: function (next) {
|
||||
user.create({username: 'regular'}, next);
|
||||
}
|
||||
user.create({ username: 'regular' }, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -43,7 +42,7 @@ describe('Admin Controllers', function () {
|
||||
regularUid = results.regularUid;
|
||||
cid = results.category.cid;
|
||||
|
||||
topics.post({uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
|
||||
topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) {
|
||||
tid = result.topicData.tid;
|
||||
pid = result.postData.pid;
|
||||
done(err);
|
||||
@@ -55,7 +54,7 @@ describe('Admin Controllers', function () {
|
||||
helpers.loginUser('admin', 'barbar', function (err, _jar) {
|
||||
assert.ifError(err);
|
||||
jar = _jar;
|
||||
request(nconf.get('url') + '/admin', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 403);
|
||||
assert(body);
|
||||
@@ -67,7 +66,7 @@ describe('Admin Controllers', function () {
|
||||
it('should load admin dashboard', function (done) {
|
||||
groups.join('administrators', adminUid, function (err) {
|
||||
assert.ifError(err);
|
||||
request(nconf.get('url') + '/admin', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -77,7 +76,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load groups page', function (done) {
|
||||
request(nconf.get('url') + '/admin/manage/groups', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin/manage/groups', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -86,7 +85,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load groups detail page', function (done) {
|
||||
request(nconf.get('url') + '/admin/manage/groups/administrators', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin/manage/groups/administrators', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -96,7 +95,7 @@ describe('Admin Controllers', function () {
|
||||
|
||||
|
||||
it('should load general settings page', function (done) {
|
||||
request(nconf.get('url') + '/admin/settings', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin/settings', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -105,7 +104,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load email settings page', function (done) {
|
||||
request(nconf.get('url') + '/admin/settings/email', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/admin/settings/email', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -114,7 +113,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load info page for a user', function (done) {
|
||||
request(nconf.get('url') + '/api/user/regular/info', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/regular/info', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body.history);
|
||||
@@ -127,7 +126,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should 404 for edit/email page if user does not exist', function (done) {
|
||||
request(nconf.get('url') + '/api/user/doesnotexist/edit/email', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/doesnotexist/edit/email', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
done();
|
||||
@@ -135,7 +134,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/homepage', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/homepage', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/general/homepage', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body.routes);
|
||||
@@ -144,7 +143,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/database', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/database', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/database', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
|
||||
@@ -158,7 +157,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/extend/plugins', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/extend/plugins', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/extend/plugins', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body.hasOwnProperty('installed'));
|
||||
assert(body.hasOwnProperty('upgradeCount'));
|
||||
@@ -169,7 +168,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -177,7 +176,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/search', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/search', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/search', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body.users);
|
||||
done();
|
||||
@@ -185,7 +184,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/not-validated', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/not-validated', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/not-validated', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -193,7 +192,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/no-posts', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/no-posts', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/no-posts', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -201,7 +200,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/top-posters', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/top-posters', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/top-posters', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -209,7 +208,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/most-reputation', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/most-reputation', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/most-reputation', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -217,7 +216,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/inactive', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/inactive', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/inactive', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -225,7 +224,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/flagged', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/flagged', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/flagged', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -233,7 +232,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/users/banned', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/banned', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/users/banned', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -241,7 +240,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/registration', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/registration', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/registration', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -249,7 +248,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/users/csv', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/users/csv', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/users/csv', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -257,7 +256,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/flags', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/flags', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/flags', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -265,7 +264,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/cache', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/cache', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/cache', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -273,7 +272,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/errors', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/errors', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/errors', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -281,7 +280,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/errors/export', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/errors/export', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/errors/export', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -289,7 +288,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/logs', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/logs', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/logs', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -297,7 +296,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/navigation', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/navigation', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -305,7 +304,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/development/info', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/development/info', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/development/info', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -313,7 +312,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/development/logger', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/development/logger', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/development/logger', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -321,7 +320,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/advanced/events', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/events', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/advanced/events', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -329,7 +328,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/sounds', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/sounds', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/general/sounds', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -337,7 +336,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/categories', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -345,7 +344,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/categories/1', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories/1', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories/1', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -353,7 +352,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/categories/1/analytics', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories/1/analytics', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/categories/1/analytics', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -361,7 +360,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/extend/rewards', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/extend/rewards', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/extend/rewards', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -369,7 +368,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/extend/widgets', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/extend/widgets', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/extend/widgets', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -377,7 +376,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/languages', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/languages', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/general/languages', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -385,7 +384,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/social', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/social', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/general/social', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -393,7 +392,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/tags', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/tags', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/tags', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -401,7 +400,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/manage/ip-blacklist', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/manage/ip-blacklist', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/manage/ip-blacklist', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -409,7 +408,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/appearance/themes', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/appearance/themes', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/appearance/themes', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -417,7 +416,7 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/appearance/customise', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/appearance/customise', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/admin/appearance/customise', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
@@ -427,7 +426,7 @@ describe('Admin Controllers', function () {
|
||||
it('should load /recent in maintenance mode', function (done) {
|
||||
var meta = require('../src/meta');
|
||||
meta.config.maintenanceMode = 1;
|
||||
request(nconf.get('url') + '/api/recent', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/recent', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -438,7 +437,7 @@ describe('Admin Controllers', function () {
|
||||
|
||||
|
||||
it('should load /posts/flags', function (done) {
|
||||
request(nconf.get('url') + '/api/posts/flags', {jar: jar, json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/posts/flags', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
|
||||
@@ -13,7 +13,6 @@ var meta = require('../src/meta');
|
||||
|
||||
|
||||
describe('Controllers', function () {
|
||||
|
||||
var tid;
|
||||
var cid;
|
||||
var pid;
|
||||
@@ -24,18 +23,18 @@ describe('Controllers', function () {
|
||||
category: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
user: function (next) {
|
||||
user.create({username: 'foo', password: 'barbar'}, next);
|
||||
user.create({ username: 'foo', password: 'barbar' }, next);
|
||||
},
|
||||
navigation: function (next) {
|
||||
var navigation = require('../src/navigation/admin');
|
||||
var data = require('../install/data/navigation.json');
|
||||
|
||||
navigation.save(data, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -43,7 +42,7 @@ describe('Controllers', function () {
|
||||
cid = results.category.cid;
|
||||
fooUid = results.user;
|
||||
|
||||
topics.post({uid: results.user, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
|
||||
topics.post({ uid: results.user, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) {
|
||||
tid = result.topicData.tid;
|
||||
pid = result.postData.pid;
|
||||
done(err);
|
||||
@@ -52,7 +51,6 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should load default home route', function (done) {
|
||||
request(nconf.get('url'), function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
@@ -444,7 +442,7 @@ describe('Controllers', function () {
|
||||
groups.create({
|
||||
name: 'group-details',
|
||||
description: 'Foobar!',
|
||||
hidden: 0
|
||||
hidden: 0,
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
request(nconf.get('url') + '/groups/group-details', function (err, res, body) {
|
||||
@@ -470,7 +468,7 @@ describe('Controllers', function () {
|
||||
groups.create({
|
||||
name: 'hidden-group',
|
||||
description: 'Foobar!',
|
||||
hidden: 1
|
||||
hidden: 1,
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
request(nconf.get('url') + '/groups/hidden-group/members', function (err, res, body) {
|
||||
@@ -515,7 +513,7 @@ describe('Controllers', function () {
|
||||
var csrf_token;
|
||||
var helpers = require('./helpers');
|
||||
before(function (done) {
|
||||
user.create({username: 'revokeme', password: 'barbar'}, function (err, _uid) {
|
||||
user.create({ username: 'revokeme', password: 'barbar' }, function (err, _uid) {
|
||||
assert.ifError(err);
|
||||
uid = _uid;
|
||||
helpers.loginUser('revokeme', 'barbar', function (err, _jar, io, _csrf_token) {
|
||||
@@ -531,8 +529,8 @@ describe('Controllers', function () {
|
||||
request.del(nconf.get('url') + '/api/user/revokeme/session', {
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': csrf_token
|
||||
}
|
||||
'x-csrf-token': csrf_token,
|
||||
},
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
@@ -544,8 +542,8 @@ describe('Controllers', function () {
|
||||
request.del(nconf.get('url') + '/api/user/doesnotexist/session/1112233', {
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': csrf_token
|
||||
}
|
||||
'x-csrf-token': csrf_token,
|
||||
},
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 403);
|
||||
@@ -564,8 +562,8 @@ describe('Controllers', function () {
|
||||
request.del(nconf.get('url') + '/api/user/revokeme/session/' + sessionObj.meta.uuid, {
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': csrf_token
|
||||
}
|
||||
'x-csrf-token': csrf_token,
|
||||
},
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
@@ -592,25 +590,25 @@ describe('Controllers', function () {
|
||||
widgets: [
|
||||
{
|
||||
widget: 'html',
|
||||
data: [ {
|
||||
data: [{
|
||||
widget: 'html',
|
||||
data: {
|
||||
html: 'test',
|
||||
title: '',
|
||||
container: ''
|
||||
}
|
||||
} ]
|
||||
}
|
||||
]
|
||||
container: '',
|
||||
},
|
||||
}],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
widgets.setArea(data, next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should return {} if there is no template or locations', function (done) {
|
||||
request(nconf.get('url') + '/api/widgets/render', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/widgets/render', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -621,7 +619,7 @@ describe('Controllers', function () {
|
||||
|
||||
it('should render templates', function (done) {
|
||||
var url = nconf.get('url') + '/api/widgets/render?template=categories.tpl&url=&isMobile=false&locations%5B%5D=sidebar&locations%5B%5D=footer&locations%5B%5D=header';
|
||||
request(url, {json: true}, function (err, res, body) {
|
||||
request(url, { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -638,7 +636,7 @@ describe('Controllers', function () {
|
||||
title: 'topic title',
|
||||
content: 'test topic content',
|
||||
cid: cid,
|
||||
tags: ['nodebb', 'bug', 'test']
|
||||
tags: ['nodebb', 'bug', 'test'],
|
||||
}, function (err, result) {
|
||||
assert.ifError(err);
|
||||
tid = result.topicData.tid;
|
||||
@@ -647,7 +645,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should render tags page', function (done) {
|
||||
request(nconf.get('url') + '/api/tags', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/tags', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -657,7 +655,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should render tag page with no topics', function (done) {
|
||||
request(nconf.get('url') + '/api/tags/notag', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/tags/notag', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -668,7 +666,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should render tag page with 1 topic', function (done) {
|
||||
request(nconf.get('url') + '/api/tags/nodebb', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/tags/nodebb', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -681,7 +679,6 @@ describe('Controllers', function () {
|
||||
|
||||
|
||||
describe('maintenance mode', function () {
|
||||
|
||||
before(function (done) {
|
||||
meta.config.maintenanceMode = 1;
|
||||
done();
|
||||
@@ -692,7 +689,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should return 503 in maintenance mode', function (done) {
|
||||
request(nconf.get('url') + '/recent', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/recent', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 503);
|
||||
done();
|
||||
@@ -700,7 +697,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should return 503 in maintenance mode', function (done) {
|
||||
request(nconf.get('url') + '/api/recent', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/recent', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 503);
|
||||
assert(body);
|
||||
@@ -709,7 +706,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should return 200 in maintenance mode', function (done) {
|
||||
request(nconf.get('url') + '/api/login', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/login', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -748,7 +745,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /user/foo/bookmarks', function (done) {
|
||||
request(nconf.get('url') + '/api/user/foo/bookmarks', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/bookmarks', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -757,7 +754,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /user/foo/upvoted', function (done) {
|
||||
request(nconf.get('url') + '/api/user/foo/upvoted', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/upvoted', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -766,7 +763,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /user/foo/downvoted', function (done) {
|
||||
request(nconf.get('url') + '/api/user/foo/downvoted', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/downvoted', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -784,7 +781,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /user/foo/watched', function (done) {
|
||||
request(nconf.get('url') + '/api/user/foo/watched', {jar: jar}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/watched', { jar: jar }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
@@ -812,7 +809,7 @@ describe('Controllers', function () {
|
||||
tid: 1,
|
||||
from: fooUid,
|
||||
mergeId: 'notifications:user_posted_to|' + 1,
|
||||
topicTitle: 'topic title'
|
||||
topicTitle: 'topic title',
|
||||
};
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -825,7 +822,7 @@ describe('Controllers', function () {
|
||||
setTimeout(next, 2500);
|
||||
},
|
||||
function (next) {
|
||||
request(nconf.get('url') + '/api/notifications', {jar: jar, json: true}, next);
|
||||
request(nconf.get('url') + '/api/notifications', { jar: jar, json: true }, next);
|
||||
},
|
||||
function (res, body, next) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
@@ -837,7 +834,7 @@ describe('Controllers', function () {
|
||||
assert.equal(notif.path, notifData.path);
|
||||
assert.equal(notif.nid, notifData.nid);
|
||||
next();
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
});
|
||||
@@ -846,12 +843,12 @@ describe('Controllers', function () {
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
var uid;
|
||||
before(function (done) {
|
||||
user.create({username: 'follower'}, function (err, _uid) {
|
||||
user.create({ username: 'follower' }, function (err, _uid) {
|
||||
assert.ifError(err);
|
||||
uid = _uid;
|
||||
socketUser.follow({uid: uid}, {uid: fooUid}, function (err) {
|
||||
socketUser.follow({ uid: uid }, { uid: fooUid }, function (err) {
|
||||
assert.ifError(err);
|
||||
socketUser.isFollowing({uid: uid}, {uid: fooUid}, function (err, isFollowing) {
|
||||
socketUser.isFollowing({ uid: uid }, { uid: fooUid }, function (err, isFollowing) {
|
||||
assert.ifError(err);
|
||||
assert(isFollowing);
|
||||
done();
|
||||
@@ -861,7 +858,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should get followers page', function (done) {
|
||||
request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/followers', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(body.users[0].username, 'follower');
|
||||
@@ -870,7 +867,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
|
||||
it('should get following page', function (done) {
|
||||
request(nconf.get('url') + '/api/user/follower/following', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/follower/following', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(body.users[0].username, 'foo');
|
||||
@@ -878,10 +875,10 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty after unfollow', function (done ) {
|
||||
socketUser.unfollow({uid: uid}, {uid: fooUid}, function (err) {
|
||||
it('should return empty after unfollow', function (done) {
|
||||
socketUser.unfollow({ uid: uid }, { uid: fooUid }, function (err) {
|
||||
assert.ifError(err);
|
||||
request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {
|
||||
request(nconf.get('url') + '/api/user/foo/followers', { json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(body.users.length, 0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var db = require('./mocks/databasemock');
|
||||
@@ -25,5 +25,4 @@ describe('Test database', function () {
|
||||
require('./database/sets');
|
||||
require('./database/hash');
|
||||
require('./database/sorted');
|
||||
|
||||
});
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
var async = require('async'),
|
||||
assert = require('assert'),
|
||||
db = require('../mocks/databasemock');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var db = require('../mocks/databasemock');
|
||||
|
||||
describe('Hash methods', function () {
|
||||
var testData = {
|
||||
name: 'baris',
|
||||
lastname: 'usakli',
|
||||
age: 99
|
||||
age: 99,
|
||||
};
|
||||
|
||||
beforeEach(function (done) {
|
||||
@@ -18,7 +18,7 @@ describe('Hash methods', function () {
|
||||
|
||||
describe('setObject()', function () {
|
||||
it('should create a object', function (done) {
|
||||
db.setObject('testObject1', {foo: 'baris', bar: 99}, function (err) {
|
||||
db.setObject('testObject1', { foo: 'baris', bar: 99 }, function (err) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 1);
|
||||
done();
|
||||
@@ -26,7 +26,7 @@ describe('Hash methods', function () {
|
||||
});
|
||||
|
||||
it('should do nothing if key is falsy', function (done) {
|
||||
db.setObject('', {foo: 1, derp: 2}, function (err) {
|
||||
db.setObject('', { foo: 1, derp: 2 }, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -86,8 +86,8 @@ describe('Hash methods', function () {
|
||||
describe('getObjects()', function () {
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
async.apply(db.setObject, 'testObject4', {name: 'baris'}),
|
||||
async.apply(db.setObjectField, 'testObject5', 'name', 'ginger')
|
||||
async.apply(db.setObject, 'testObject4', { name: 'baris' }),
|
||||
async.apply(db.setObjectField, 'testObject5', 'name', 'ginger'),
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -161,8 +161,8 @@ describe('Hash methods', function () {
|
||||
describe('getObjectsFields()', function () {
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
async.apply(db.setObject, 'testObject8', {name: 'baris', age:99}),
|
||||
async.apply(db.setObject, 'testObject9', {name: 'ginger', age: 3})
|
||||
async.apply(db.setObject, 'testObject8', { name: 'baris', age: 99 }),
|
||||
async.apply(db.setObject, 'testObject9', { name: 'ginger', age: 3 }),
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -278,7 +278,7 @@ describe('Hash methods', function () {
|
||||
|
||||
describe('deleteObjectField()', function () {
|
||||
before(function (done) {
|
||||
db.setObject('testObject10', {foo: 'bar', delete: 'this', delete1: 'this', delete2: 'this'}, done);
|
||||
db.setObject('testObject10', { foo: 'bar', delete: 'this', delete1: 'this', delete2: 'this' }, done);
|
||||
});
|
||||
|
||||
it('should delete an objects field', function (done) {
|
||||
@@ -299,7 +299,7 @@ describe('Hash methods', function () {
|
||||
assert.equal(arguments.length, 1);
|
||||
async.parallel({
|
||||
delete1: async.apply(db.isObjectField, 'testObject10', 'delete1'),
|
||||
delete2: async.apply(db.isObjectField, 'testObject10', 'delete2')
|
||||
delete2: async.apply(db.isObjectField, 'testObject10', 'delete2'),
|
||||
}, function (err, results) {
|
||||
assert.ifError(err);
|
||||
assert.equal(results.delete1, false);
|
||||
@@ -312,7 +312,7 @@ describe('Hash methods', function () {
|
||||
|
||||
describe('incrObjectField()', function () {
|
||||
before(function (done) {
|
||||
db.setObject('testObject11', {age: 99}, done);
|
||||
db.setObject('testObject11', { age: 99 }, done);
|
||||
});
|
||||
|
||||
it('should set an objects field to 1 if object does not exist', function (done) {
|
||||
@@ -336,7 +336,7 @@ describe('Hash methods', function () {
|
||||
|
||||
describe('decrObjectField()', function () {
|
||||
before(function (done) {
|
||||
db.setObject('testObject13', {age: 99}, done);
|
||||
db.setObject('testObject13', { age: 99 }, done);
|
||||
});
|
||||
|
||||
it('should set an objects field to -1 if object does not exist', function (done) {
|
||||
@@ -360,7 +360,7 @@ describe('Hash methods', function () {
|
||||
|
||||
describe('incrObjectFieldBy()', function () {
|
||||
before(function (done) {
|
||||
db.setObject('testObject15', {age: 100}, done);
|
||||
db.setObject('testObject15', { age: 100 }, done);
|
||||
});
|
||||
|
||||
it('should set an objects field to 5 if object does not exist', function (done) {
|
||||
@@ -391,7 +391,6 @@ describe('Hash methods', function () {
|
||||
});
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
/*global require, after*/
|
||||
|
||||
var async = require('async'),
|
||||
assert = require('assert'),
|
||||
db = require('../mocks/databasemock');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var db = require('../mocks/databasemock');
|
||||
|
||||
describe('Key methods', function () {
|
||||
|
||||
beforeEach(function (done) {
|
||||
db.set('testKey', 'testValue', done);
|
||||
});
|
||||
@@ -78,7 +77,7 @@ describe('Key methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.set('key2', 'value2', next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -92,7 +91,7 @@ describe('Key methods', function () {
|
||||
},
|
||||
key2exists: function (next) {
|
||||
db.exists('key2', next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(results.key1exists, false);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
var async = require('async'),
|
||||
assert = require('assert'),
|
||||
db = require('../mocks/databasemock');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var db = require('../mocks/databasemock');
|
||||
|
||||
describe('List methods', function () {
|
||||
|
||||
describe('listAppend()', function () {
|
||||
it('should append to a list', function (done) {
|
||||
db.listAppend('testList1', 5, function (err) {
|
||||
@@ -33,7 +32,7 @@ describe('List methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.listPrepend('testList2', 1, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
assert.equal(err, null);
|
||||
done();
|
||||
@@ -52,7 +51,7 @@ describe('List methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.listAppend('testList4', 5, next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -94,7 +93,7 @@ describe('List methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.listPrepend('testList4', 9, next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -115,7 +114,7 @@ describe('List methods', function () {
|
||||
async.apply(db.listAppend, 'testList5', 1),
|
||||
async.apply(db.listAppend, 'testList5', 1),
|
||||
async.apply(db.listAppend, 'testList5', 2),
|
||||
async.apply(db.listAppend, 'testList5', 5)
|
||||
async.apply(db.listAppend, 'testList5', 5),
|
||||
], done);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
var async = require('async'),
|
||||
assert = require('assert'),
|
||||
db = require('../mocks/databasemock');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var db = require('../mocks/databasemock');
|
||||
|
||||
describe('Set methods', function () {
|
||||
|
||||
describe('setAdd()', function () {
|
||||
it('should add to a set', function (done) {
|
||||
db.setAdd('testSet1', 5, function (err) {
|
||||
@@ -27,7 +26,7 @@ describe('Set methods', function () {
|
||||
|
||||
describe('getSetMembers()', function () {
|
||||
before(function (done) {
|
||||
db.setAdd('testSet2', [1,2,3,4,5], done);
|
||||
db.setAdd('testSet2', [1, 2, 3, 4, 5], done);
|
||||
});
|
||||
|
||||
it('should return an empty set', function (done) {
|
||||
@@ -139,7 +138,7 @@ describe('Set methods', function () {
|
||||
|
||||
describe('setCount()', function () {
|
||||
before(function (done) {
|
||||
db.setAdd('testSet5', [1,2,3,4,5], done);
|
||||
db.setAdd('testSet5', [1, 2, 3, 4, 5], done);
|
||||
});
|
||||
|
||||
it('should return the element count of set', function (done) {
|
||||
@@ -155,9 +154,9 @@ describe('Set methods', function () {
|
||||
describe('setsCount()', function () {
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
async.apply(db.setAdd, 'set5', [1,2,3,4,5]),
|
||||
async.apply(db.setAdd, 'set5', [1, 2, 3, 4, 5]),
|
||||
async.apply(db.setAdd, 'set6', 1),
|
||||
async.apply(db.setAdd, 'set7', 2)
|
||||
async.apply(db.setAdd, 'set7', 2),
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -211,7 +210,7 @@ describe('Set methods', function () {
|
||||
|
||||
describe('setRemoveRandom()', function () {
|
||||
before(function (done) {
|
||||
db.setAdd('testSet7', [1,2,3,4,5], done);
|
||||
db.setAdd('testSet7', [1, 2, 3, 4, 5], done);
|
||||
});
|
||||
|
||||
it('should remove a random element from set', function (done) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
var async = require('async'),
|
||||
assert = require('assert'),
|
||||
db = require('../mocks/databasemock');
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var db = require('../mocks/databasemock');
|
||||
|
||||
describe('Sorted Set methods', function () {
|
||||
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
function (next) {
|
||||
@@ -20,7 +19,7 @@ describe('Sorted Set methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('sortedSetLex', [0, 0, 0, 0], ['a', 'b', 'c', 'd'], next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -97,7 +96,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, [{value: 'value1', score: 1.1}, {value: 'value2', score: 1.2}, {value: 'value3', score: 1.3}]);
|
||||
assert.deepEqual(values, [{ value: 'value1', score: 1.1 }, { value: 'value2', score: 1.2 }, { value: 'value3', score: 1.3 }]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -108,7 +107,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, [{value: 'value3', score: 1.3}, {value: 'value2', score: 1.2}, {value: 'value1', score: 1.1}]);
|
||||
assert.deepEqual(values, [{ value: 'value3', score: 1.3 }, { value: 'value2', score: 1.2 }, { value: 'value1', score: 1.1 }]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -141,7 +140,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 1.2, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, [{value: 'value1', score: 1.1}, {value: 'value2', score: 1.2}]);
|
||||
assert.deepEqual(values, [{ value: 'value1', score: 1.1 }, { value: 'value2', score: 1.2 }]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -152,7 +151,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 1.2, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, [{value: 'value3', score: 1.3}, {value: 'value2', score: 1.2}]);
|
||||
assert.deepEqual(values, [{ value: 'value3', score: 1.3 }, { value: 'value2', score: 1.2 }]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -451,7 +450,7 @@ describe('Sorted Set methods', function () {
|
||||
|
||||
describe('getSortedSetUnion()', function () {
|
||||
it('should return an array of values from both sorted sets sorted by scores lowest to highest', function (done) {
|
||||
db.getSortedSetUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function (err, values) {
|
||||
db.getSortedSetUnion({ sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1 }, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, ['value1', 'value2', 'value4']);
|
||||
@@ -462,7 +461,7 @@ describe('Sorted Set methods', function () {
|
||||
|
||||
describe('getSortedSetRevUnion()', function () {
|
||||
it('should return an array of values from both sorted sets sorted by scores highest to lowest', function (done) {
|
||||
db.getSortedSetRevUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function (err, values) {
|
||||
db.getSortedSetRevUnion({ sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1 }, function (err, values) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(arguments.length, 2);
|
||||
assert.deepEqual(values, ['value4', 'value2', 'value1']);
|
||||
@@ -521,8 +520,8 @@ describe('Sorted Set methods', function () {
|
||||
describe('sortedSetsRemove()', function () {
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetAdd, 'sorted4', [1,2], ['value1', 'value2']),
|
||||
async.apply(db.sortedSetAdd, 'sorted5', [1,2], ['value1', 'value3']),
|
||||
async.apply(db.sortedSetAdd, 'sorted4', [1, 2], ['value1', 'value2']),
|
||||
async.apply(db.sortedSetAdd, 'sorted5', [1, 2], ['value1', 'value3']),
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -541,7 +540,7 @@ describe('Sorted Set methods', function () {
|
||||
|
||||
describe('sortedSetsRemoveRangeByScore()', function () {
|
||||
before(function (done) {
|
||||
db.sortedSetAdd('sorted6', [1,2,3,4,5], ['value1','value2','value3','value4','value5'], done);
|
||||
db.sortedSetAdd('sorted6', [1, 2, 3, 4, 5], ['value1', 'value2', 'value3', 'value4', 'value5'], done);
|
||||
});
|
||||
|
||||
it('should remove elements with scores between min max inclusive', function (done) {
|
||||
@@ -561,11 +560,11 @@ describe('Sorted Set methods', function () {
|
||||
before(function (done) {
|
||||
async.parallel([
|
||||
function (next) {
|
||||
db.sortedSetAdd('interSet1', [1,2,3], ['value1', 'value2', 'value3'], next);
|
||||
db.sortedSetAdd('interSet1', [1, 2, 3], ['value1', 'value2', 'value3'], next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('interSet2', [4,5,6], ['value2', 'value3', 'value5'], next);
|
||||
}
|
||||
db.sortedSetAdd('interSet2', [4, 5, 6], ['value2', 'value3', 'value5'], next);
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -573,7 +572,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetIntersect({
|
||||
sets: ['interSet1', 'interSet2'],
|
||||
start: 0,
|
||||
stop: -1
|
||||
stop: -1,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(['value2', 'value3'], data);
|
||||
@@ -586,10 +585,10 @@ describe('Sorted Set methods', function () {
|
||||
sets: ['interSet1', 'interSet2'],
|
||||
start: 0,
|
||||
stop: -1,
|
||||
withScores: true
|
||||
withScores: true,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([{value: 'value2', score: 6}, {value: 'value3', score: 8}], data);
|
||||
assert.deepEqual([{ value: 'value2', score: 6 }, { value: 'value3', score: 8 }], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -600,10 +599,10 @@ describe('Sorted Set methods', function () {
|
||||
start: 0,
|
||||
stop: -1,
|
||||
withScores: true,
|
||||
aggregate: 'MIN'
|
||||
aggregate: 'MIN',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([{value: 'value2', score: 2}, {value: 'value3', score: 3}], data);
|
||||
assert.deepEqual([{ value: 'value2', score: 2 }, { value: 'value3', score: 3 }], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -614,10 +613,10 @@ describe('Sorted Set methods', function () {
|
||||
start: 0,
|
||||
stop: -1,
|
||||
withScores: true,
|
||||
aggregate: 'MAX'
|
||||
aggregate: 'MAX',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([{value: 'value2', score: 4}, {value: 'value3', score: 5}], data);
|
||||
assert.deepEqual([{ value: 'value2', score: 4 }, { value: 'value3', score: 5 }], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -628,10 +627,10 @@ describe('Sorted Set methods', function () {
|
||||
start: 0,
|
||||
stop: -1,
|
||||
withScores: true,
|
||||
weights: [1, 0.5]
|
||||
weights: [1, 0.5],
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([{value: 'value2', score: 4}, {value: 'value3', score: 5.5}], data);
|
||||
assert.deepEqual([{ value: 'value2', score: 4 }, { value: 'value3', score: 5.5 }], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -640,7 +639,7 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetIntersect({
|
||||
sets: ['interSet10', 'interSet12'],
|
||||
start: 0,
|
||||
stop: -1
|
||||
stop: -1,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.length, 0);
|
||||
@@ -652,14 +651,13 @@ describe('Sorted Set methods', function () {
|
||||
db.getSortedSetIntersect({
|
||||
sets: ['interSet1', 'interSet12'],
|
||||
start: 0,
|
||||
stop: -1
|
||||
stop: -1,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('sortedSetIntersectCard', function () {
|
||||
@@ -676,7 +674,7 @@ describe('Sorted Set methods', function () {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetAdd('interCard4', [0, 0, 0], ['value4', 'value5', 'value6'], next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
|
||||
445
test/groups.js
445
test/groups.js
File diff suppressed because one or more lines are too long
@@ -14,7 +14,7 @@ helpers.loginUser = function (username, password, callback) {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, res, body) {
|
||||
if (err || res.statusCode !== 200) {
|
||||
return callback(err || new Error('[[error:invalid-response]]'));
|
||||
@@ -28,8 +28,8 @@ helpers.loginUser = function (username, password, callback) {
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
}
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
}, function (err, res) {
|
||||
if (err || res.statusCode !== 200) {
|
||||
return callback(err || new Error('[[error:invalid-response]]'));
|
||||
@@ -46,7 +46,7 @@ helpers.loginUser = function (username, password, callback) {
|
||||
|
||||
var socketClient = require('socket.io-client');
|
||||
|
||||
var io = socketClient.connect(nconf.get('url'), {forceNew: true, multiplex: false});
|
||||
var io = socketClient.connect(nconf.get('url'), { forceNew: true, multiplex: false });
|
||||
io.on('connect', function () {
|
||||
callback(null, jar, io, body.csrf_token);
|
||||
});
|
||||
@@ -63,7 +63,7 @@ helpers.initSocketIO = function (callback) {
|
||||
request.get({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
jar: jar,
|
||||
json: true
|
||||
json: true,
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -79,7 +79,7 @@ helpers.initSocketIO = function (callback) {
|
||||
};
|
||||
};
|
||||
|
||||
var io = require('socket.io-client')(nconf.get('url'), {forceNew: true});
|
||||
var io = require('socket.io-client')(nconf.get('url'), { forceNew: true });
|
||||
|
||||
io.on('connect', function () {
|
||||
callback(null, jar, io);
|
||||
@@ -96,8 +96,8 @@ helpers.uploadFile = function (uploadEndPoint, filePath, body, jar, csrf_token,
|
||||
var formData = {
|
||||
files: [
|
||||
fs.createReadStream(filePath),
|
||||
fs.createReadStream(filePath) // see https://github.com/request/request/issues/2445
|
||||
]
|
||||
fs.createReadStream(filePath), // see https://github.com/request/request/issues/2445
|
||||
],
|
||||
};
|
||||
formData = utils.merge(formData, body);
|
||||
request.post({
|
||||
@@ -106,8 +106,8 @@ helpers.uploadFile = function (uploadEndPoint, filePath, body, jar, csrf_token,
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': csrf_token
|
||||
}
|
||||
'x-csrf-token': csrf_token,
|
||||
},
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -121,7 +121,7 @@ helpers.registerUser = function (data, callback) {
|
||||
request({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
json: true,
|
||||
jar: jar
|
||||
jar: jar,
|
||||
}, function (err, response, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -132,8 +132,8 @@ helpers.registerUser = function (data, callback) {
|
||||
json: true,
|
||||
jar: jar,
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
}
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -144,20 +144,19 @@ helpers.registerUser = function (data, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
//http://stackoverflow.com/a/14387791/583363
|
||||
// http://stackoverflow.com/a/14387791/583363
|
||||
helpers.copyFile = function (source, target, callback) {
|
||||
|
||||
var cbCalled = false;
|
||||
|
||||
var rd = fs.createReadStream(source);
|
||||
rd.on("error", function (err) {
|
||||
rd.on('error', function (err) {
|
||||
done(err);
|
||||
});
|
||||
var wr = fs.createWriteStream(target);
|
||||
wr.on("error", function (err) {
|
||||
wr.on('error', function (err) {
|
||||
done(err);
|
||||
});
|
||||
wr.on("close", function () {
|
||||
wr.on('close', function () {
|
||||
done();
|
||||
});
|
||||
rd.pipe(wr);
|
||||
@@ -168,4 +167,4 @@ helpers.copyFile = function (source, target, callback) {
|
||||
cbCalled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('Messaging Library', function () {
|
||||
async.series([
|
||||
async.apply(User.create, { username: 'foo', password: 'barbar' }), // admin
|
||||
async.apply(User.create, { username: 'baz', password: 'quuxquux' }), // restricted user
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }) // regular user
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }), // regular user
|
||||
], function (err, uids) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -37,7 +37,7 @@ describe('Messaging Library', function () {
|
||||
|
||||
async.parallel([
|
||||
async.apply(Groups.join, 'administrators', fooUid),
|
||||
async.apply(User.setSetting, bazUid, 'restrictChat', '1')
|
||||
async.apply(User.setSetting, bazUid, 'restrictChat', '1'),
|
||||
], done);
|
||||
});
|
||||
});
|
||||
@@ -80,7 +80,7 @@ describe('Messaging Library', function () {
|
||||
describe('rooms', function () {
|
||||
var socketModules = require('../src/socket.io/modules');
|
||||
it('should create a new chat room', function (done) {
|
||||
socketModules.chats.newRoom({uid: fooUid}, {touid: bazUid}, function (err, _roomId) {
|
||||
socketModules.chats.newRoom({ uid: fooUid }, { touid: bazUid }, function (err, _roomId) {
|
||||
roomId = _roomId;
|
||||
assert.ifError(err);
|
||||
assert(roomId);
|
||||
@@ -89,14 +89,14 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should add a user to room', function (done) {
|
||||
socketModules.chats.addUserToRoom({uid: fooUid}, {roomId: roomId, username: 'herp'}, function (err) {
|
||||
socketModules.chats.addUserToRoom({ uid: fooUid }, { roomId: roomId, username: 'herp' }, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should leave the chat room', function (done) {
|
||||
socketModules.chats.leave({uid: bazUid}, roomId, function (err) {
|
||||
socketModules.chats.leave({ uid: bazUid }, roomId, function (err) {
|
||||
assert.ifError(err);
|
||||
Messaging.isUserInRoom(bazUid, roomId, function (err, isUserInRoom) {
|
||||
assert.ifError(err);
|
||||
@@ -107,13 +107,13 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should send a message to a room', function (done) {
|
||||
socketModules.chats.send({uid: fooUid}, {roomId: roomId, message: 'first chat message'}, function (err, messageData) {
|
||||
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: 'first chat message' }, function (err, messageData) {
|
||||
assert.ifError(err);
|
||||
assert(messageData);
|
||||
assert.equal(messageData.content, 'first chat message');
|
||||
assert(messageData.fromUser);
|
||||
assert(messageData.roomId, roomId);
|
||||
socketModules.chats.getRaw({uid: fooUid}, {roomId: roomId, mid: messageData.mid}, function (err, raw) {
|
||||
socketModules.chats.getRaw({ uid: fooUid }, { roomId: roomId, mid: messageData.mid }, function (err, raw) {
|
||||
assert.ifError(err);
|
||||
assert.equal(raw, 'first chat message');
|
||||
done();
|
||||
@@ -126,7 +126,7 @@ describe('Messaging Library', function () {
|
||||
|
||||
db.sortedSetAdd('users:online', Date.now() - 350000, herpUid, function (err) {
|
||||
assert.ifError(err);
|
||||
socketModules.chats.send({uid: fooUid}, {roomId: roomId, message: 'second chat message'}, function (err) {
|
||||
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: 'second chat message' }, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
User.notifications.get(herpUid, function (err, data) {
|
||||
@@ -144,10 +144,10 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should get messages from room', function (done) {
|
||||
socketModules.chats.getMessages({uid: fooUid}, {
|
||||
socketModules.chats.getMessages({ uid: fooUid }, {
|
||||
uid: fooUid,
|
||||
roomId: roomId,
|
||||
start: 0
|
||||
start: 0,
|
||||
}, function (err, messages) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(messages));
|
||||
@@ -158,21 +158,21 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should mark room read', function (done) {
|
||||
socketModules.chats.markRead({uid: fooUid}, roomId, function (err) {
|
||||
socketModules.chats.markRead({ uid: fooUid }, roomId, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark all rooms read', function (done) {
|
||||
socketModules.chats.markAllRead({uid: fooUid}, {}, function (err) {
|
||||
socketModules.chats.markAllRead({ uid: fooUid }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should rename room', function (done) {
|
||||
socketModules.chats.renameRoom({uid: fooUid}, {roomId: roomId, newName: 'new room name'}, function (err) {
|
||||
socketModules.chats.renameRoom({ uid: fooUid }, { roomId: roomId, newName: 'new room name' }, function (err) {
|
||||
assert.ifError(err);
|
||||
|
||||
done();
|
||||
@@ -180,7 +180,7 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should load chat room', function (done) {
|
||||
socketModules.chats.loadRoom({uid: fooUid}, {roomId: roomId}, function (err, data) {
|
||||
socketModules.chats.loadRoom({ uid: fooUid }, { roomId: roomId }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
assert.equal(data.roomName, 'new room name');
|
||||
@@ -193,7 +193,7 @@ describe('Messaging Library', function () {
|
||||
var socketModules = require('../src/socket.io/modules');
|
||||
var mid;
|
||||
before(function (done) {
|
||||
socketModules.chats.send({uid: fooUid}, {roomId: roomId, message: 'first chat message'}, function (err, messageData) {
|
||||
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: 'first chat message' }, function (err, messageData) {
|
||||
assert.ifError(err);
|
||||
mid = messageData.mid;
|
||||
done();
|
||||
@@ -201,9 +201,9 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should edit message', function (done) {
|
||||
socketModules.chats.edit({uid: fooUid}, {mid: mid, roomId: roomId, message: 'message edited'}, function (err) {
|
||||
socketModules.chats.edit({ uid: fooUid }, { mid: mid, roomId: roomId, message: 'message edited' }, function (err) {
|
||||
assert.ifError(err);
|
||||
socketModules.chats.getRaw({uid: fooUid}, {roomId: roomId, mid: mid}, function (err, raw) {
|
||||
socketModules.chats.getRaw({ uid: fooUid }, { roomId: roomId, mid: mid }, function (err, raw) {
|
||||
assert.ifError(err);
|
||||
assert.equal(raw, 'message edited');
|
||||
done();
|
||||
@@ -212,7 +212,7 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should delete message', function (done) {
|
||||
socketModules.chats.delete({uid: fooUid}, {messageId: mid, roomId: roomId}, function (err) {
|
||||
socketModules.chats.delete({ uid: fooUid }, { messageId: mid, roomId: roomId }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.exists('message:' + mid, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
@@ -249,7 +249,6 @@ describe('Messaging Library', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('logged in chat controller', function () {
|
||||
@@ -263,7 +262,7 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should return chats page data', function (done) {
|
||||
request(nconf.get('url') + '/api/user/herp/chats', {json: true, jar: jar}, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/user/herp/chats', { json: true, jar: jar }, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert(Array.isArray(body.rooms));
|
||||
@@ -274,7 +273,7 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should return room data', function (done) {
|
||||
request(nconf.get('url') + '/api/user/herp/chats/' + roomId, {json: true, jar: jar}, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/user/herp/chats/' + roomId, { json: true, jar: jar }, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(body.roomId, roomId);
|
||||
@@ -284,7 +283,7 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
|
||||
it('should redirect to chats page', function (done) {
|
||||
request(nconf.get('url') + '/api/chats', {jar: jar}, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/chats', { jar: jar }, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(body, '"/user/herp/chats"');
|
||||
assert.equal(response.statusCode, 308);
|
||||
@@ -295,7 +294,7 @@ describe('Messaging Library', function () {
|
||||
it('should return 404 if user is not in room', function (done) {
|
||||
helpers.loginUser('baz', 'quuxquux', function (err, jar) {
|
||||
assert.ifError(err);
|
||||
request(nconf.get('url') + '/api/user/baz/chats/' + roomId, {json: true, jar: jar}, function (err, response, body) {
|
||||
request(nconf.get('url') + '/api/user/baz/chats/' + roomId, { json: true, jar: jar }, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.statusCode, 404);
|
||||
done();
|
||||
|
||||
29
test/meta.js
29
test/meta.js
@@ -19,7 +19,7 @@ describe('meta', function () {
|
||||
async.series([
|
||||
async.apply(User.create, { username: 'foo', password: 'barbar' }), // admin
|
||||
async.apply(User.create, { username: 'baz', password: 'quuxquux' }), // restricted user
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }) // regular user
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }), // regular user
|
||||
], function (err, uids) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -36,7 +36,7 @@ describe('meta', function () {
|
||||
describe('settings', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
it('it should set setting', function (done) {
|
||||
socketAdmin.settings.set({uid: fooUid}, {hash: 'some:hash', values: {foo: '1', derp: 'value'}}, function (err) {
|
||||
socketAdmin.settings.set({ uid: fooUid }, { hash: 'some:hash', values: { foo: '1', derp: 'value' } }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
@@ -48,7 +48,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('it should get setting', function (done) {
|
||||
socketAdmin.settings.get({uid: fooUid}, {hash: 'some:hash'}, function (err, data) {
|
||||
socketAdmin.settings.get({ uid: fooUid }, { hash: 'some:hash' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, '1');
|
||||
assert.equal(data.derp, 'value');
|
||||
@@ -57,7 +57,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should not set setting if not empty', function (done) {
|
||||
meta.settings.setOnEmpty('some:hash', {foo: 2}, function (err) {
|
||||
meta.settings.setOnEmpty('some:hash', { foo: 2 }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
@@ -69,7 +69,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should set setting if empty', function (done) {
|
||||
meta.settings.setOnEmpty('some:hash', {empty: '2'}, function (err) {
|
||||
meta.settings.setOnEmpty('some:hash', { empty: '2' }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObject('settings:some:hash', function (err, data) {
|
||||
assert.ifError(err);
|
||||
@@ -91,14 +91,13 @@ describe('meta', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('config', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
before(function (done) {
|
||||
db.setObject('config', {minimumTagLength: 3, maximumTagLength: 15}, done);
|
||||
db.setObject('config', { minimumTagLength: 3, maximumTagLength: 15 }, done);
|
||||
});
|
||||
|
||||
it('should get config fields', function (done) {
|
||||
@@ -118,7 +117,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should fail if data is invalid', function (done) {
|
||||
socketAdmin.config.set({uid: fooUid}, null, function (err) {
|
||||
socketAdmin.config.set({ uid: fooUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
@@ -136,17 +135,17 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should fail if data is invalid', function (done) {
|
||||
socketAdmin.config.setMultiple({uid: fooUid}, null, function (err) {
|
||||
socketAdmin.config.setMultiple({ uid: fooUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should set multiple values', function (done ) {
|
||||
socketAdmin.config.setMultiple({uid: fooUid}, {
|
||||
it('should set multiple values', function (done) {
|
||||
socketAdmin.config.setMultiple({ uid: fooUid }, {
|
||||
someField1: 'someValue1',
|
||||
someField2: 'someValue2',
|
||||
customCSS: '.derp{color:#00ff00;}'
|
||||
customCSS: '.derp{color:#00ff00;}',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
meta.configs.getFields(['someField1', 'someField2'], function (err, data) {
|
||||
@@ -159,7 +158,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should not set config if not empty', function (done) {
|
||||
meta.configs.setOnEmpty({someField1: 'foo'}, function (err) {
|
||||
meta.configs.setOnEmpty({ someField1: 'foo' }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.getObjectField('config', 'someField1', function (err, value) {
|
||||
assert.ifError(err);
|
||||
@@ -170,7 +169,7 @@ describe('meta', function () {
|
||||
});
|
||||
|
||||
it('should remove config field', function (done) {
|
||||
socketAdmin.config.remove({uid: fooUid}, 'someField1', function (err) {
|
||||
socketAdmin.config.remove({ uid: fooUid }, 'someField1', function (err) {
|
||||
assert.ifError(err);
|
||||
db.isObjectField('config', 'someField1', function (err, isObjectField) {
|
||||
assert.ifError(err);
|
||||
@@ -179,11 +178,9 @@ describe('meta', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Database Mock - wrapper for database.js, makes system use separate test db, instead of production
|
||||
* ATTENTION: testing db is flushed before every use!
|
||||
*/
|
||||
|
||||
(function (module) {
|
||||
'use strict';
|
||||
/*global require, before, __dirname*/
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var path = require('path');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
var url = require('url');
|
||||
var errorText;
|
||||
@@ -17,11 +16,11 @@
|
||||
|
||||
nconf.file({ file: path.join(__dirname, '../../config.json') });
|
||||
nconf.defaults({
|
||||
base_dir: path.join(__dirname,'../..'),
|
||||
base_dir: path.join(__dirname, '../..'),
|
||||
themes_path: path.join(__dirname, '../../node_modules'),
|
||||
upload_path: 'public/uploads',
|
||||
views_dir: path.join(__dirname, '../../build/public/templates'),
|
||||
relative_path: ''
|
||||
relative_path: '',
|
||||
});
|
||||
|
||||
if (!nconf.get('isCluster')) {
|
||||
@@ -39,27 +38,27 @@
|
||||
'\n===========================================================\n' +
|
||||
'Please, add parameters for test database in config.json\n' +
|
||||
'For example (redis):\n' +
|
||||
'"test_database": {' + '\n' +
|
||||
' "host": "127.0.0.1",' + '\n' +
|
||||
' "port": "6379",' + '\n' +
|
||||
' "password": "",' + '\n' +
|
||||
' "database": "1"' + '\n' +
|
||||
'"test_database": {\n' +
|
||||
' "host": "127.0.0.1",\n' +
|
||||
' "port": "6379",\n' +
|
||||
' "password": "",\n' +
|
||||
' "database": "1"\n' +
|
||||
'}\n' +
|
||||
' or (mongo):\n' +
|
||||
'"test_database": {' + '\n' +
|
||||
' "host": "127.0.0.1",' + '\n' +
|
||||
' "port": "27017",' + '\n' +
|
||||
' "password": "",' + '\n' +
|
||||
' "database": "1"' + '\n' +
|
||||
'"test_database": {\n' +
|
||||
' "host": "127.0.0.1",\n' +
|
||||
' "port": "27017",\n' +
|
||||
' "password": "",\n' +
|
||||
' "database": "1\n' +
|
||||
'}\n' +
|
||||
' or (mongo) in a replicaset\n' +
|
||||
'"test_database": {\n' +
|
||||
' "host": "127.0.0.1,127.0.0.1,127.0.0.1",\n' +
|
||||
' "port": "27017,27018,27019",\n' +
|
||||
' "username": "",\n' +
|
||||
' "password": "",\n' +
|
||||
' "database": "nodebb_test"\n' +
|
||||
'}\n' +
|
||||
' or (mongo) in a replicaset' + '\n' +
|
||||
'"test_database": {' + '\n' +
|
||||
' "host": "127.0.0.1,127.0.0.1,127.0.0.1",' + '\n' +
|
||||
' "port": "27017,27018,27019",' + '\n' +
|
||||
' "username": "",' + '\n' +
|
||||
' "password": "",' + '\n' +
|
||||
' "database": "nodebb_test"' + '\n' +
|
||||
'}\n' +
|
||||
'==========================================================='
|
||||
);
|
||||
winston.error(errorText);
|
||||
@@ -116,7 +115,7 @@
|
||||
function (next) {
|
||||
meta.themes.set({
|
||||
type: 'local',
|
||||
id: 'nodebb-theme-persona'
|
||||
id: 'nodebb-theme-persona',
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
@@ -151,7 +150,7 @@
|
||||
require('../../src/user').startJobs();
|
||||
|
||||
webserver.listen(next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
@@ -167,7 +166,7 @@
|
||||
winston.info('Enabling default plugins\n');
|
||||
|
||||
var defaultEnabled = [
|
||||
'nodebb-plugin-dbsearch'
|
||||
'nodebb-plugin-dbsearch',
|
||||
];
|
||||
|
||||
winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled);
|
||||
@@ -176,5 +175,4 @@
|
||||
}
|
||||
|
||||
module.exports = db;
|
||||
|
||||
}(module));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
// see https://gist.github.com/jfromaniello/4087861#gistcomment-1447029
|
||||
// XMLHttpRequest to override.
|
||||
|
||||
@@ -35,7 +37,7 @@ var callbacks = {};
|
||||
var newXhr = function () {
|
||||
stdXhr.apply(this, arguments);
|
||||
for (var method in callbacks) {
|
||||
if (typeof callbacks[method] == "function") {
|
||||
if (typeof callbacks[method] === 'function') {
|
||||
callbacks[method].apply(this, arguments);
|
||||
}
|
||||
}
|
||||
@@ -45,4 +47,4 @@ newXhr.XMLHttpRequest = newXhr;
|
||||
|
||||
cachedXhr.exports = newXhr;
|
||||
module.exports = newXhr;
|
||||
module.exports.callbacks = callbacks;
|
||||
module.exports.callbacks = callbacks;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
/*global require, after, before*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
@@ -15,7 +14,7 @@ describe('Notifications', function () {
|
||||
var notification;
|
||||
|
||||
before(function (done) {
|
||||
user.create({username: 'poster'}, function (err, _uid) {
|
||||
user.create({ username: 'poster' }, function (err, _uid) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
@@ -29,7 +28,7 @@ describe('Notifications', function () {
|
||||
notifications.create({
|
||||
bodyShort: 'bodyShort',
|
||||
nid: 'notification_id',
|
||||
path: '/notification/path'
|
||||
path: '/notification/path',
|
||||
}, function (err, _notification) {
|
||||
notification = _notification;
|
||||
assert.ifError(err);
|
||||
@@ -96,7 +95,7 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should mark a notification read', function (done) {
|
||||
socketNotifications.markRead({uid: uid}, notification.nid, function (err) {
|
||||
socketNotifications.markRead({ uid: uid }, notification.nid, function (err) {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -111,7 +110,7 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should mark a notification unread', function (done) {
|
||||
socketNotifications.markUnread({uid: uid}, notification.nid, function (err) {
|
||||
socketNotifications.markUnread({ uid: uid }, notification.nid, function (err) {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -119,7 +118,7 @@ describe('Notifications', function () {
|
||||
db.isSortedSetMember('uid:' + uid + ':notifications:read', notification.nid, function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
socketNotifications.getCount({uid: uid}, null, function (err, count) {
|
||||
socketNotifications.getCount({ uid: uid }, null, function (err, count) {
|
||||
assert.ifError(err);
|
||||
assert.equal(count, 1);
|
||||
done();
|
||||
@@ -130,7 +129,7 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should mark all notifications read', function (done) {
|
||||
socketNotifications.markAllRead({uid: uid}, null, function (err) {
|
||||
socketNotifications.markAllRead({ uid: uid }, null, function (err) {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -155,14 +154,14 @@ describe('Notifications', function () {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.create({username: 'watcher'}, next);
|
||||
user.create({ username: 'watcher' }, next);
|
||||
},
|
||||
function (_watcherUid, next) {
|
||||
watcherUid = _watcherUid;
|
||||
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
@@ -172,7 +171,7 @@ describe('Notifications', function () {
|
||||
uid: watcherUid,
|
||||
cid: cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
content: 'The content of test topic',
|
||||
}, next);
|
||||
},
|
||||
function (topic, next) {
|
||||
@@ -184,7 +183,7 @@ describe('Notifications', function () {
|
||||
topics.reply({
|
||||
uid: uid,
|
||||
content: 'This is the first reply.',
|
||||
tid: tid
|
||||
tid: tid,
|
||||
}, next);
|
||||
},
|
||||
function (post, next) {
|
||||
@@ -193,7 +192,7 @@ describe('Notifications', function () {
|
||||
topics.reply({
|
||||
uid: uid,
|
||||
content: 'This is the second reply.',
|
||||
tid: tid
|
||||
tid: tid,
|
||||
}, next);
|
||||
},
|
||||
function (post, next) {
|
||||
@@ -207,7 +206,7 @@ describe('Notifications', function () {
|
||||
assert.equal(notifications.unread.length, 1, 'there should be 1 unread notification');
|
||||
assert.equal('/post/' + pid, notifications.unread[0].path, 'the notification should link to the first unread post');
|
||||
next();
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
@@ -215,7 +214,7 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should get notification by nid', function (done) {
|
||||
socketNotifications.get({uid: uid}, {nids: [notification.nid]}, function (err, data) {
|
||||
socketNotifications.get({ uid: uid }, { nids: [notification.nid] }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0].bodyShort, 'bodyShort');
|
||||
assert.equal(data[0].nid, 'notification_id');
|
||||
@@ -225,7 +224,7 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should get user\'s notifications', function (done) {
|
||||
socketNotifications.get({uid: uid}, {}, function (err, data) {
|
||||
socketNotifications.get({ uid: uid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.unread.length, 0);
|
||||
assert.equal(data.read[0].nid, 'notification_id');
|
||||
@@ -234,21 +233,21 @@ describe('Notifications', function () {
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketNotifications.loadMore({uid: uid}, {after: 'test'}, function (err) {
|
||||
socketNotifications.loadMore({ uid: uid }, { after: 'test' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if not logged in', function (done) {
|
||||
socketNotifications.loadMore({uid: 0}, {after: 10}, function (err) {
|
||||
socketNotifications.loadMore({ uid: 0 }, { after: 10 }, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more notifications', function (done) {
|
||||
socketNotifications.loadMore({uid: uid}, {after: 0}, function (err, data) {
|
||||
socketNotifications.loadMore({ uid: uid }, { after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.notifications[0].bodyShort, 'bodyShort');
|
||||
assert.equal(data.notifications[0].nid, 'notification_id');
|
||||
@@ -259,16 +258,16 @@ describe('Notifications', function () {
|
||||
|
||||
|
||||
it('should error if not logged in', function (done) {
|
||||
socketNotifications.deleteAll({uid: 0}, null, function (err) {
|
||||
socketNotifications.deleteAll({ uid: 0 }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete all user notifications', function (done) {
|
||||
socketNotifications.deleteAll({uid: uid}, null, function (err) {
|
||||
socketNotifications.deleteAll({ uid: uid }, null, function (err) {
|
||||
assert.ifError(err);
|
||||
socketNotifications.get({uid: uid}, {}, function (err, data) {
|
||||
socketNotifications.get({ uid: uid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.unread.length, 0);
|
||||
assert.equal(data.read.length, 0);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var pagination = require('../src/pagination');
|
||||
|
||||
describe('Pagination', function () {
|
||||
|
||||
it('should create empty pagination for 1 page', function (done) {
|
||||
var data = pagination.create(1, 1);
|
||||
assert.equal(data.pages.length, 0);
|
||||
@@ -28,7 +27,7 @@ describe('Pagination', function () {
|
||||
});
|
||||
|
||||
it('should create pagination for 3 pages with query params', function (done) {
|
||||
var data = pagination.create(1, 3, {key: 'value'});
|
||||
var data = pagination.create(1, 3, { key: 'value' });
|
||||
assert.equal(data.pages.length, 3);
|
||||
assert.equal(data.rel.length, 1);
|
||||
assert.equal(data.pageCount, 3);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var path = require('path');
|
||||
@@ -10,7 +10,6 @@ var db = require('./mocks/databasemock');
|
||||
var plugins = require('../src/plugins');
|
||||
|
||||
describe('Plugins', function () {
|
||||
|
||||
it('should load plugin data', function (done) {
|
||||
var pluginId = 'nodebb-plugin-markdown';
|
||||
plugins.loadPlugin(path.join(nconf.get('base_dir'), 'node_modules/' + pluginId), function (err) {
|
||||
@@ -30,7 +29,7 @@ describe('Plugins', function () {
|
||||
|
||||
it('should register and fire a filter hook', function (done) {
|
||||
function filterMethod1(data, callback) {
|
||||
data.foo ++;
|
||||
data.foo += 1;
|
||||
callback(null, data);
|
||||
}
|
||||
function filterMethod2(data, callback) {
|
||||
@@ -38,15 +37,14 @@ describe('Plugins', function () {
|
||||
callback(null, data);
|
||||
}
|
||||
|
||||
plugins.registerHook('test-plugin', {hook: 'filter:test.hook', method: filterMethod1});
|
||||
plugins.registerHook('test-plugin', {hook: 'filter:test.hook', method: filterMethod2});
|
||||
plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 });
|
||||
plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 });
|
||||
|
||||
plugins.fireHook('filter:test.hook', {foo: 1}, function (err, data) {
|
||||
plugins.fireHook('filter:test.hook', { foo: 1 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.foo, 7);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should register and fire an action hook', function (done) {
|
||||
@@ -55,8 +53,8 @@ describe('Plugins', function () {
|
||||
done();
|
||||
}
|
||||
|
||||
plugins.registerHook('test-plugin', {hook: 'action:test.hook', method: actionMethod});
|
||||
plugins.fireHook('action:test.hook', {bar: 'test'});
|
||||
plugins.registerHook('test-plugin', { hook: 'action:test.hook', method: actionMethod });
|
||||
plugins.fireHook('action:test.hook', { bar: 'test' });
|
||||
});
|
||||
|
||||
it('should register and fire a static hook', function (done) {
|
||||
@@ -65,8 +63,8 @@ describe('Plugins', function () {
|
||||
callback();
|
||||
}
|
||||
|
||||
plugins.registerHook('test-plugin', {hook: 'static:test.hook', method: actionMethod});
|
||||
plugins.fireHook('static:test.hook', {bar: 'test'}, function (err) {
|
||||
plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: actionMethod });
|
||||
plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -179,8 +177,5 @@ describe('Plugins', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
343
test/posts.js
343
test/posts.js
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require, before, after*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
@@ -24,20 +24,20 @@ describe('Post\'s', function () {
|
||||
groups.resetCache();
|
||||
async.series({
|
||||
voterUid: function (next) {
|
||||
user.create({username: 'upvoter'}, next);
|
||||
user.create({ username: 'upvoter' }, next);
|
||||
},
|
||||
voteeUid: function (next) {
|
||||
user.create({username: 'upvotee'}, next);
|
||||
user.create({ username: 'upvotee' }, next);
|
||||
},
|
||||
globalModUid: function (next) {
|
||||
user.create({username: 'globalmod'}, next);
|
||||
user.create({ username: 'globalmod' }, next);
|
||||
},
|
||||
category: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -52,7 +52,7 @@ describe('Post\'s', function () {
|
||||
uid: results.voteeUid,
|
||||
cid: results.category.cid,
|
||||
title: 'Test Topic Title',
|
||||
content: 'The content of test topic'
|
||||
content: 'The content of test topic',
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -68,7 +68,7 @@ describe('Post\'s', function () {
|
||||
describe('voting', function () {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
it('should upvote a post', function (done) {
|
||||
socketPosts.upvote({uid: voterUid}, {pid: postData.pid, room_id: 'topic_1'}, function (err, result) {
|
||||
socketPosts.upvote({ uid: voterUid }, { pid: postData.pid, room_id: 'topic_1' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.post.upvotes, 1);
|
||||
assert.equal(result.post.downvotes, 0);
|
||||
@@ -84,7 +84,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should get voters', function (done) {
|
||||
socketPosts.getVoters({uid: globalModUid}, {pid: postData.pid, cid: cid}, function (err, data) {
|
||||
socketPosts.getVoters({ uid: globalModUid }, { pid: postData.pid, cid: cid }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.upvoteCount, 1);
|
||||
assert.equal(data.downvoteCount, 0);
|
||||
@@ -95,7 +95,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should get upvoters', function (done) {
|
||||
socketPosts.getUpvoters({uid: globalModUid}, [postData.pid], function (err, data) {
|
||||
socketPosts.getUpvoters({ uid: globalModUid }, [postData.pid], function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0].otherCount, 0);
|
||||
assert.equal(data[0].usernames, 'upvoter');
|
||||
@@ -104,7 +104,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should unvote a post', function (done) {
|
||||
socketPosts.unvote({uid: voterUid}, {pid: postData.pid, room_id: 'topic_1'}, function (err, result) {
|
||||
socketPosts.unvote({ uid: voterUid }, { pid: postData.pid, room_id: 'topic_1' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.post.upvotes, 0);
|
||||
assert.equal(result.post.downvotes, 0);
|
||||
@@ -120,7 +120,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should downvote a post', function (done) {
|
||||
socketPosts.downvote({uid: voterUid}, {pid: postData.pid, room_id: 'topic_1'}, function (err, result) {
|
||||
socketPosts.downvote({ uid: voterUid }, { pid: postData.pid, room_id: 'topic_1' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.post.upvotes, 0);
|
||||
assert.equal(result.post.downvotes, 1);
|
||||
@@ -166,14 +166,14 @@ describe('Post\'s', function () {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
|
||||
it('should error if data is invalid', function (done) {
|
||||
socketPosts.loadPostTools({uid: globalModUid}, null, function (err) {
|
||||
socketPosts.loadPostTools({ uid: globalModUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load post tools', function (done) {
|
||||
socketPosts.loadPostTools({uid: globalModUid}, {pid: postData.pid, cid: cid}, function (err, data) {
|
||||
socketPosts.loadPostTools({ uid: globalModUid }, { pid: postData.pid, cid: cid }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data.posts.display_edit_tools);
|
||||
assert(data.posts.display_delete_tools);
|
||||
@@ -190,14 +190,14 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
cid: cid,
|
||||
title: 'topic to delete/restore/purge',
|
||||
content: 'A post to delete/restore/purge'
|
||||
content: 'A post to delete/restore/purge',
|
||||
}, function (err, topicPostData) {
|
||||
assert.ifError(err);
|
||||
topics.reply({
|
||||
uid: voterUid,
|
||||
tid: topicPostData.topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'A post to delete/restore and purge'
|
||||
content: 'A post to delete/restore and purge',
|
||||
}, function (err, replyData) {
|
||||
assert.ifError(err);
|
||||
callback(topicPostData, replyData);
|
||||
@@ -220,14 +220,14 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.delete({uid: voterUid}, null, function (err) {
|
||||
socketPosts.delete({ uid: voterUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a post', function (done) {
|
||||
socketPosts.delete({uid: voterUid}, {pid: replyPid, tid: tid}, function (err) {
|
||||
socketPosts.delete({ uid: voterUid }, { pid: replyPid, tid: tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(replyPid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
@@ -238,7 +238,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should restore a post', function (done) {
|
||||
socketPosts.restore({uid: voterUid}, {pid: replyPid, tid: tid}, function (err) {
|
||||
socketPosts.restore({ uid: voterUid }, { pid: replyPid, tid: tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(replyPid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
@@ -249,7 +249,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should delete posts', function (done) {
|
||||
socketPosts.deletePosts({uid: globalModUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
||||
socketPosts.deletePosts({ uid: globalModUid }, { pids: [replyPid, mainPid], tid: tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(replyPid, 'deleted', function (err, deleted) {
|
||||
assert.ifError(err);
|
||||
@@ -264,9 +264,9 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should delete topic if last main post is deleted', function (done) {
|
||||
topics.post({uid: voterUid, cid: cid, title: 'test topic', content: 'test topic'}, function (err, data) {
|
||||
topics.post({ uid: voterUid, cid: cid, title: 'test topic', content: 'test topic' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
socketPosts.deletePosts({uid: globalModUid}, {pids: [data.postData.pid], tid: data.topicData.tid}, function (err) {
|
||||
socketPosts.deletePosts({ uid: globalModUid }, { pids: [data.postData.pid], tid: data.topicData.tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
|
||||
assert.ifError(err);
|
||||
@@ -278,9 +278,8 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should purge posts and delete topic', function (done) {
|
||||
|
||||
createTopicWithReply(function (topicPostData, replyData) {
|
||||
socketPosts.purgePosts({uid: voterUid}, {pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid}, function (err) {
|
||||
socketPosts.purgePosts({ uid: voterUid }, { pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.exists('post:' + replyData.pid, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
@@ -307,7 +306,7 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
cid: cid,
|
||||
title: 'topic to edit',
|
||||
content: 'A post to edit'
|
||||
content: 'A post to edit',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
pid = data.postData.pid;
|
||||
@@ -316,7 +315,7 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
tid: tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'A reply to edit'
|
||||
content: 'A reply to edit',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
replyPid = data.pid;
|
||||
@@ -326,21 +325,21 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should error if user is not logged in', function (done) {
|
||||
socketPosts.edit({uid: 0}, {}, function (err) {
|
||||
socketPosts.edit({ uid: 0 }, {}, function (err) {
|
||||
assert.equal(err.message, '[[error:not-logged-in]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if data is invalid or missing', function (done) {
|
||||
socketPosts.edit({uid: voterUid}, {}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, {}, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if title is too short', function (done) {
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited post content', title: 'a'}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: 'a' }, function (err) {
|
||||
assert.equal(err.message, '[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]');
|
||||
done();
|
||||
});
|
||||
@@ -348,7 +347,7 @@ describe('Post\'s', function () {
|
||||
|
||||
it('should error if title is too long', function (done) {
|
||||
var longTitle = new Array(parseInt(meta.config.maximumTitleLength, 10) + 2).join('a');
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited post content', title: longTitle}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: longTitle }, function (err) {
|
||||
assert.equal(err.message, '[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]');
|
||||
done();
|
||||
});
|
||||
@@ -357,7 +356,7 @@ describe('Post\'s', function () {
|
||||
it('should error with too few tags', function (done) {
|
||||
var oldValue = meta.config.minimumTagsPerTopic;
|
||||
meta.config.minimumTagsPerTopic = 1;
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited post content', tags: []}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', tags: [] }, function (err) {
|
||||
assert.equal(err.message, '[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]');
|
||||
meta.config.minimumTagsPerTopic = oldValue;
|
||||
done();
|
||||
@@ -366,17 +365,17 @@ describe('Post\'s', function () {
|
||||
|
||||
it('should error with too many tags', function (done) {
|
||||
var tags = [];
|
||||
for(var i = 0; i < meta.config.maximumTagsPerTopic + 1; ++i) {
|
||||
for (var i = 0; i < meta.config.maximumTagsPerTopic + 1; i += 1) {
|
||||
tags.push('tag' + i);
|
||||
}
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited post content', tags: tags}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', tags: tags }, function (err) {
|
||||
assert.equal(err.message, '[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if content is too short', function (done) {
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'e'}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'e' }, function (err) {
|
||||
assert.equal(err.message, '[[error:content-too-short, ' + meta.config.minimumPostLength + ']]');
|
||||
done();
|
||||
});
|
||||
@@ -384,14 +383,14 @@ describe('Post\'s', function () {
|
||||
|
||||
it('should error if content is too long', function (done) {
|
||||
var longContent = new Array(parseInt(meta.config.maximumPostLength, 10) + 2).join('a');
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: longContent}, function (err) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: longContent }, function (err) {
|
||||
assert.equal(err.message, '[[error:content-too-long, ' + meta.config.maximumPostLength + ']]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should edit post', function (done) {
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited post content', title: 'edited title', tags: ['edited']}, function (err, data) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: 'edited title', tags: ['edited'] }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.content, 'edited post content');
|
||||
assert.equal(data.editor, voterUid);
|
||||
@@ -402,9 +401,9 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should edit a deleted post', function (done) {
|
||||
socketPosts.delete({uid: voterUid}, {pid: pid, tid: tid}, function (err) {
|
||||
socketPosts.delete({ uid: voterUid }, { pid: pid, tid: tid }, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.edit({uid: voterUid}, {pid: pid, content: 'edited deleted content', title: 'edited deleted title', tags: ['deleted']}, function (err, data) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited deleted content', title: 'edited deleted title', tags: ['deleted'] }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.content, 'edited deleted content');
|
||||
assert.equal(data.editor, voterUid);
|
||||
@@ -416,7 +415,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should edit a reply post', function (done) {
|
||||
socketPosts.edit({uid: voterUid}, {pid: replyPid, content: 'edited reply'}, function (err, data) {
|
||||
socketPosts.edit({ uid: voterUid }, { pid: replyPid, content: 'edited reply' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.content, 'edited reply');
|
||||
assert.equal(data.editor, voterUid);
|
||||
@@ -440,7 +439,7 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
cid: cid,
|
||||
title: 'topic 1',
|
||||
content: 'some content'
|
||||
content: 'some content',
|
||||
}, next);
|
||||
},
|
||||
function (data, next) {
|
||||
@@ -449,7 +448,7 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
cid: cid,
|
||||
title: 'topic 2',
|
||||
content: 'some content'
|
||||
content: 'some content',
|
||||
}, next);
|
||||
},
|
||||
function (data, next) {
|
||||
@@ -458,32 +457,32 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
tid: tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'A reply to move'
|
||||
content: 'A reply to move',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
replyPid = data.pid;
|
||||
next();
|
||||
});
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should error if uid is not logged in', function (done) {
|
||||
socketPosts.movePost({uid: 0}, {}, function (err) {
|
||||
socketPosts.movePost({ uid: 0 }, {}, function (err) {
|
||||
assert.equal(err.message, '[[error:not-logged-in]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if data is invalid', function (done) {
|
||||
socketPosts.movePost({uid: globalModUid}, {}, function (err) {
|
||||
socketPosts.movePost({ uid: globalModUid }, {}, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if user does not have move privilege', function (done) {
|
||||
socketPosts.movePost({uid: voterUid}, {pid: replyPid, tid: moveTid}, function (err) {
|
||||
socketPosts.movePost({ uid: voterUid }, { pid: replyPid, tid: moveTid }, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
@@ -491,7 +490,7 @@ describe('Post\'s', function () {
|
||||
|
||||
|
||||
it('should move a post', function (done) {
|
||||
socketPosts.movePost({uid: globalModUid}, {pid: replyPid, tid: moveTid}, function (err) {
|
||||
socketPosts.movePost({ uid: globalModUid }, { pid: replyPid, tid: moveTid }, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(replyPid, 'tid', function (err, tid) {
|
||||
assert.ifError(err);
|
||||
@@ -502,6 +501,221 @@ describe('Post\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('flagging a post', function () {
|
||||
var meta = require('../src/meta');
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
it('should fail to flag a post due to low reputation', function (done) {
|
||||
meta.config['privileges:flag'] = 10;
|
||||
flagPost(function (err) {
|
||||
assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should flag a post', function (done) {
|
||||
meta.config['privileges:flag'] = -1;
|
||||
flagPost(function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return nothing without a uid or a reason', function (done) {
|
||||
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) {
|
||||
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) {
|
||||
socketPosts.flag({ uid: voteeUid }, { pid: postData.pid, reason: 'reason' }, function (err) {
|
||||
assert.equal(err.message, '[[error:already-flagged]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function flagPost(next) {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
socketPosts.flag({ uid: voteeUid }, { pid: postData.pid, reason: 'reason' }, next);
|
||||
}
|
||||
|
||||
describe('get flag data', function () {
|
||||
it('should see the flagged post', function (done) {
|
||||
posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {
|
||||
assert.ifError(err);
|
||||
assert(hasFlagged);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the flagged post data', function (done) {
|
||||
posts.getFlags('posts:flagged', cid, voteeUid, 0, -1, function (err, flagData) {
|
||||
assert.ifError(err);
|
||||
assert(flagData.posts);
|
||||
assert(flagData.count);
|
||||
assert.equal(flagData.count, 1);
|
||||
assert.equal(flagData.posts.length, 1);
|
||||
assert(flagData.posts[0].flagReasons);
|
||||
assert.equal(flagData.posts[0].flagReasons.length, 1);
|
||||
assert.strictEqual(flagData.posts[0].flagReasons[0].reason, 'reason');
|
||||
assert(flagData.posts[0].flagData);
|
||||
assert.strictEqual(flagData.posts[0].flagData.state, 'open');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('updating a flag', function () {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
|
||||
it('should update a flag', function (done) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
socketPosts.updateFlag({ uid: globalModUid }, {
|
||||
pid: postData.pid,
|
||||
data: [
|
||||
{ name: 'assignee', value: `${globalModUid}` },
|
||||
{ name: 'notes', value: 'notes' },
|
||||
],
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getFlags('posts:flagged', cid, globalModUid, 0, -1, function (err, flagData) {
|
||||
assert.ifError(err);
|
||||
assert(flagData.posts);
|
||||
assert.equal(flagData.posts.length, 1);
|
||||
assert.deepEqual({
|
||||
assignee: flagData.posts[0].flagData.assignee,
|
||||
notes: flagData.posts[0].flagData.notes,
|
||||
state: flagData.posts[0].flagData.state,
|
||||
labelClass: flagData.posts[0].flagData.labelClass,
|
||||
}, {
|
||||
assignee: `${globalModUid}`,
|
||||
notes: 'notes',
|
||||
state: 'open',
|
||||
labelClass: 'info',
|
||||
});
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, function (next) {
|
||||
posts.updateFlagData(globalModUid, postData.pid, {
|
||||
state: 'rejected',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getFlags('posts:flagged', cid, globalModUid, 0, -1, function (err, flagData) {
|
||||
assert.ifError(err);
|
||||
assert(flagData.posts);
|
||||
assert.equal(flagData.posts.length, 1);
|
||||
assert.deepEqual({
|
||||
state: flagData.posts[0].flagData.state,
|
||||
labelClass: flagData.posts[0].flagData.labelClass,
|
||||
}, {
|
||||
state: 'rejected',
|
||||
labelClass: 'danger',
|
||||
});
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, function (next) {
|
||||
posts.updateFlagData(globalModUid, postData.pid, {
|
||||
state: 'wip',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getFlags('posts:flagged', cid, globalModUid, 0, -1, function (err, flagData) {
|
||||
assert.ifError(err);
|
||||
assert(flagData.posts);
|
||||
assert.equal(flagData.posts.length, 1);
|
||||
assert.deepEqual({
|
||||
state: flagData.posts[0].flagData.state,
|
||||
labelClass: flagData.posts[0].flagData.labelClass,
|
||||
}, {
|
||||
state: 'wip',
|
||||
labelClass: 'warning',
|
||||
});
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, function (next) {
|
||||
posts.updateFlagData(globalModUid, postData.pid, {
|
||||
state: 'resolved',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getFlags('posts:flagged', cid, globalModUid, 0, -1, function (err, flagData) {
|
||||
assert.ifError(err);
|
||||
assert(flagData.posts);
|
||||
assert.equal(flagData.posts.length, 1);
|
||||
assert.deepEqual({
|
||||
state: flagData.posts[0].flagData.state,
|
||||
labelClass: flagData.posts[0].flagData.labelClass,
|
||||
}, {
|
||||
state: 'resolved',
|
||||
labelClass: 'success',
|
||||
});
|
||||
next();
|
||||
});
|
||||
});
|
||||
},
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dismissing a flag', function () {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
|
||||
it('should dismiss a flag', function (done) {
|
||||
socketPosts.dismissFlag({ uid: globalModUid }, postData.pid, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {
|
||||
assert.ifError(err);
|
||||
assert(!hasFlagged);
|
||||
flagPost(function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should dismiss all of a user\'s flags', function (done) {
|
||||
posts.dismissUserFlags(voteeUid, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {
|
||||
assert.ifError(err);
|
||||
assert(!hasFlagged);
|
||||
flagPost(function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should dismiss all flags', function (done) {
|
||||
socketPosts.dismissAllFlags({ uid: globalModUid }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.isFlaggedByUser(postData.pid, voteeUid, function (err, hasFlagged) {
|
||||
assert.ifError(err);
|
||||
assert(!hasFlagged);
|
||||
flagPost(function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPostSummaryByPids', function () {
|
||||
it('should return empty array for empty pids', function (done) {
|
||||
posts.getPostSummaryByPids([], 0, {}, function (err, data) {
|
||||
@@ -527,7 +741,7 @@ describe('Post\'s', function () {
|
||||
uid: voterUid,
|
||||
tid: topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'some content'
|
||||
content: 'some content',
|
||||
}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getRecentPosterUids(0, 1, function (err, uids) {
|
||||
@@ -541,14 +755,13 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
describe('socket methods', function () {
|
||||
|
||||
var pid;
|
||||
before(function (done) {
|
||||
topics.reply({
|
||||
uid: voterUid,
|
||||
tid: topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'raw content'
|
||||
content: 'raw content',
|
||||
}, function (err, postData) {
|
||||
assert.ifError(err);
|
||||
pid = postData.pid;
|
||||
@@ -558,21 +771,21 @@ describe('Post\'s', function () {
|
||||
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.reply({uid: 0}, null, function (err) {
|
||||
socketPosts.reply({ uid: 0 }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid tid', function (done) {
|
||||
socketPosts.reply({uid: 0}, {tid: 0, content: 'derp'}, function (err) {
|
||||
socketPosts.reply({ uid: 0 }, { tid: 0, content: 'derp' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to get raw post because of privilege', function (done) {
|
||||
socketPosts.getRawPost({uid: 0}, pid, function (err) {
|
||||
socketPosts.getRawPost({ uid: 0 }, pid, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
@@ -581,7 +794,7 @@ describe('Post\'s', function () {
|
||||
it('should fail to get raw post because post is deleted', function (done) {
|
||||
posts.setPostField(pid, 'deleted', 1, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.getRawPost({uid: voterUid}, pid, function (err) {
|
||||
socketPosts.getRawPost({ uid: voterUid }, pid, function (err) {
|
||||
assert.equal(err.message, '[[error:no-post]]');
|
||||
done();
|
||||
});
|
||||
@@ -591,7 +804,7 @@ describe('Post\'s', function () {
|
||||
it('should get raw post content', function (done) {
|
||||
posts.setPostField(pid, 'deleted', 0, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.getRawPost({uid: voterUid}, pid, function (err, postContent) {
|
||||
socketPosts.getRawPost({ uid: voterUid }, pid, function (err, postContent) {
|
||||
assert.ifError(err);
|
||||
assert.equal(postContent, 'raw content');
|
||||
done();
|
||||
@@ -600,7 +813,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should get post', function (done) {
|
||||
socketPosts.getPost({uid: voterUid}, pid, function (err, postData) {
|
||||
socketPosts.getPost({ uid: voterUid }, pid, function (err, postData) {
|
||||
assert.ifError(err);
|
||||
assert(postData);
|
||||
done();
|
||||
@@ -608,14 +821,14 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('shold error with invalid data', function (done) {
|
||||
socketPosts.loadMoreBookmarks({uid: voterUid}, {uid: voterUid, after: null}, function (err, postData) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: null }, function (err, postData) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more bookmarks', function (done) {
|
||||
socketPosts.loadMoreBookmarks({uid: voterUid}, {uid: voterUid, after: 0}, function (err, data) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -623,7 +836,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should load more user posts', function (done) {
|
||||
socketPosts.loadMoreUserPosts({uid: voterUid}, {uid: voterUid, after: 0}, function (err, data) {
|
||||
socketPosts.loadMoreUserPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -631,7 +844,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should load more best posts', function (done) {
|
||||
socketPosts.loadMoreBestPosts({uid: voterUid}, {uid: voterUid, after: 0}, function (err, data) {
|
||||
socketPosts.loadMoreBestPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -639,7 +852,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should load more up voted posts', function (done) {
|
||||
socketPosts.loadMoreUpVotedPosts({uid: voterUid}, {uid: voterUid, after: 0}, function (err, data) {
|
||||
socketPosts.loadMoreUpVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -647,7 +860,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should load more down voted posts', function (done) {
|
||||
socketPosts.loadMoreDownVotedPosts({uid: voterUid}, {uid: voterUid, after: 0}, function (err, data) {
|
||||
socketPosts.loadMoreDownVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
@@ -655,7 +868,7 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should get post category', function (done) {
|
||||
socketPosts.getCategory({uid: voterUid}, pid, function (err, postCid) {
|
||||
socketPosts.getCategory({ uid: voterUid }, pid, function (err, postCid) {
|
||||
assert.ifError(err);
|
||||
assert.equal(cid, postCid);
|
||||
done();
|
||||
@@ -663,14 +876,14 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.getPidIndex({uid: voterUid}, null, function (err) {
|
||||
socketPosts.getPidIndex({ uid: voterUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get pid index', function (done) {
|
||||
socketPosts.getPidIndex({uid: voterUid}, {pid: pid, tid: topicData.tid, topicPostSort: 'oldest-to-newest'}, function (err, index) {
|
||||
socketPosts.getPidIndex({ uid: voterUid }, { pid: pid, tid: topicData.tid, topicPostSort: 'oldest-to-newest' }, function (err, index) {
|
||||
assert.ifError(err);
|
||||
assert.equal(index, 2);
|
||||
done();
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('rewards', function () {
|
||||
async.series([
|
||||
async.apply(User.create, { username: 'foo', password: 'barbar' }),
|
||||
async.apply(User.create, { username: 'baz', password: 'quuxquux' }),
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' })
|
||||
async.apply(User.create, { username: 'herp', password: 'derpderp' }),
|
||||
], function (err, uids) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -31,11 +31,11 @@ describe('rewards', function () {
|
||||
|
||||
async.series([
|
||||
function (next) {
|
||||
Groups.join('administrators', adminUid, done);
|
||||
Groups.join('administrators', adminUid, next);
|
||||
},
|
||||
function (next) {
|
||||
Groups.join('rewardGroup', adminUid, done);
|
||||
}
|
||||
Groups.join('rewardGroup', adminUid, next);
|
||||
},
|
||||
], done);
|
||||
});
|
||||
});
|
||||
@@ -53,11 +53,11 @@ describe('rewards', function () {
|
||||
rid: 'essentials/add-to-group',
|
||||
claimable: '1',
|
||||
id: '',
|
||||
disabled: false
|
||||
}
|
||||
disabled: false,
|
||||
},
|
||||
];
|
||||
|
||||
socketAdmin.rewards.save({uid: adminUid}, data, function (err) {
|
||||
socketAdmin.rewards.save({ uid: adminUid }, data, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -72,14 +72,9 @@ describe('rewards', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var search = require('../src/admin/search');
|
||||
|
||||
describe('admin search', function () {
|
||||
describe('filterDirectories', function () {
|
||||
it('should resolve all paths to relative paths', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
it('should exclude partials', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
'dfahdfsgf/admin/partials/hgkfds/fdhsdfh.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
it('should exclude files in the admin directory', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
'dfdasg/admin/hjkdfsk.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('filterDirectories', function () {
|
||||
it('should resolve all paths to relative paths', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
it('should exclude partials', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
'dfahdfsgf/admin/partials/hgkfds/fdhsdfh.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
it('should exclude files in the admin directory', function (done) {
|
||||
assert.deepEqual(search.filterDirectories([
|
||||
'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl',
|
||||
'dfdasg/admin/hjkdfsk.tpl',
|
||||
]), [
|
||||
'admin/gdhgfsdg/sggag',
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitize', function () {
|
||||
it('should strip out scripts', function (done) {
|
||||
assert.equal(
|
||||
describe('sanitize', function () {
|
||||
it('should strip out scripts', function (done) {
|
||||
assert.equal(
|
||||
search.sanitize('Pellentesque tristique senectus' +
|
||||
'<script>alert("nope");</script> habitant morbi'),
|
||||
'Pellentesque tristique senectus' +
|
||||
' habitant morbi'
|
||||
);
|
||||
done();
|
||||
});
|
||||
it('should remove all tags', function (done) {
|
||||
assert.equal(
|
||||
done();
|
||||
});
|
||||
it('should remove all tags', function (done) {
|
||||
assert.equal(
|
||||
search.sanitize('<p>Pellentesque <b>habitant morbi</b> tristique senectus' +
|
||||
'Aenean <i>vitae</i> est.Mauris <a href="placerat">eleifend</a> leo.</p>'),
|
||||
'Pellentesque habitant morbi tristique senectus' +
|
||||
'Aenean vitae est.Mauris eleifend leo.'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('simplify', function () {
|
||||
it('should remove all mustaches', function (done) {
|
||||
assert.equal(
|
||||
describe('simplify', function () {
|
||||
it('should remove all mustaches', function (done) {
|
||||
assert.equal(
|
||||
search.simplify(
|
||||
'Pellentesque tristique {{senectus}}habitant morbi' +
|
||||
'liquam tincidunt {mauris.eu}risus'
|
||||
@@ -65,10 +65,10 @@ describe('admin search', function () {
|
||||
'Pellentesque tristique habitant morbi' +
|
||||
'liquam tincidunt risus'
|
||||
);
|
||||
done();
|
||||
});
|
||||
it('should collapse all whitespace', function (done) {
|
||||
assert.equal(
|
||||
done();
|
||||
});
|
||||
it('should collapse all whitespace', function (done) {
|
||||
assert.equal(
|
||||
search.simplify(
|
||||
'Pellentesque tristique habitant morbi' +
|
||||
' \n\n liquam tincidunt mauris eu risus.'
|
||||
@@ -76,7 +76,7 @@ describe('admin search', function () {
|
||||
'Pellentesque tristique habitant morbi' +
|
||||
'\nliquam tincidunt mauris eu risus.'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require, before, after*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
@@ -29,23 +29,23 @@ describe('Search', function () {
|
||||
function (next) {
|
||||
async.series({
|
||||
phoebe: function (next) {
|
||||
user.create({username: 'phoebe'}, next);
|
||||
user.create({ username: 'phoebe' }, next);
|
||||
},
|
||||
ginger: function (next) {
|
||||
user.create({username: 'ginger'}, next);
|
||||
user.create({ username: 'ginger' }, next);
|
||||
},
|
||||
category1: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
category2: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -61,7 +61,7 @@ describe('Search', function () {
|
||||
cid: cid1,
|
||||
title: 'nodebb mongodb bugs',
|
||||
content: 'avocado cucumber apple orange fox',
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'jquery']
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'jquery'],
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -73,7 +73,7 @@ describe('Search', function () {
|
||||
cid: cid2,
|
||||
title: 'java mongodb redis',
|
||||
content: 'avocado cucumber carrot armadillo',
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'javascript']
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'javascript'],
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -82,27 +82,26 @@ describe('Search', function () {
|
||||
topics.reply({
|
||||
uid: phoebeUid,
|
||||
content: 'reply post apple',
|
||||
tid: topic2Data.tid
|
||||
tid: topic2Data.tid,
|
||||
}, next);
|
||||
},
|
||||
function (_post3Data, next) {
|
||||
post3Data = _post3Data;
|
||||
setTimeout(next, 500);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should search term in titles and posts', function (done) {
|
||||
|
||||
var meta = require('../src/meta');
|
||||
meta.config.allowGuestSearching = 1;
|
||||
var qs = '/api/search?term=cucumber&in=titlesposts&categories[]=' + cid1 + '&by=phoebe&replies=1&repliesFilter=atleast&sortBy=timestamp&sortDirection=desc&showAs=posts';
|
||||
|
||||
request({
|
||||
url: nconf.get('url') + qs,
|
||||
json: true
|
||||
json: true,
|
||||
}, function (err, response, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
@@ -118,7 +117,7 @@ describe('Search', function () {
|
||||
it('should search for a user', function (done) {
|
||||
search.search({
|
||||
query: 'gin',
|
||||
searchIn: 'users'
|
||||
searchIn: 'users',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
@@ -133,7 +132,7 @@ describe('Search', function () {
|
||||
it('should search for a tag', function (done) {
|
||||
search.search({
|
||||
query: 'plug',
|
||||
searchIn: 'tags'
|
||||
searchIn: 'tags',
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
@@ -148,7 +147,7 @@ describe('Search', function () {
|
||||
it('should fail if searchIn is wrong', function (done) {
|
||||
search.search({
|
||||
query: 'plug',
|
||||
searchIn: 'invalidfilter'
|
||||
searchIn: 'invalidfilter',
|
||||
}, function (err) {
|
||||
assert.equal(err.message, '[[error:unknown-search-filter]]');
|
||||
done();
|
||||
@@ -159,7 +158,7 @@ describe('Search', function () {
|
||||
search.search({
|
||||
query: 'mongodb',
|
||||
searchIn: 'titles',
|
||||
hasTags: ['nodebb', 'javascript']
|
||||
hasTags: ['nodebb', 'javascript'],
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.posts[0].tid, topic2Data.tid);
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
// see https://gist.github.com/jfromaniello/4087861#gistcomment-1447029
|
||||
|
||||
/* global process, require, before, after*/
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
@@ -20,7 +19,6 @@ var categories = require('../src/categories');
|
||||
|
||||
|
||||
describe('socket.io', function () {
|
||||
|
||||
var io;
|
||||
var cid;
|
||||
var tid;
|
||||
@@ -30,11 +28,11 @@ describe('socket.io', function () {
|
||||
before(function (done) {
|
||||
async.series([
|
||||
async.apply(user.create, { username: 'admin', password: 'adminpwd' }),
|
||||
async.apply(user.create, { username: 'regular', password: 'regularpwd', email: 'regular@test.com'}),
|
||||
async.apply(user.create, { username: 'regular', password: 'regularpwd', email: 'regular@test.com' }),
|
||||
async.apply(categories.create, {
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
})
|
||||
description: 'Test category created by testing script',
|
||||
}),
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -52,7 +50,7 @@ describe('socket.io', function () {
|
||||
request.get({
|
||||
url: nconf.get('url') + '/api/config',
|
||||
jar: cookies,
|
||||
json: true
|
||||
json: true,
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -60,12 +58,12 @@ describe('socket.io', function () {
|
||||
jar: cookies,
|
||||
form: {
|
||||
username: 'admin',
|
||||
password: 'adminpwd'
|
||||
password: 'adminpwd',
|
||||
},
|
||||
headers: {
|
||||
'x-csrf-token': body.csrf_token
|
||||
'x-csrf-token': body.csrf_token,
|
||||
},
|
||||
json: true
|
||||
json: true,
|
||||
}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -79,7 +77,7 @@ describe('socket.io', function () {
|
||||
};
|
||||
};
|
||||
|
||||
io = require('socket.io-client')(nconf.get('url'), {forceNew: true});
|
||||
io = require('socket.io-client')(nconf.get('url'), { forceNew: true });
|
||||
|
||||
io.on('connect', function () {
|
||||
done();
|
||||
@@ -116,7 +114,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should post a topic', function (done) {
|
||||
io.emit('topics.post', {title: 'test topic title', content: 'test topic main post content', uid: adminUid, cid: cid}, function (err, result) {
|
||||
io.emit('topics.post', { title: 'test topic title', content: 'test topic main post content', uid: adminUid, cid: cid }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.user.username, 'admin');
|
||||
assert.equal(result.category.cid, cid);
|
||||
@@ -127,7 +125,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should reply to topic', function (done) {
|
||||
io.emit('posts.reply', {tid: tid, uid: adminUid, content: 'test post content'}, function (err, result) {
|
||||
io.emit('posts.reply', { tid: tid, uid: adminUid, content: 'test post content' }, function (err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.uid, adminUid);
|
||||
assert.equal(result.user.username, 'admin');
|
||||
@@ -138,7 +136,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should ban a user', function (done) {
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
socketUser.banUsers({uid: adminUid}, {uids: [regularUid], reason: 'spammer'}, function (err) {
|
||||
socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, function (err) {
|
||||
assert.ifError(err);
|
||||
user.getLatestBanInfo(regularUid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
@@ -162,7 +160,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should unban a user', function (done) {
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
socketUser.unbanUsers({uid: adminUid}, [regularUid], function (err) {
|
||||
socketUser.unbanUsers({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
user.isBanned(regularUid, function (err, isBanned) {
|
||||
assert.ifError(err);
|
||||
@@ -174,7 +172,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should make user admin', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.makeAdmins({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.makeAdmins({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
groups.isMember(regularUid, 'administrators', function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -186,7 +184,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should make user non-admin', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.removeAdmins({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.removeAdmins({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
groups.isMember(regularUid, 'administrators', function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -200,7 +198,7 @@ describe('socket.io', function () {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
var uid;
|
||||
it('should create a user', function (done) {
|
||||
socketAdmin.user.createUser({uid: adminUid}, {username: 'foo1'}, function (err, _uid) {
|
||||
socketAdmin.user.createUser({ uid: adminUid }, { username: 'foo1' }, function (err, _uid) {
|
||||
assert.ifError(err);
|
||||
uid = _uid;
|
||||
groups.isMember(uid, 'registered-users', function (err, isMember) {
|
||||
@@ -212,7 +210,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should delete users', function (done) {
|
||||
socketAdmin.user.deleteUsers({uid: adminUid}, [uid], function (err) {
|
||||
socketAdmin.user.deleteUsers({ uid: adminUid }, [uid], function (err) {
|
||||
assert.ifError(err);
|
||||
groups.isMember(uid, 'registered-users', function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
@@ -223,7 +221,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should delete users and their content', function (done) {
|
||||
socketAdmin.user.deleteUsersAndContent({uid: adminUid}, [uid], function (err) {
|
||||
socketAdmin.user.deleteUsersAndContent({ uid: adminUid }, [uid], function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -232,7 +230,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.createUser({uid: adminUid}, null, function (err) {
|
||||
socketAdmin.user.createUser({ uid: adminUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
@@ -240,7 +238,15 @@ describe('socket.io', function () {
|
||||
|
||||
it('should reset lockouts', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.resetLockouts({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.resetLockouts({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should reset flags', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.resetFlags({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -251,7 +257,7 @@ describe('socket.io', function () {
|
||||
var meta = require('../src/meta');
|
||||
|
||||
it('should validate emails', function (done) {
|
||||
socketAdmin.user.validateEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.validateEmail({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
user.getUserField(regularUid, 'email:confirmed', function (err, emailConfirmed) {
|
||||
assert.ifError(err);
|
||||
@@ -263,7 +269,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should error with invalid uids', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, null, function (err) {
|
||||
socketAdmin.user.sendValidationEmail({ uid: adminUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
@@ -271,7 +277,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should error if email validation is not required', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.sendValidationEmail({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.equal(err.message, '[[error:email-confirmations-are-disabled]]');
|
||||
done();
|
||||
});
|
||||
@@ -280,7 +286,7 @@ describe('socket.io', function () {
|
||||
it('should send validation email', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
meta.config.requireEmailConfirmation = 1;
|
||||
socketAdmin.user.sendValidationEmail({uid: adminUid}, [regularUid], function (err) {
|
||||
socketAdmin.user.sendValidationEmail({ uid: adminUid }, [regularUid], function (err) {
|
||||
assert.ifError(err);
|
||||
meta.config.requireEmailConfirmation = 0;
|
||||
done();
|
||||
@@ -290,7 +296,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should search users', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.search({uid: adminUid}, {query: 'reg', searchBy: 'username'}, function (err, data) {
|
||||
socketAdmin.user.search({ uid: adminUid }, { query: 'reg', searchBy: 'username' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.matchCount, 1);
|
||||
assert.equal(data.users[0].username, 'regular');
|
||||
@@ -300,7 +306,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should push unread notifications on reconnect', function (done) {
|
||||
var socketMeta = require('../src/socket.io/meta');
|
||||
socketMeta.reconnected({uid: 1}, {}, function (err) {
|
||||
socketMeta.reconnected({ uid: 1 }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -316,14 +322,14 @@ describe('socket.io', function () {
|
||||
|
||||
it('should return if uid is 0', function (done) {
|
||||
var socketMeta = require('../src/socket.io/meta');
|
||||
socketMeta.rooms.enter({uid: 0}, null, function (err) {
|
||||
socketMeta.rooms.enter({ uid: 0 }, null, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should join a room', function (done) {
|
||||
io.emit('meta.rooms.enter', {enter: 'recent_topics'}, function (err) {
|
||||
io.emit('meta.rooms.enter', { enter: 'recent_topics' }, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -338,7 +344,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should get server time', function (done) {
|
||||
var socketMeta = require('../src/socket.io/meta');
|
||||
socketMeta.getServerTime({uid: 1}, null, function (err, time) {
|
||||
socketMeta.getServerTime({ uid: 1 }, null, function (err, time) {
|
||||
assert.ifError(err);
|
||||
assert(time);
|
||||
done();
|
||||
@@ -346,7 +352,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should get daily analytics', function (done) {
|
||||
io.emit('admin.analytics.get', {graph: 'traffic', units: 'days'}, function (err, data) {
|
||||
io.emit('admin.analytics.get', { graph: 'traffic', units: 'days' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
assert(data.monthlyPageViews);
|
||||
@@ -355,7 +361,7 @@ describe('socket.io', function () {
|
||||
});
|
||||
|
||||
it('should get hourly analytics', function (done) {
|
||||
io.emit('admin.analytics.get', {graph: 'traffic', units: 'hours'}, function (err, data) {
|
||||
io.emit('admin.analytics.get', { graph: 'traffic', units: 'hours' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
assert(data.monthlyPageViews);
|
||||
@@ -365,7 +371,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should return error', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.before({uid: 10}, 'someMethod', {}, function (err) {
|
||||
socketAdmin.before({ uid: 10 }, 'someMethod', {}, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
@@ -374,12 +380,12 @@ describe('socket.io', function () {
|
||||
it('should get room stats', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
|
||||
io.emit('meta.rooms.enter', {enter: 'topic_1'}, function (err) {
|
||||
io.emit('meta.rooms.enter', { enter: 'topic_1' }, function (err) {
|
||||
assert.ifError(err);
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err) {
|
||||
socketAdmin.rooms.getAll({ uid: 10 }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err, data) {
|
||||
socketAdmin.rooms.getAll({ uid: 10 }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data.hasOwnProperty('onlineGuestCount'));
|
||||
assert(data.hasOwnProperty('onlineRegisteredCount'));
|
||||
@@ -397,12 +403,12 @@ describe('socket.io', function () {
|
||||
it('should get room stats', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
|
||||
io.emit('meta.rooms.enter', {enter: 'category_1'}, function (err) {
|
||||
io.emit('meta.rooms.enter', { enter: 'category_1' }, function (err) {
|
||||
assert.ifError(err);
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err) {
|
||||
socketAdmin.rooms.getAll({ uid: 10 }, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err, data) {
|
||||
socketAdmin.rooms.getAll({ uid: 10 }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.users.category, 1);
|
||||
done();
|
||||
@@ -414,7 +420,7 @@ describe('socket.io', function () {
|
||||
|
||||
it('should get admin search dictionary', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.getSearchDict({uid: adminUid}, {}, function (err, data) {
|
||||
socketAdmin.getSearchDict({ uid: adminUid }, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
assert(data[0].namespace);
|
||||
@@ -428,6 +434,5 @@ describe('socket.io', function () {
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
52
test/template-helpers.js
Normal file
52
test/template-helpers.js
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
|
||||
var db = require('./mocks/databasemock');
|
||||
var helpers = require('../public/src/modules/helpers');
|
||||
|
||||
describe('helpers', function () {
|
||||
it('should return false if item doesn\'t exist', function (done) {
|
||||
var flag = helpers.displayMenuItem({ navigation: [] }, 0);
|
||||
assert(!flag);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should return false if route is /users and privateUserInfo is on and user is not logged in', function (done) {
|
||||
var flag = helpers.displayMenuItem({
|
||||
navigation: [{ route: '/users' }],
|
||||
privateUserInfo: true,
|
||||
config: {
|
||||
loggedIn: false,
|
||||
},
|
||||
}, 0);
|
||||
assert(!flag);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false if route is /tags and privateTagListing is on and user is not logged in', function (done) {
|
||||
var flag = helpers.displayMenuItem({
|
||||
navigation: [{ route: '/tags' }],
|
||||
privateTagListing: true,
|
||||
config: {
|
||||
loggedIn: false,
|
||||
},
|
||||
}, 0);
|
||||
assert(!flag);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should stringify object', function (done) {
|
||||
var str = helpers.stringify({ a: 'herp < derp > and & quote "' });
|
||||
assert.equal(str, '{"a":"herp < derp > and & quote \\""}');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should escape html', function (done) {
|
||||
var str = helpers.escape('gdkfhgk < some > and &');
|
||||
assert.equal(str, 'gdkfhgk < some > and &');
|
||||
done();
|
||||
});
|
||||
});
|
||||
548
test/topics.js
548
test/topics.js
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var shim = require('../public/src/modules/translator.js');
|
||||
@@ -120,7 +120,7 @@ describe('new Translator(language)', function () {
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
var title = 'Test 1\\, 2\\, 3 %2 salmon';
|
||||
var key = "[[topic:composer.replying_to, " + title + "]]";
|
||||
var key = '[[topic:composer.replying_to, ' + title + ']]';
|
||||
return translator.translate(key).then(function (translated) {
|
||||
assert.strictEqual(translated, 'Replying to Test 1, 2, 3 %2 salmon');
|
||||
});
|
||||
@@ -130,7 +130,7 @@ describe('new Translator(language)', function () {
|
||||
var translator = Translator.create('en-GB');
|
||||
|
||||
var title = '3 % salmon';
|
||||
var key = "[[topic:composer.replying_to, " + title + "]]";
|
||||
var key = '[[topic:composer.replying_to, ' + title + ']]';
|
||||
return translator.translate(key).then(function (translated) {
|
||||
assert.strictEqual(translated, 'Replying to 3 % salmon');
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@ var helpers = require('./helpers');
|
||||
|
||||
|
||||
describe('Upload Controllers', function () {
|
||||
|
||||
var tid;
|
||||
var cid;
|
||||
var pid;
|
||||
@@ -28,15 +27,15 @@ describe('Upload Controllers', function () {
|
||||
category: function (next) {
|
||||
categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'Test category created by testing script'
|
||||
description: 'Test category created by testing script',
|
||||
}, next);
|
||||
},
|
||||
adminUid: function (next) {
|
||||
user.create({username: 'admin', password: 'barbar'}, next);
|
||||
user.create({ username: 'admin', password: 'barbar' }, next);
|
||||
},
|
||||
regularUid: function (next) {
|
||||
user.create({username: 'regular', password: 'zugzug'}, next);
|
||||
}
|
||||
user.create({ username: 'regular', password: 'zugzug' }, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@@ -45,7 +44,7 @@ describe('Upload Controllers', function () {
|
||||
regularUid = results.regularUid;
|
||||
cid = results.category.cid;
|
||||
|
||||
topics.post({uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
|
||||
topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) {
|
||||
tid = result.topicData.tid;
|
||||
pid = result.postData.pid;
|
||||
done(err);
|
||||
@@ -78,7 +77,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload an image to a post', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), {cid: cid}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -88,10 +87,24 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should resize and upload an image to a post', function (done) {
|
||||
var oldValue = meta.config.maximumImageWidth;
|
||||
meta.config.maximumImageWidth = 10;
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
assert(body[0].path);
|
||||
assert(body[0].url);
|
||||
meta.config.maximumImageWidth = oldValue;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should upload a file to a post', function (done) {
|
||||
meta.config.allowFileUploads = 1;
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/503.html'), {cid: cid}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/503.html'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -101,6 +114,36 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if topic thumbs are disabled', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 500);
|
||||
assert.equal(body.error, '[[error:topic-thumbnails-are-disabled]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if file is not image', function (done) {
|
||||
meta.config.allowTopicsThumbnail = 1;
|
||||
helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/503.html'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 500);
|
||||
assert.equal(body.error, '[[error:invalid-file]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should upload topic thumb', function (done) {
|
||||
meta.config.allowTopicsThumbnail = 1;
|
||||
helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
assert(body[0].path);
|
||||
assert(body[0].url);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -128,7 +171,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload category image', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/category/uploadpicture', path.join(__dirname, '../test/files/test.png'), {params: JSON.stringify({cid: cid})}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/category/uploadpicture', path.join(__dirname, '../test/files/test.png'), { params: JSON.stringify({ cid: cid }) }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -159,8 +202,6 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
222
test/user.js
222
test/user.js
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/*global require*/
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var utils = require('./../public/src/utils.js');
|
||||
@@ -30,15 +30,15 @@ describe('Utility Methods', function () {
|
||||
|
||||
describe('UUID generation', function () {
|
||||
it('return unique random value every time', function () {
|
||||
var uuid1 = utils.generateUUID(),
|
||||
uuid2 = utils.generateUUID();
|
||||
var uuid1 = utils.generateUUID();
|
||||
var uuid2 = utils.generateUUID();
|
||||
assert.notEqual(uuid1, uuid2, 'matches');
|
||||
});
|
||||
});
|
||||
|
||||
describe('cleanUpTag', function () {
|
||||
it('should cleanUp a tag', function (done) {
|
||||
var cleanedTag = utils.cleanUpTag(',\/#!$%\^\*;TaG1:{}=_`<>\'"~()?\|');
|
||||
var cleanedTag = utils.cleanUpTag(',/#!$%^*;TaG1:{}=_`<>\'"~()?|');
|
||||
assert.equal(cleanedTag, 'tag1');
|
||||
done();
|
||||
});
|
||||
@@ -70,8 +70,8 @@ describe('Utility Methods', function () {
|
||||
});
|
||||
|
||||
it('should shallow merge two objects', function (done) {
|
||||
var a = {foo: 1, cat1: 'ginger'};
|
||||
var b = {baz: 2, cat2: 'phoebe'};
|
||||
var a = { foo: 1, cat1: 'ginger' };
|
||||
var b = { baz: 2, cat2: 'phoebe' };
|
||||
var obj = utils.merge(a, b);
|
||||
assert.strictEqual(obj.foo, 1);
|
||||
assert.strictEqual(obj.baz, 2);
|
||||
@@ -151,10 +151,10 @@ describe('Utility Methods', function () {
|
||||
var currentHour = new Date().getHours();
|
||||
var hours = utils.getHoursArray();
|
||||
var index = hours.length - 1;
|
||||
for (var i = currentHour, ii = currentHour - 24; i > ii; i--) {
|
||||
for (var i = currentHour, ii = currentHour - 24; i > ii; i -= 1) {
|
||||
var hour = i < 0 ? 24 + i : i;
|
||||
assert.equal(hours[index], hour + ':00');
|
||||
-- index;
|
||||
index -= 1;
|
||||
}
|
||||
done();
|
||||
});
|
||||
@@ -164,12 +164,11 @@ describe('Utility Methods', function () {
|
||||
var days = utils.getDaysArray();
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
var index = 0;
|
||||
for(var x = 29; x >= 0; x--) {
|
||||
for (var x = 29; x >= 0; x -= 1) {
|
||||
var tmpDate = new Date(currentDay - (1000 * 60 * 60 * 24 * x));
|
||||
assert.equal(months[tmpDate.getMonth()] + ' ' + tmpDate.getDate(), days[index]);
|
||||
++ index;
|
||||
assert.equal(months[tmpDate.getMonth()] + ' ' + tmpDate.getDate(), days[index]);
|
||||
index += 1;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user