Skip to content

Commit

Permalink
feat: additional tests for #8569
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Aug 19, 2020
1 parent 360aa00 commit e047b72
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/flags.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit e047b72

Please sign in to comment.