|
|
@ -9,6 +9,8 @@ const nconf = require('nconf');
|
|
|
|
const request = require('request');
|
|
|
|
const request = require('request');
|
|
|
|
const util = require('util');
|
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sleep = util.promisify(setTimeout);
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('./mocks/databasemock');
|
|
|
|
const db = require('./mocks/databasemock');
|
|
|
|
const file = require('../src/file');
|
|
|
|
const file = require('../src/file');
|
|
|
|
const topics = require('../src/topics');
|
|
|
|
const topics = require('../src/topics');
|
|
|
@ -1498,35 +1500,15 @@ describe('Topic\'s', () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should mark topic notifications read', (done) => {
|
|
|
|
it('should mark topic notifications read', async () => {
|
|
|
|
async.waterfall([
|
|
|
|
await apiTopics.follow({ uid: adminUid }, { tid: tid });
|
|
|
|
function (next) {
|
|
|
|
const data = await topics.reply({ uid: uid, timestamp: Date.now(), content: 'some content', tid: tid });
|
|
|
|
socketTopics.follow({ uid: adminUid }, tid, next);
|
|
|
|
await sleep(2500);
|
|
|
|
},
|
|
|
|
let count = await User.notifications.getUnreadCount(adminUid);
|
|
|
|
function (next) {
|
|
|
|
assert.strictEqual(count, 1);
|
|
|
|
topics.reply({ uid: uid, timestamp: Date.now(), content: 'some content', tid: tid }, next);
|
|
|
|
await socketTopics.markTopicNotificationsRead({ uid: adminUid }, [tid]);
|
|
|
|
},
|
|
|
|
count = await User.notifications.getUnreadCount(adminUid);
|
|
|
|
function (data, next) {
|
|
|
|
assert.strictEqual(count, 0);
|
|
|
|
setTimeout(next, 2500);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
User.notifications.getUnreadCount(adminUid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (count, next) {
|
|
|
|
|
|
|
|
assert.equal(count, 1);
|
|
|
|
|
|
|
|
socketTopics.markTopicNotificationsRead({ uid: adminUid }, [tid], next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
User.notifications.getUnreadCount(adminUid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (count, next) {
|
|
|
|
|
|
|
|
assert.equal(count, 0);
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], (err) => {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should fail with invalid data', (done) => {
|
|
|
|
it('should fail with invalid data', (done) => {
|
|
|
@ -2161,37 +2143,29 @@ describe('Topic\'s', () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should error if not logged in', (done) => {
|
|
|
|
it('should error if not logged in', async () => {
|
|
|
|
socketTopics.changeWatching({ uid: 0 }, { tid: tid, type: 'ignore' }, (err) => {
|
|
|
|
try {
|
|
|
|
|
|
|
|
await apiTopics.ignore({ uid: 0 }, { tid: tid });
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
assert.equal(err.message, '[[error:not-logged-in]]');
|
|
|
|
assert.equal(err.message, '[[error:not-logged-in]]');
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should filter ignoring uids', (done) => {
|
|
|
|
it('should filter ignoring uids', async () => {
|
|
|
|
socketTopics.changeWatching({ uid: followerUid }, { tid: tid, type: 'ignore' }, (err) => {
|
|
|
|
await apiTopics.ignore({ uid: followerUid }, { tid: tid });
|
|
|
|
assert.ifError(err);
|
|
|
|
const uids = await topics.filterIgnoringUids(tid, [adminUid, followerUid]);
|
|
|
|
topics.filterIgnoringUids(tid, [adminUid, followerUid], (err, uids) => {
|
|
|
|
assert.equal(uids.length, 1);
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(uids[0], adminUid);
|
|
|
|
assert.equal(uids.length, 1);
|
|
|
|
|
|
|
|
assert.equal(uids[0], adminUid);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should error with invalid data', (done) => {
|
|
|
|
it('should error with topic that does not exist', async () => {
|
|
|
|
socketTopics.changeWatching({ uid: followerUid }, {}, (err) => {
|
|
|
|
try {
|
|
|
|
assert.equal(err.message, '[[error:invalid-data]]');
|
|
|
|
await apiTopics.follow({ uid: followerUid }, { tid: -1 });
|
|
|
|
done();
|
|
|
|
assert(false);
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
});
|
|
|
|
assert.equal(err.message, '[[error:no-topic]]');
|
|
|
|
|
|
|
|
}
|
|
|
|
it('should error with invalid type', (done) => {
|
|
|
|
|
|
|
|
socketTopics.changeWatching({ uid: followerUid }, { tid: tid, type: 'derp' }, (err) => {
|
|
|
|
|
|
|
|
assert.equal(err.message, '[[error:invalid-command]]');
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should follow topic', (done) => {
|
|
|
|
it('should follow topic', (done) => {
|
|
|
|