mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
@ulfgebhardt: The reason why the test case was failing is pretty obvious. You forgot to create a user that you want to update. If there is no user to update, then you get an empty response. @ulfgebhardt: I moved the spec also in the right directory. You're testing resolvers, so that's where I moved the `.spec` file.
32 lines
934 B
JavaScript
32 lines
934 B
JavaScript
import { UserInputError } from 'apollo-server'
|
|
|
|
const USERNAME_MIN_LENGTH = 3
|
|
|
|
const validateUsername = async (resolve, root, args, context, info) => {
|
|
if (args.name && args.name.length >= USERNAME_MIN_LENGTH) {
|
|
/* eslint-disable-next-line no-return-await */
|
|
return await resolve(root, args, context, info)
|
|
} else {
|
|
throw new UserInputError(`Username must be at least ${USERNAME_MIN_LENGTH} characters long!`)
|
|
}
|
|
}
|
|
|
|
const validateUrl = async (resolve, root, args, context, info) => {
|
|
const { url } = args
|
|
const isValid = url.match(/^(?:https?:\/\/)(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g)
|
|
if (isValid) {
|
|
/* eslint-disable-next-line no-return-await */
|
|
return await resolve(root, args, context, info)
|
|
} else {
|
|
throw new UserInputError('Input is not a URL')
|
|
}
|
|
}
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreateUser: validateUsername,
|
|
UpdateUser: validateUsername,
|
|
CreateSocialMedia: validateUrl
|
|
}
|
|
}
|