mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
Merge remote-tracking branch 'origin/master' into flagging-refactor
This commit is contained in:
@@ -703,7 +703,7 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('account post pages', function () {
|
||||
describe('account pages', function () {
|
||||
var helpers = require('./helpers');
|
||||
var jar;
|
||||
before(function (done) {
|
||||
@@ -785,6 +785,46 @@ describe('Controllers', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load notifications page', function (done) {
|
||||
var notifications = require('../src/notifications');
|
||||
var notifData = {
|
||||
bodyShort: '[[notifications:user_posted_to, test1, test2]]',
|
||||
bodyLong: 'some post content',
|
||||
pid: 1,
|
||||
path: '/post/' + 1,
|
||||
nid: 'new_post:tid:' + 1 + ':pid:' + 1 + ':uid:' + fooUid,
|
||||
tid: 1,
|
||||
from: fooUid,
|
||||
mergeId: 'notifications:user_posted_to|' + 1,
|
||||
topicTitle: 'topic title'
|
||||
};
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
notifications.create(notifData, next);
|
||||
},
|
||||
function (notification, next) {
|
||||
notifications.push(notification, fooUid, next);
|
||||
},
|
||||
function (next) {
|
||||
setTimeout(next, 2500);
|
||||
},
|
||||
function (next) {
|
||||
request(nconf.get('url') + '/api/notifications', {jar: jar, json: true}, next);
|
||||
},
|
||||
function (res, body, next) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
var notif = body.notifications[0];
|
||||
assert.equal(notif.bodyShort, notifData.bodyShort);
|
||||
assert.equal(notif.bodyLong, notifData.bodyLong);
|
||||
assert.equal(notif.pid, notifData.pid);
|
||||
assert.equal(notif.path, notifData.path);
|
||||
assert.equal(notif.nid, notifData.nid);
|
||||
next();
|
||||
}
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('account follow page', function () {
|
||||
|
||||
@@ -378,18 +378,44 @@ describe('Post\'s', function () {
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
replyPid = data.pid;
|
||||
socketPosts.movePost({uid: globalModUid}, {pid: replyPid, tid: moveTid}, next);
|
||||
next();
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
posts.getPostField(replyPid, 'tid', next);
|
||||
},
|
||||
function (tid, next) {
|
||||
assert(tid, moveTid);
|
||||
next();
|
||||
}
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should error if uid is not logged in', function (done) {
|
||||
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) {
|
||||
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) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should move a post', function (done) {
|
||||
socketPosts.movePost({uid: globalModUid}, {pid: replyPid, tid: moveTid}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(replyPid, 'tid', function (err, tid) {
|
||||
assert.ifError(err);
|
||||
assert(tid, moveTid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('flagging a post', function () {
|
||||
|
||||
@@ -872,10 +872,101 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('tags', function () {
|
||||
var socketTopics = require('../src/socket.io/topics');
|
||||
before(function (done) {
|
||||
async.parallel({
|
||||
topic1: function (next) {
|
||||
topics.post({uid: adminUid, tags: ['php', 'nosql', 'psql', 'nodebb'], title: 'topic title 1', content: 'topic 1 content', cid: topic.categoryId}, next);
|
||||
},
|
||||
topic2: function (next) {
|
||||
topics.post({uid: adminUid, tags: ['javascript', 'mysql', 'python', 'nodejs'], title: 'topic title 2', content: 'topic 2 content', cid: topic.categoryId}, next);
|
||||
}
|
||||
}, function (err, results) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array if query is falsy', function (done) {
|
||||
socketTopics.autocompleteTags({uid: adminUid}, {query: ''}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should autocomplete tags', function (done) {
|
||||
socketTopics.autocompleteTags({uid: adminUid}, {query: 'p'}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
['php', 'psql', 'python'].forEach(function (tag) {
|
||||
assert.notEqual(data.indexOf(tag), -1);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array if query is falsy', function (done) {
|
||||
socketTopics.searchTags({uid: adminUid}, {query: ''}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual([], data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search tags', function (done) {
|
||||
socketTopics.searchTags({uid: adminUid}, {query: 'no'}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
['nodebb', 'nodejs', 'nosql'].forEach(function (tag) {
|
||||
assert.notEqual(data.indexOf(tag), -1);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array if query is falsy', function (done) {
|
||||
socketTopics.searchAndLoadTags({uid: adminUid}, {query: ''}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.matchCount, 0);
|
||||
assert.equal(data.pageCount, 1);
|
||||
assert.deepEqual(data.tags, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search and load tags', function (done) {
|
||||
socketTopics.searchAndLoadTags({uid: adminUid}, {query: 'no'}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.matchCount, 3);
|
||||
assert.equal(data.pageCount, 1);
|
||||
var tagData = [
|
||||
{ value: 'nodebb', color: '', bgColor: '', score: 3 },
|
||||
{ value: 'nodejs', color: '', bgColor: '', score: 1 },
|
||||
{ value: 'nosql', color: '', bgColor: '', score: 1 }
|
||||
];
|
||||
assert.deepEqual(data.tags, tagData);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('shold return error if data is invalid', function (done) {
|
||||
socketTopics.loadMoreTags({uid: adminUid}, {after: 'asd'}, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more tags', function (done) {
|
||||
socketTopics.loadMoreTags({uid: adminUid}, {after: 0}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data.tags));
|
||||
assert.equal(data.nextStart, 100);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user