mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
test: fix tests since nid format changed
This commit is contained in:
@@ -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') {
|
||||
|
||||
@@ -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'];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user