mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fix test case, move spec to the right location
@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.
This commit is contained in:
parent
47d7c615a5
commit
81a26e14ff
@ -15,6 +15,6 @@ export default {
|
||||
const result = await resolve(root, args, context, info)
|
||||
await createOrUpdateLocations(args.id, args.locationName, context.driver)
|
||||
return result
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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!'
|
||||
Loading…
x
Reference in New Issue
Block a user