mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement error for to short 'description' and test it
This commit is contained in:
parent
b5678f7c61
commit
117bd5e4e6
@ -1,5 +1,3 @@
|
||||
// this file is duplicated in `backend/src/config/metadata.js` and `webapp/constants/metadata.js`
|
||||
export default {
|
||||
CATEGORIES_MIN: 1,
|
||||
CATEGORIES_MAX: 3,
|
||||
}
|
||||
// this file is duplicated in `backend/src/constants/metadata.js` and `webapp/constants/metadata.js`
|
||||
export const CATEGORIES_MIN = 1
|
||||
export const CATEGORIES_MAX = 3
|
||||
|
||||
2
backend/src/constants/groups.js
Normal file
2
backend/src/constants/groups.js
Normal file
@ -0,0 +1,2 @@
|
||||
// this file is duplicated in `backend/src/constants/group.js` and `webapp/constants/group.js`
|
||||
export const DESCRIPTION_WITHOUT_HTML_LENGTH_MIN = 100 // with removed HTML tags
|
||||
@ -1,6 +1,13 @@
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
import linkifyHtml from 'linkifyjs/html'
|
||||
|
||||
export const removeHtmlTags = (input) => {
|
||||
return sanitizeHtml(input, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})
|
||||
}
|
||||
|
||||
const standardSanitizeHtmlOptions = {
|
||||
allowedTags: [
|
||||
'img',
|
||||
|
||||
@ -1,12 +1,5 @@
|
||||
import LanguageDetect from 'languagedetect'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
|
||||
const removeHtmlTags = (input) => {
|
||||
return sanitizeHtml(input, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})
|
||||
}
|
||||
import { removeHtmlTags } from '../helpers/cleanHtml.js'
|
||||
|
||||
const setPostLanguage = (text) => {
|
||||
const lngDetector = new LanguageDetect()
|
||||
|
||||
@ -3,7 +3,9 @@ import { v4 as uuid } from 'uuid'
|
||||
// Wolle: import { isEmpty } from 'lodash'
|
||||
import { UserInputError } from 'apollo-server'
|
||||
import CONFIG from '../../config'
|
||||
import categories from '../../constants/categories'
|
||||
import { CATEGORIES_MIN, CATEGORIES_MAX } from '../../constants/categories'
|
||||
import { DESCRIPTION_WITHOUT_HTML_LENGTH_MIN } from '../../constants/groups'
|
||||
import { removeHtmlTags } from '../../middleware/helpers/cleanHtml.js'
|
||||
// Wolle: import { mergeImage, deleteImage } from './images/images'
|
||||
import Resolver from './helpers/Resolver'
|
||||
// Wolle: import { filterForMutedUsers } from './helpers/filterForMutedUsers'
|
||||
@ -70,12 +72,19 @@ export default {
|
||||
CreateGroup: async (_parent, params, context, _resolveInfo) => {
|
||||
const { categoryIds } = params
|
||||
delete params.categoryIds
|
||||
if (!categoryIds || categoryIds.length < categories.CATEGORIES_MIN) {
|
||||
if (!categoryIds || categoryIds.length < CATEGORIES_MIN) {
|
||||
throw new UserInputError('To Less Categories!')
|
||||
}
|
||||
if (categoryIds && categoryIds.length > categories.CATEGORIES_MAX) {
|
||||
if (categoryIds && categoryIds.length > CATEGORIES_MAX) {
|
||||
throw new UserInputError('To Many Categories!')
|
||||
}
|
||||
if (
|
||||
params.description === undefined ||
|
||||
params.description === null ||
|
||||
removeHtmlTags(params.description).length < DESCRIPTION_WITHOUT_HTML_LENGTH_MIN
|
||||
) {
|
||||
throw new UserInputError('To Short Description!')
|
||||
}
|
||||
params.id = params.id || uuid()
|
||||
const session = context.driver.session()
|
||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||
|
||||
@ -13,6 +13,8 @@ let authenticatedUser
|
||||
let user
|
||||
|
||||
const categoryIds = ['cat9', 'cat4', 'cat15']
|
||||
const descriptionAddition100 =
|
||||
' 123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789'
|
||||
let variables = {}
|
||||
|
||||
beforeAll(async () => {
|
||||
@ -116,7 +118,7 @@ describe('Group', () => {
|
||||
id: 'others-group',
|
||||
name: 'Uninteresting Group',
|
||||
about: 'We will change nothing!',
|
||||
description: 'We love it like it is!?',
|
||||
description: 'We love it like it is!?' + descriptionAddition100,
|
||||
groupType: 'closed',
|
||||
actionRadius: 'international',
|
||||
categoryIds,
|
||||
@ -129,7 +131,7 @@ describe('Group', () => {
|
||||
id: 'my-group',
|
||||
name: 'The Best Group',
|
||||
about: 'We will change the world!',
|
||||
description: 'Some description',
|
||||
description: 'Some description' + descriptionAddition100,
|
||||
groupType: 'public',
|
||||
actionRadius: 'regional',
|
||||
categoryIds,
|
||||
@ -363,7 +365,7 @@ describe('CreateGroup', () => {
|
||||
name: 'The Best Group',
|
||||
slug: 'the-group',
|
||||
about: 'We will change the world!',
|
||||
description: 'Some description',
|
||||
description: 'Some description' + descriptionAddition100,
|
||||
groupType: 'public',
|
||||
actionRadius: 'regional',
|
||||
categoryIds,
|
||||
@ -423,6 +425,25 @@ describe('CreateGroup', () => {
|
||||
)
|
||||
})
|
||||
|
||||
describe('description', () => {
|
||||
describe('length without HTML', () => {
|
||||
describe('less then 100 chars', () => {
|
||||
it('throws error: "To Less Categories!"', async () => {
|
||||
const { errors } = await mutate({
|
||||
mutation: createGroupMutation,
|
||||
variables: {
|
||||
...variables,
|
||||
description:
|
||||
'0123456789' +
|
||||
'<a href="https://domain.org/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789">0123456789</a>',
|
||||
},
|
||||
})
|
||||
expect(errors[0]).toHaveProperty('message', 'To Short Description!')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('categories', () => {
|
||||
describe('not even one', () => {
|
||||
it('throws error: "To Less Categories!"', async () => {
|
||||
|
||||
3
webapp/constants/categories.js
Normal file
3
webapp/constants/categories.js
Normal file
@ -0,0 +1,3 @@
|
||||
// this file is duplicated in `backend/src/constants/metadata.js` and `webapp/constants/metadata.js`
|
||||
export const CATEGORIES_MIN = 1
|
||||
export const CATEGORIES_MAX = 3
|
||||
2
webapp/constants/groups.js
Normal file
2
webapp/constants/groups.js
Normal file
@ -0,0 +1,2 @@
|
||||
// this file is duplicated in `backend/src/constants/group.js` and `webapp/constants/group.js`
|
||||
export const DESCRIPTION_WITHOUT_HTML_LENGTH_MIN = 100 // with removed HTML tags
|
||||
Loading…
x
Reference in New Issue
Block a user