mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
add max length validations for summary in challenge create and update… (#14053)
* add max length validations for summary in challenge create and update controllers * Add validation to group APIs * fix lint errors * add validation to group plan * fix imports * add tests * add max length validations for summary in challenge create and update controllers * Add validation to group APIs * fix lint errors * add validation to group plan * fix imports * add tests * lint checks
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
createAndPopulateGroup,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { MAX_SUMMARY_SIZE_FOR_CHALLENGES } from '../../../../../website/common/script/constants';
|
||||
|
||||
describe('POST /challenges', () => {
|
||||
it('returns error when group is empty', async () => {
|
||||
@@ -60,6 +61,22 @@ describe('POST /challenges', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('return error when creating a challenge with summary with greater than MAX_SUMMARY_SIZE_FOR_CHALLENGES characters', async () => {
|
||||
const user = await generateUser();
|
||||
const summary = 'A'.repeat(MAX_SUMMARY_SIZE_FOR_CHALLENGES + 1);
|
||||
const group = createAndPopulateGroup({
|
||||
members: 1,
|
||||
});
|
||||
await expect(user.post('/challenges', {
|
||||
group: group._id,
|
||||
summary,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
});
|
||||
});
|
||||
|
||||
context('Creating a challenge for a valid group', () => {
|
||||
let groupLeader;
|
||||
let group;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
createAndPopulateGroup,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { MAX_SUMMARY_SIZE_FOR_CHALLENGES } from '../../../../../website/common/script/constants';
|
||||
|
||||
describe('PUT /challenges/:challengeId', () => {
|
||||
let privateGuild; let user; let nonMember; let challenge; let
|
||||
@@ -91,4 +92,15 @@ describe('PUT /challenges/:challengeId', () => {
|
||||
expect(res.name).to.equal('New Challenge Name');
|
||||
expect(res.description).to.equal('New challenge description.');
|
||||
});
|
||||
|
||||
it('return error when challenge summary is greater than MAX_SUMMARY_SIZE_FOR_CHALLENGES characters', async () => {
|
||||
const summary = 'A'.repeat(MAX_SUMMARY_SIZE_FOR_CHALLENGES + 1);
|
||||
await expect(user.put(`/challenges/${challenge._id}`, {
|
||||
summary,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('invalidReqParams'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user