mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Implement errors for to less or to many categories and test it
This commit is contained in:
parent
7847d6912c
commit
61344fc96b
5
backend/src/constants/categories.js
Normal file
5
backend/src/constants/categories.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// this file is duplicated in `backend/src/config/metadata.js` and `webapp/constants/metadata.js`
|
||||||
|
export default {
|
||||||
|
CATEGORIES_MIN: 1,
|
||||||
|
CATEGORIES_MAX: 3,
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ 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'
|
||||||
// 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'
|
||||||
@ -69,6 +70,12 @@ 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) {
|
||||||
|
throw new UserInputError('To Less Categories!')
|
||||||
|
}
|
||||||
|
if (categoryIds && categoryIds.length > categories.CATEGORIES_MAX) {
|
||||||
|
throw new UserInputError('To Many Categories!')
|
||||||
|
}
|
||||||
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) => {
|
||||||
|
|||||||
@ -416,12 +416,34 @@ describe('CreateGroup', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('`disabled` and `deleted` default to `false`', async () => {
|
it('"disabled" and "deleted" default to "false"', async () => {
|
||||||
const expected = { data: { CreateGroup: { disabled: false, deleted: false } } }
|
const expected = { data: { CreateGroup: { disabled: false, deleted: false } } }
|
||||||
await expect(mutate({ mutation: createGroupMutation, variables })).resolves.toMatchObject(
|
await expect(mutate({ mutation: createGroupMutation, variables })).resolves.toMatchObject(
|
||||||
expected,
|
expected,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('categories', () => {
|
||||||
|
describe('not even one', () => {
|
||||||
|
it('throws error: "To Less Categories!"', async () => {
|
||||||
|
const { errors } = await mutate({
|
||||||
|
mutation: createGroupMutation,
|
||||||
|
variables: { ...variables, categoryIds: null },
|
||||||
|
})
|
||||||
|
expect(errors[0]).toHaveProperty('message', 'To Less Categories!')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('four', () => {
|
||||||
|
it('throws error: "To Many Categories!"', async () => {
|
||||||
|
const { errors } = await mutate({
|
||||||
|
mutation: createGroupMutation,
|
||||||
|
variables: { ...variables, categoryIds: ['cat9', 'cat4', 'cat15', 'cat27'] },
|
||||||
|
})
|
||||||
|
expect(errors[0]).toHaveProperty('message', 'To Many Categories!')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user