Skip to content

Node.js based forum software built for the modern web

feat: additional tests for #8569

Julian Lame047b72c87f5
diff --git a/test/flags.js b/test/flags.js
index e975933c63..b0f6fcac1f 100644
--- a/test/flags.js
+++ b/test/flags.js
@@ -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 () {