mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
chore: eslint prefer-arrow-callback
This commit is contained in:
committed by
Julian Lam
parent
707b55b6a5
commit
b56d9e12b5
@@ -14,12 +14,12 @@ var groups = require('../src/groups');
|
||||
var notifications = require('../src/notifications');
|
||||
var socketNotifications = require('../src/socket.io/notifications');
|
||||
|
||||
describe('Notifications', function () {
|
||||
describe('Notifications', () => {
|
||||
var uid;
|
||||
var notification;
|
||||
|
||||
before(function (done) {
|
||||
user.create({ username: 'poster' }, function (err, _uid) {
|
||||
before((done) => {
|
||||
user.create({ username: 'poster' }, (err, _uid) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
@@ -29,27 +29,27 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to create notification without a nid', function (done) {
|
||||
notifications.create({}, function (err) {
|
||||
it('should fail to create notification without a nid', (done) => {
|
||||
notifications.create({}, (err) => {
|
||||
assert.equal(err.message, '[[error:no-notification-id]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a notification', function (done) {
|
||||
it('should create a notification', (done) => {
|
||||
notifications.create({
|
||||
bodyShort: 'bodyShort',
|
||||
nid: 'notification_id',
|
||||
path: '/notification/path',
|
||||
pid: 1,
|
||||
}, function (err, _notification) {
|
||||
}, (err, _notification) => {
|
||||
notification = _notification;
|
||||
assert.ifError(err);
|
||||
assert(notification);
|
||||
db.exists(`notifications:${notification.nid}`, function (err, exists) {
|
||||
db.exists(`notifications:${notification.nid}`, (err, exists) => {
|
||||
assert.ifError(err);
|
||||
assert(exists);
|
||||
db.isSortedSetMember('notifications', notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember('notifications', notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert(isMember);
|
||||
done();
|
||||
@@ -58,22 +58,22 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return null if pid is same and importance is lower', function (done) {
|
||||
it('should return null if pid is same and importance is lower', (done) => {
|
||||
notifications.create({
|
||||
bodyShort: 'bodyShort',
|
||||
nid: 'notification_id',
|
||||
path: '/notification/path',
|
||||
pid: 1,
|
||||
importance: 1,
|
||||
}, function (err, notification) {
|
||||
}, (err, notification) => {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(notification, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get empty array', function (done) {
|
||||
notifications.getMultiple(null, function (err, data) {
|
||||
it('should get empty array', (done) => {
|
||||
notifications.getMultiple(null, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
assert.equal(data.length, 0);
|
||||
@@ -81,8 +81,8 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get notifications', function (done) {
|
||||
notifications.getMultiple([notification.nid], function (err, notificationsData) {
|
||||
it('should get notifications', (done) => {
|
||||
notifications.getMultiple([notification.nid], (err, notificationsData) => {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(notificationsData));
|
||||
assert(notificationsData[0]);
|
||||
@@ -91,12 +91,12 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should do nothing', function (done) {
|
||||
notifications.push(null, [], function (err) {
|
||||
it('should do nothing', (done) => {
|
||||
notifications.push(null, [], (err) => {
|
||||
assert.ifError(err);
|
||||
notifications.push({ nid: null }, [], function (err) {
|
||||
notifications.push({ nid: null }, [], (err) => {
|
||||
assert.ifError(err);
|
||||
notifications.push(notification, [], function (err) {
|
||||
notifications.push(notification, [], (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
@@ -104,11 +104,11 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should push a notification to uid', function (done) {
|
||||
notifications.push(notification, [uid], function (err) {
|
||||
it('should push a notification to uid', (done) => {
|
||||
notifications.push(notification, [uid], (err) => {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
setTimeout(() => {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert(isMember);
|
||||
done();
|
||||
@@ -117,11 +117,11 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should push a notification to a group', function (done) {
|
||||
notifications.pushGroup(notification, 'registered-users', function (err) {
|
||||
it('should push a notification to a group', (done) => {
|
||||
notifications.pushGroup(notification, 'registered-users', (err) => {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
setTimeout(() => {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert(isMember);
|
||||
done();
|
||||
@@ -130,11 +130,11 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should push a notification to groups', function (done) {
|
||||
notifications.pushGroups(notification, ['registered-users', 'administrators'], function (err) {
|
||||
it('should push a notification to groups', (done) => {
|
||||
notifications.pushGroups(notification, ['registered-users', 'administrators'], (err) => {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
setTimeout(() => {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert(isMember);
|
||||
done();
|
||||
@@ -143,23 +143,23 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not mark anything with invalid uid or nid', function (done) {
|
||||
socketNotifications.markRead({ uid: null }, null, function (err) {
|
||||
it('should not mark anything with invalid uid or nid', (done) => {
|
||||
socketNotifications.markRead({ uid: null }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
socketNotifications.markRead({ uid: uid }, null, function (err) {
|
||||
socketNotifications.markRead({ uid: uid }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark a notification read', function (done) {
|
||||
socketNotifications.markRead({ uid: uid }, notification.nid, function (err) {
|
||||
it('should mark a notification read', (done) => {
|
||||
socketNotifications.markRead({ uid: uid }, notification.nid, (err) => {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, true);
|
||||
done();
|
||||
@@ -168,33 +168,33 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not mark anything with invalid uid or nid', function (done) {
|
||||
socketNotifications.markUnread({ uid: null }, null, function (err) {
|
||||
it('should not mark anything with invalid uid or nid', (done) => {
|
||||
socketNotifications.markUnread({ uid: null }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
socketNotifications.markUnread({ uid: uid }, null, function (err) {
|
||||
socketNotifications.markUnread({ uid: uid }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if notification does not exist', function (done) {
|
||||
socketNotifications.markUnread({ uid: uid }, 123123, function (err) {
|
||||
it('should error if notification does not exist', (done) => {
|
||||
socketNotifications.markUnread({ uid: uid }, 123123, (err) => {
|
||||
assert.equal(err.message, '[[error:no-notification]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark a notification unread', function (done) {
|
||||
socketNotifications.markUnread({ uid: uid }, notification.nid, function (err) {
|
||||
it('should mark a notification unread', (done) => {
|
||||
socketNotifications.markUnread({ uid: uid }, notification.nid, (err) => {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, true);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
socketNotifications.getCount({ uid: uid }, null, function (err, count) {
|
||||
socketNotifications.getCount({ uid: uid }, null, (err, count) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(count, 1);
|
||||
done();
|
||||
@@ -204,13 +204,13 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark all notifications read', function (done) {
|
||||
socketNotifications.markAllRead({ uid: uid }, null, function (err) {
|
||||
it('should mark all notifications read', (done) => {
|
||||
socketNotifications.markAllRead({ uid: uid }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:unread`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, function (err, isMember) {
|
||||
db.isSortedSetMember(`uid:${uid}:notifications:read`, notification.nid, (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, true);
|
||||
done();
|
||||
@@ -219,14 +219,14 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not do anything', function (done) {
|
||||
socketNotifications.markAllRead({ uid: 1000 }, null, function (err) {
|
||||
it('should not do anything', (done) => {
|
||||
socketNotifications.markAllRead({ uid: 1000 }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should link to the first unread post in a watched topic', function (done) {
|
||||
it('should link to the first unread post in a watched topic', (done) => {
|
||||
var categories = require('../src/categories');
|
||||
var topics = require('../src/topics');
|
||||
var watcherUid;
|
||||
@@ -289,14 +289,14 @@ describe('Notifications', function () {
|
||||
assert.equal(`${nconf.get('relative_path')}/post/${pid}`, notifications.unread[0].path, 'the notification should link to the first unread post');
|
||||
next();
|
||||
},
|
||||
], function (err) {
|
||||
], (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get notification by nid', function (done) {
|
||||
socketNotifications.get({ uid: uid }, { nids: [notification.nid] }, function (err, data) {
|
||||
it('should get notification by nid', (done) => {
|
||||
socketNotifications.get({ uid: uid }, { nids: [notification.nid] }, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0].bodyShort, 'bodyShort');
|
||||
assert.equal(data[0].nid, 'notification_id');
|
||||
@@ -305,8 +305,8 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get user\'s notifications', function (done) {
|
||||
socketNotifications.get({ uid: uid }, {}, function (err, data) {
|
||||
it('should get user\'s notifications', (done) => {
|
||||
socketNotifications.get({ uid: uid }, {}, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.unread.length, 0);
|
||||
assert.equal(data.read[0].nid, 'notification_id');
|
||||
@@ -314,17 +314,17 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if not logged in', function (done) {
|
||||
socketNotifications.deleteAll({ uid: 0 }, null, function (err) {
|
||||
it('should error if not logged in', (done) => {
|
||||
socketNotifications.deleteAll({ uid: 0 }, null, (err) => {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete all user notifications', function (done) {
|
||||
socketNotifications.deleteAll({ uid: uid }, null, function (err) {
|
||||
it('should delete all user notifications', (done) => {
|
||||
socketNotifications.deleteAll({ uid: uid }, null, (err) => {
|
||||
assert.ifError(err);
|
||||
socketNotifications.get({ uid: uid }, {}, function (err, data) {
|
||||
socketNotifications.get({ uid: uid }, {}, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.unread.length, 0);
|
||||
assert.equal(data.read.length, 0);
|
||||
@@ -333,8 +333,8 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty with falsy uid', function (done) {
|
||||
user.notifications.get(0, function (err, data) {
|
||||
it('should return empty with falsy uid', (done) => {
|
||||
user.notifications.get(0, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.read.length, 0);
|
||||
assert.equal(data.unread.length, 0);
|
||||
@@ -342,19 +342,19 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all notifications and filter', function (done) {
|
||||
it('should get all notifications and filter', (done) => {
|
||||
var nid = 'willbefiltered';
|
||||
notifications.create({
|
||||
bodyShort: 'bodyShort',
|
||||
nid: nid,
|
||||
path: '/notification/path',
|
||||
type: 'post',
|
||||
}, function (err, notification) {
|
||||
}, (err, notification) => {
|
||||
assert.ifError(err);
|
||||
notifications.push(notification, [uid], function (err) {
|
||||
notifications.push(notification, [uid], (err) => {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
user.notifications.getAll(uid, 'post', function (err, nids) {
|
||||
setTimeout(() => {
|
||||
user.notifications.getAll(uid, 'post', (err, nids) => {
|
||||
assert.ifError(err);
|
||||
assert(nids.includes(nid));
|
||||
done();
|
||||
@@ -364,46 +364,46 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not get anything if notifications does not exist', function (done) {
|
||||
user.notifications.getNotifications(['doesnotexistnid1', 'doesnotexistnid2'], uid, function (err, data) {
|
||||
it('should not get anything if notifications does not exist', (done) => {
|
||||
user.notifications.getNotifications(['doesnotexistnid1', 'doesnotexistnid2'], uid, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(data, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get daily notifications', function (done) {
|
||||
user.notifications.getDailyUnread(uid, function (err, data) {
|
||||
it('should get daily notifications', (done) => {
|
||||
user.notifications.getDailyUnread(uid, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0].nid, 'willbefiltered');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array for invalid interval', function (done) {
|
||||
user.notifications.getUnreadInterval(uid, '2 aeons', function (err, data) {
|
||||
it('should return empty array for invalid interval', (done) => {
|
||||
user.notifications.getUnreadInterval(uid, '2 aeons', (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(data, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 0 for falsy uid', function (done) {
|
||||
user.notifications.getUnreadCount(0, function (err, count) {
|
||||
it('should return 0 for falsy uid', (done) => {
|
||||
user.notifications.getUnreadCount(0, (err, count) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(count, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not do anything if uid is falsy', function (done) {
|
||||
user.notifications.deleteAll(0, function (err) {
|
||||
it('should not do anything if uid is falsy', (done) => {
|
||||
user.notifications.deleteAll(0, (err) => {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send notification to followers of user when he posts', function (done) {
|
||||
it('should send notification to followers of user when he posts', (done) => {
|
||||
var followerUid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -433,21 +433,21 @@ describe('Notifications', function () {
|
||||
function (next) {
|
||||
user.notifications.getAll(followerUid, '', next);
|
||||
},
|
||||
], function (err, data) {
|
||||
], (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send welcome notification', function (done) {
|
||||
it('should send welcome notification', (done) => {
|
||||
meta.config.welcomeNotification = 'welcome to the forums';
|
||||
user.notifications.sendWelcomeNotification(uid, function (err) {
|
||||
user.notifications.sendWelcomeNotification(uid, (err) => {
|
||||
assert.ifError(err);
|
||||
user.notifications.sendWelcomeNotification(uid, function (err) {
|
||||
user.notifications.sendWelcomeNotification(uid, (err) => {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
user.notifications.getAll(uid, '', function (err, data) {
|
||||
setTimeout(() => {
|
||||
user.notifications.getAll(uid, '', (err, data) => {
|
||||
meta.config.welcomeNotification = '';
|
||||
assert.ifError(err);
|
||||
assert(data.includes(`welcome_${uid}`), data);
|
||||
@@ -458,21 +458,21 @@ describe('Notifications', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should prune notifications', function (done) {
|
||||
it('should prune notifications', (done) => {
|
||||
notifications.create({
|
||||
bodyShort: 'bodyShort',
|
||||
nid: 'tobedeleted',
|
||||
path: '/notification/path',
|
||||
}, function (err, notification) {
|
||||
}, (err, notification) => {
|
||||
assert.ifError(err);
|
||||
notifications.prune(function (err) {
|
||||
notifications.prune((err) => {
|
||||
assert.ifError(err);
|
||||
var week = 604800000;
|
||||
db.sortedSetAdd('notifications', Date.now() - (2 * week), notification.nid, function (err) {
|
||||
db.sortedSetAdd('notifications', Date.now() - (2 * week), notification.nid, (err) => {
|
||||
assert.ifError(err);
|
||||
notifications.prune(function (err) {
|
||||
notifications.prune((err) => {
|
||||
assert.ifError(err);
|
||||
notifications.get(notification.nid, function (err, data) {
|
||||
notifications.get(notification.nid, (err, data) => {
|
||||
assert.ifError(err);
|
||||
assert(!data);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user