feat: additional tests for #8569

v1.18.x
Julian Lam 5 years ago
parent 360aa00d5a
commit e047b72c87

@ -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 () {

Loading…
Cancel
Save