diff --git a/backend/src/middleware/userMiddleware.js b/backend/src/middleware/userMiddleware.js index 78f04638d..b3fc1bf2c 100644 --- a/backend/src/middleware/userMiddleware.js +++ b/backend/src/middleware/userMiddleware.js @@ -15,6 +15,6 @@ export default { const result = await resolve(root, args, context, info) await createOrUpdateLocations(args.id, args.locationName, context.driver) return result - }, + } } } diff --git a/backend/src/middleware/validation/index.js b/backend/src/middleware/validation/index.js index c84e111ee..de9be72e9 100644 --- a/backend/src/middleware/validation/index.js +++ b/backend/src/middleware/validation/index.js @@ -4,6 +4,7 @@ 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!`) @@ -14,6 +15,7 @@ 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') @@ -22,9 +24,8 @@ const validateUrl = async (resolve, root, args, context, info) => { export default { Mutation: { - // CreateUser: validateUsername, + CreateUser: validateUsername, UpdateUser: validateUsername, CreateSocialMedia: validateUrl } } - diff --git a/backend/src/middleware/userMiddleware.spec.js b/backend/src/resolvers/users.spec.js similarity index 71% rename from backend/src/middleware/userMiddleware.spec.js rename to backend/src/resolvers/users.spec.js index ef752c729..6d2b791e3 100644 --- a/backend/src/middleware/userMiddleware.spec.js +++ b/backend/src/resolvers/users.spec.js @@ -5,15 +5,15 @@ import Factory from '../seed/factories' const factory = Factory() let client -afterAll(async () => { +afterEach(async () => { await factory.cleanDatabase() }) -describe('userMiddleware', () => { - describe('create User', () => { +describe('users', () => { + describe('CreateUser', () => { const mutation = ` - mutation($id: ID, $password: String!, $email: String!) { - CreateUser(id: $id, password: $password, email: $email) { + mutation($id: ID, $name: String, $password: String!, $email: String!) { + CreateUser(id: $id, name: $name, password: $password, email: $email) { id } } @@ -22,6 +22,7 @@ describe('userMiddleware', () => { it('with password and email', async () => { const variables = { + name: 'John Doe', password: '123', email: '123@123.de' } @@ -35,34 +36,39 @@ describe('userMiddleware', () => { }) }) - describe('update User', () => { + describe('UpdateUser', () => { + beforeEach(async () => { + await factory.create('User', { id: 'u47', name: 'John Doe' }) + }) + const mutation = ` mutation($id: ID!, $name: String) { UpdateUser(id: $id, name: $name) { + id name } } ` client = new GraphQLClient(host) - // TODO why is this failing - it returns { UpdateUser: null } - that should not be - /* it('name within specifications', async () => { + it('name within specifications', async () => { const variables = { - id: 'u1', - name: 'Peter Lustig' + id: 'u47', + name: 'James Doe' } const expected = { UpdateUser: { - name: 'Peter Lustig' + id: 'u47', + name: 'James Doe' } } await expect(client.request(mutation, variables)) .resolves.toEqual(expected) - }) */ + }) it('with no name', async () => { const variables = { - id: 'u1' + id: 'u47' } const expected = 'Username must be at least 3 characters long!' await expect(client.request(mutation, variables)) @@ -71,7 +77,7 @@ describe('userMiddleware', () => { it('with too short name', async () => { const variables = { - id: 'u1', + id: 'u47', name: ' ' } const expected = 'Username must be at least 3 characters long!'