From e41042eeea1bc8da2cf24379465c740dcfe786b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 25 Jul 2023 11:11:31 -0400 Subject: [PATCH] test: fix tests since nid format changed --- src/flags.js | 9 +++++++-- test/flags.js | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/flags.js b/src/flags.js index 7a6c16233f..1c9dd3a5e1 100644 --- a/src/flags.js +++ b/src/flags.js @@ -680,6 +680,11 @@ Flags.update = async function (flagId, uid, changeset) { return allowed; }; + async function rescindNotifications(match) { + const nids = await db.getSortedSetScan({ key: 'notifications', match: `${match}*` }); + return notifications.rescind(nids); + } + // Retrieve existing flag data to compare for history-saving/reference purposes const tasks = []; for (const prop of Object.keys(changeset)) { @@ -692,10 +697,10 @@ Flags.update = async function (flagId, uid, changeset) { tasks.push(db.sortedSetAdd(`flags:byState:${changeset[prop]}`, now, flagId)); tasks.push(db.sortedSetRemove(`flags:byState:${current[prop]}`, flagId)); if (changeset[prop] === 'resolved' && meta.config['flags:actionOnResolve'] === 'rescind') { - tasks.push(notifications.rescind(`flag:${current.type}:${current.targetId}`)); + tasks.push(rescindNotifications(`flag:${current.type}:${current.targetId}`)); } if (changeset[prop] === 'rejected' && meta.config['flags:actionOnReject'] === 'rescind') { - tasks.push(notifications.rescind(`flag:${current.type}:${current.targetId}`)); + tasks.push(rescindNotifications(`flag:${current.type}:${current.targetId}`)); } } } else if (prop === 'assignee') { diff --git a/test/flags.js b/test/flags.js index 50f9c5543c..2912346519 100644 --- a/test/flags.js +++ b/test/flags.js @@ -514,40 +514,40 @@ describe('Flags', () => { it('should rescind notification if flag is resolved', async () => { let userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); await Flags.update(flagObj.flagId, adminUid, { state: 'resolved', }); userNotifs = await User.notifications.getAll(adminUid); - assert(!userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(!userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); }); it('should rescind notification if flag is rejected', async () => { let userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); await Flags.update(flagObj.flagId, adminUid, { state: 'rejected', }); userNotifs = await User.notifications.getAll(adminUid); - assert(!userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(!userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); }); it('should do nothing if flag is resolved but ACP action is not "rescind"', async () => { Meta.config['flags:actionOnResolve'] = ''; let userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); await Flags.update(flagObj.flagId, adminUid, { state: 'resolved', }); userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); delete Meta.config['flags:actionOnResolve']; }); @@ -556,14 +556,14 @@ describe('Flags', () => { Meta.config['flags:actionOnReject'] = ''; let userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); await Flags.update(flagObj.flagId, adminUid, { state: 'rejected', }); userNotifs = await User.notifications.getAll(adminUid); - assert(userNotifs.includes(`flag:post:${result.postData.pid}`)); + assert(userNotifs.includes(`flag:post:${result.postData.pid}:${uid1}`)); delete Meta.config['flags:actionOnReject']; });