mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: additional tests for #8569
This commit is contained in:
@@ -286,6 +286,66 @@ describe('Flags', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('(with sort)', () => {
|
||||||
|
before(async () => {
|
||||||
|
// Create a second flag to test sorting
|
||||||
|
const post = await Topics.reply({
|
||||||
|
tid: 1,
|
||||||
|
uid: uid1,
|
||||||
|
content: 'this is a reply -- flag me',
|
||||||
|
});
|
||||||
|
await Flags.create('post', post.pid, adminUid, 'another flag');
|
||||||
|
await Flags.create('post', 1, uid3, 'additional flag report');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return sorted flags latest first if no sort is passed in', async () => {
|
||||||
|
const payload = await Flags.list({
|
||||||
|
uid: adminUid,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(payload.flags.every((cur, idx) => {
|
||||||
|
if (idx === payload.flags.length - 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = payload.flags[idx + 1];
|
||||||
|
return parseInt(cur.datetime, 10) > parseInt(next.datetime, 10);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return sorted flags oldest first if "oldest" sort is passed in', async () => {
|
||||||
|
const payload = await Flags.list({
|
||||||
|
uid: adminUid,
|
||||||
|
sort: 'oldest',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(payload.flags.every((cur, idx) => {
|
||||||
|
if (idx === payload.flags.length - 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = payload.flags[idx + 1];
|
||||||
|
return parseInt(cur.datetime, 10) < parseInt(next.datetime, 10);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return flags with more reports first if "reports" sort is passed in', async () => {
|
||||||
|
const payload = await Flags.list({
|
||||||
|
uid: adminUid,
|
||||||
|
sort: 'reports',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(payload.flags.every((cur, idx) => {
|
||||||
|
if (idx === payload.flags.length - 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = payload.flags[idx + 1];
|
||||||
|
return parseInt(cur.heat, 10) >= parseInt(next.heat, 10);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.update()', function () {
|
describe('.update()', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user