Node.js based forum software built for the modern web
test: refactor tests to async/await
Barış Soner Uşaklı8382efb92873
diff --git a/src/api/notifications.js b/src/api/notifications.jsindex ad8dacd06c..98e00c87cb 100644--- a/src/api/notifications.js+++ b/src/api/notifications.js@@ -11,9 +11,7 @@ notificationsApi.list = async (caller) => {};notificationsApi.get = async (caller, { nid }) => {- let notification = await user.notifications.getNotifications([nid], caller.uid);- notification = notification.pop();-+ const [ notification ] = await user.notifications.getNotifications([nid], caller.uid);return { notification };};diff --git a/test/notifications.js b/test/notifications.jsindex 9596fd8112..9c854444bf 100644--- a/test/notifications.js+++ b/test/notifications.js@@ -408,46 +408,32 @@ describe('Notifications', () => {assert(data);});- it('should send welcome notification', (done) => {+ it('should send welcome notification', async () => {meta.config.welcomeNotification = 'welcome to the forums';- user.notifications.sendWelcomeNotification(uid, (err) => {- assert.ifError(err);- user.notifications.sendWelcomeNotification(uid, (err) => {- assert.ifError(err);- setTimeout(() => {- user.notifications.getAll(uid, '', (err, data) => {- meta.config.welcomeNotification = '';- assert.ifError(err);- assert(data.includes(`welcome_${uid}`), data);- done();- });- }, 2000);- });- });+ await user.notifications.sendWelcomeNotification(uid);+ await user.notifications.sendWelcomeNotification(uid);+ await sleep(2000);++ const data = await user.notifications.getAll(uid, '');+ meta.config.welcomeNotification = '';++ assert(data.includes(`welcome_${uid}`), data);});- it('should prune notifications', (done) => {- notifications.create({+ it('should prune notifications', async () => {+ const notification = await notifications.create({bodyShort: 'bodyShort',nid: 'tobedeleted',path: '/notification/path',- }, (err, notification) => {- assert.ifError(err);- notifications.prune((err) => {- assert.ifError(err);- const month = 2592000000;- db.sortedSetAdd('notifications', Date.now() - (2 * month), notification.nid, (err) => {- assert.ifError(err);- notifications.prune((err) => {- assert.ifError(err);- notifications.get(notification.nid, (err, data) => {- assert.ifError(err);- assert(!data);- done();- });- });- });- });});++ await notifications.prune();+ const month = 2592000000;+ await db.sortedSetAdd('notifications', Date.now() - (2 * month), notification.nid);++ await notifications.prune();++ const data = await notifications.get(notification.nid);+ assert(!data);});});