-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
822 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test/api/v3/integration/challenges/POST-challenge_flag.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { v4 as generateUUID } from 'uuid'; | ||
import { | ||
generateChallenge, | ||
createAndPopulateGroup, | ||
translate as t, | ||
} from '../../../../helpers/api-integration/v3'; | ||
|
||
describe('POST /challenges/:challengeId/flag', () => { | ||
let user; | ||
let challenge; | ||
|
||
beforeEach(async () => { | ||
const { group, groupLeader } = await createAndPopulateGroup({ | ||
groupDetails: { | ||
name: 'TestParty', | ||
type: 'party', | ||
privacy: 'private', | ||
}, | ||
members: 1, | ||
}); | ||
|
||
user = groupLeader; | ||
|
||
challenge = await generateChallenge(user, group); | ||
}); | ||
|
||
it('returns an error when challenge is not found', async () => { | ||
await expect(user.post(`/challenges/${generateUUID()}/flag`)) | ||
.to.eventually.be.rejected.and.eql({ | ||
code: 404, | ||
error: 'NotFound', | ||
message: t('challengeNotFound'), | ||
}); | ||
}); | ||
|
||
it('flags a challenge', async () => { | ||
const flagResult = await user.post(`/challenges/${challenge._id}/flag`); | ||
|
||
expect(flagResult.challenge.flags[user._id]).to.equal(true); | ||
expect(flagResult.challenge.flagCount).to.equal(1); | ||
}); | ||
|
||
it('flags a challenge with a higher count when from an admin', async () => { | ||
await user.update({ 'contributor.admin': true }); | ||
|
||
const flagResult = await user.post(`/challenges/${challenge._id}/flag`); | ||
|
||
expect(flagResult.challenge.flags[user._id]).to.equal(true); | ||
expect(flagResult.challenge.flagCount).to.equal(5); | ||
}); | ||
|
||
it('returns an error when user tries to flag a challenge that is already flagged', async () => { | ||
await user.post(`/challenges/${challenge._id}/flag`); | ||
|
||
await expect(user.post(`/challenges/${challenge._id}/flag`)) | ||
.to.eventually.be.rejected.and.eql({ | ||
code: 404, | ||
error: 'NotFound', | ||
message: t('messageChallengeFlagAlreadyReported'), | ||
}); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
test/api/v3/integration/challenges/POST-challenge_flag_clear.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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.update({ '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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,7 +366,6 @@ | |
} | ||
} | ||
} | ||
} | ||
</style> | ||
|
||
|
Oops, something went wrong.