Helper message for backend tests failed by missing constraints in database

This commit is contained in:
Wolfgang Huß 2019-09-12 11:14:42 +02:00
parent 6ff532ab4a
commit 0f2398295b

View File

@ -28,7 +28,9 @@ beforeAll(() => {
beforeEach(async () => {
variables = {}
const admin = await factory.create('User', { role: 'admin' })
const admin = await factory.create('User', {
role: 'admin',
})
await factory.create('User', {
email: 'someone@example.org',
password: '1234',
@ -66,9 +68,16 @@ describe('slugifyMiddleware', () => {
})
it('generates a slug based on title', async () => {
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
await expect(
mutate({
mutation: createPostMutation,
variables,
}),
).resolves.toMatchObject({
data: {
CreatePost: { slug: 'i-am-a-brand-new-post' },
CreatePost: {
slug: 'i-am-a-brand-new-post',
},
},
})
})
@ -90,13 +99,22 @@ describe('slugifyMiddleware', () => {
content: 'Some content',
categoryIds,
}
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
data: { CreatePost: { slug: 'pre-existing-post-1' } },
await expect(
mutate({
mutation: createPostMutation,
variables,
}),
).resolves.toMatchObject({
data: {
CreatePost: {
slug: 'pre-existing-post-1',
},
},
})
})
describe('but if the client specifies a slug', () => {
it('rejects CreatePost', async () => {
it('rejects CreatePost (on FAIL Neo4j constraints may not defined in database)', async () => {
variables = {
...variables,
title: 'Pre-existing post',
@ -104,8 +122,17 @@ describe('slugifyMiddleware', () => {
slug: 'pre-existing-post',
categoryIds,
}
await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject({
errors: [{ message: 'Post with this slug already exists!' }],
await expect(
mutate({
mutation: createPostMutation,
variables,
}),
).resolves.toMatchObject({
errors: [
{
message: 'Post with this slug already exists!',
},
],
})
})
})
@ -156,31 +183,58 @@ describe('slugifyMiddleware', () => {
})
it('generates a slug based on name', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
data: { SignupVerification: { slug: 'i-am-a-user' } },
await expect(
mutate({
mutation,
variables,
}),
).resolves.toMatchObject({
data: {
SignupVerification: {
slug: 'i-am-a-user',
},
},
})
})
describe('if slug exists', () => {
beforeEach(async () => {
await factory.create('User', { name: 'I am a user', slug: 'i-am-a-user' })
await factory.create('User', {
name: 'I am a user',
slug: 'i-am-a-user',
})
})
it('chooses another slug', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({
mutation,
variables,
}),
).resolves.toMatchObject({
data: {
SignupVerification: { slug: 'i-am-a-user-1' },
SignupVerification: {
slug: 'i-am-a-user-1',
},
},
})
})
describe('but if the client specifies a slug', () => {
beforeEach(() => {
variables = { ...variables, slug: 'i-am-a-user' }
variables = {
...variables,
slug: 'i-am-a-user',
}
})
it('rejects SignupVerification', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
it('rejects SignupVerification (on FAIL Neo4j constraints may not defined in database)', async () => {
await expect(
mutate({
mutation,
variables,
}),
).resolves.toMatchObject({
errors: [
{
message: 'User with this slug already exists!',