mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-04-06 01:25:31 +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`
|
// this file is duplicated in `backend/src/constants/metadata.js` and `webapp/constants/metadata.js`
|
||||||
export default {
|
export const CATEGORIES_MIN = 1
|
||||||
CATEGORIES_MIN: 1,
|
export const CATEGORIES_MAX = 3
|
||||||
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 sanitizeHtml from 'sanitize-html'
|
||||||
import linkifyHtml from 'linkifyjs/html'
|
import linkifyHtml from 'linkifyjs/html'
|
||||||
|
|
||||||
|
export const removeHtmlTags = (input) => {
|
||||||
|
return sanitizeHtml(input, {
|
||||||
|
allowedTags: [],
|
||||||
|
allowedAttributes: {},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const standardSanitizeHtmlOptions = {
|
const standardSanitizeHtmlOptions = {
|
||||||
allowedTags: [
|
allowedTags: [
|
||||||
'img',
|
'img',
|
||||||
|
|||||||
@ -1,12 +1,5 @@
|
|||||||
import LanguageDetect from 'languagedetect'
|
import LanguageDetect from 'languagedetect'
|
||||||
import sanitizeHtml from 'sanitize-html'
|
import { removeHtmlTags } from '../helpers/cleanHtml.js'
|
||||||
|
|
||||||
const removeHtmlTags = (input) => {
|
|
||||||
return sanitizeHtml(input, {
|
|
||||||
allowedTags: [],
|
|
||||||
allowedAttributes: {},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const setPostLanguage = (text) => {
|
const setPostLanguage = (text) => {
|
||||||
const lngDetector = new LanguageDetect()
|
const lngDetector = new LanguageDetect()
|
||||||
|
|||||||
@ -3,7 +3,9 @@ import { v4 as uuid } from 'uuid'
|
|||||||
// Wolle: import { isEmpty } from 'lodash'
|
// Wolle: import { isEmpty } from 'lodash'
|
||||||
import { UserInputError } from 'apollo-server'
|
import { UserInputError } from 'apollo-server'
|
||||||
import CONFIG from '../../config'
|
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'
|
// Wolle: import { mergeImage, deleteImage } from './images/images'
|
||||||
import Resolver from './helpers/Resolver'
|
import Resolver from './helpers/Resolver'
|
||||||
// Wolle: import { filterForMutedUsers } from './helpers/filterForMutedUsers'
|
// Wolle: import { filterForMutedUsers } from './helpers/filterForMutedUsers'
|
||||||
@ -70,12 +72,19 @@ export default {
|
|||||||
CreateGroup: async (_parent, params, context, _resolveInfo) => {
|
CreateGroup: async (_parent, params, context, _resolveInfo) => {
|
||||||
const { categoryIds } = params
|
const { categoryIds } = params
|
||||||
delete params.categoryIds
|
delete params.categoryIds
|
||||||
if (!categoryIds || categoryIds.length < categories.CATEGORIES_MIN) {
|
if (!categoryIds || categoryIds.length < CATEGORIES_MIN) {
|
||||||
throw new UserInputError('To Less Categories!')
|
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!')
|
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()
|
params.id = params.id || uuid()
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
|
|||||||
@ -13,6 +13,8 @@ let authenticatedUser
|
|||||||
let user
|
let user
|
||||||
|
|
||||||
const categoryIds = ['cat9', 'cat4', 'cat15']
|
const categoryIds = ['cat9', 'cat4', 'cat15']
|
||||||
|
const descriptionAddition100 =
|
||||||
|
' 123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789'
|
||||||
let variables = {}
|
let variables = {}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@ -116,7 +118,7 @@ describe('Group', () => {
|
|||||||
id: 'others-group',
|
id: 'others-group',
|
||||||
name: 'Uninteresting Group',
|
name: 'Uninteresting Group',
|
||||||
about: 'We will change nothing!',
|
about: 'We will change nothing!',
|
||||||
description: 'We love it like it is!?',
|
description: 'We love it like it is!?' + descriptionAddition100,
|
||||||
groupType: 'closed',
|
groupType: 'closed',
|
||||||
actionRadius: 'international',
|
actionRadius: 'international',
|
||||||
categoryIds,
|
categoryIds,
|
||||||
@ -129,7 +131,7 @@ describe('Group', () => {
|
|||||||
id: 'my-group',
|
id: 'my-group',
|
||||||
name: 'The Best Group',
|
name: 'The Best Group',
|
||||||
about: 'We will change the world!',
|
about: 'We will change the world!',
|
||||||
description: 'Some description',
|
description: 'Some description' + descriptionAddition100,
|
||||||
groupType: 'public',
|
groupType: 'public',
|
||||||
actionRadius: 'regional',
|
actionRadius: 'regional',
|
||||||
categoryIds,
|
categoryIds,
|
||||||
@ -363,7 +365,7 @@ describe('CreateGroup', () => {
|
|||||||
name: 'The Best Group',
|
name: 'The Best Group',
|
||||||
slug: 'the-group',
|
slug: 'the-group',
|
||||||
about: 'We will change the world!',
|
about: 'We will change the world!',
|
||||||
description: 'Some description',
|
description: 'Some description' + descriptionAddition100,
|
||||||
groupType: 'public',
|
groupType: 'public',
|
||||||
actionRadius: 'regional',
|
actionRadius: 'regional',
|
||||||
categoryIds,
|
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('categories', () => {
|
||||||
describe('not even one', () => {
|
describe('not even one', () => {
|
||||||
it('throws error: "To Less Categories!"', async () => {
|
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