mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
* remove some unused dependencies * update mongoose version * make common tests pass * Make unit tests pass * make api v3 integration tests pass * fix lint issues * fix issue with package-lock * fix(lint): we don't need no .js * fix(lint): update to latest config-habitrpg * chore(npm): update package locks * fix(test): replace deprecated fn * chore(package): update eslint-habitrpg again * fix(lint): server linting * fix(lint): client linting * fix(client): correct mangled common imports * chore(npm): update package-locks * fix(lint): punctuation, module --------- Co-authored-by: SabreCat <sabrecat@gmail.com> Co-authored-by: SabreCat <sabe@habitica.com>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
import { v4 as generateUUID } from 'uuid';
|
|
import {
|
|
generateChallenge,
|
|
createAndPopulateGroup,
|
|
translate as t,
|
|
} from '../../../../helpers/api-integration/v3';
|
|
|
|
describe('POST /challenges/:challengeId/clearflags', () => {
|
|
let admin;
|
|
let nonAdmin;
|
|
let challenge;
|
|
|
|
beforeEach(async () => {
|
|
const { group, groupLeader, members } = await createAndPopulateGroup({
|
|
groupDetails: {
|
|
name: 'TestParty',
|
|
type: 'party',
|
|
privacy: 'private',
|
|
},
|
|
members: 1,
|
|
});
|
|
|
|
admin = groupLeader;
|
|
[nonAdmin] = members;
|
|
|
|
await admin.updateOne({ 'permissions.moderator': true });
|
|
|
|
challenge = await generateChallenge(admin, group);
|
|
await admin.post(`/challenges/${challenge._id}/flag`);
|
|
});
|
|
|
|
it('returns error when non-admin attempts to clear flags', async () => {
|
|
await expect(nonAdmin.post(`/challenges/${generateUUID()}/clearflags`))
|
|
.to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: t('messageGroupChatAdminClearFlagCount'),
|
|
});
|
|
});
|
|
|
|
it('returns an error when challenge is not found', async () => {
|
|
await expect(admin.post(`/challenges/${generateUUID()}/clearflags`))
|
|
.to.eventually.be.rejected.and.eql({
|
|
code: 404,
|
|
error: 'NotFound',
|
|
message: t('challengeNotFound'),
|
|
});
|
|
});
|
|
|
|
it('clears flags and sets mod flag to false', async () => {
|
|
await nonAdmin.post(`/challenges/${challenge._id}/flag`);
|
|
const flagResult = await admin.post(`/challenges/${challenge._id}/clearflags`);
|
|
|
|
expect(flagResult.challenge.flagCount).to.eql(0);
|
|
expect(flagResult.challenge.flags).to.have.property(admin._id, false);
|
|
expect(flagResult.challenge.flags).to.have.property(nonAdmin._id, true);
|
|
});
|
|
});
|