mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-20 20:01:25 +00:00
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
import { create, cleanDatabase } from '../seed/factories'
|
|
import { testServerHost as host, authenticatedHeaders } from '../jest/helpers'
|
|
import { GraphQLClient } from 'graphql-request'
|
|
|
|
let client
|
|
let headers
|
|
beforeEach(async () => {
|
|
await create('user', { email: 'user@example.org', password: '1234' })
|
|
headers = await authenticatedHeaders({ email: 'user@example.org', password: '1234' })
|
|
client = new GraphQLClient(host, { headers })
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await cleanDatabase()
|
|
})
|
|
|
|
describe('slugify', () => {
|
|
describe('CreatePost', () => {
|
|
it('generates a slug based on the title', async () => {
|
|
const response = await client.request(`mutation {
|
|
CreatePost(
|
|
title: "I am a brand new post",
|
|
content: "Some content"
|
|
) { slug }
|
|
}`, { headers })
|
|
expect(response).toEqual({ CreatePost: { slug: 'i-am-a-brand-new-post' } })
|
|
})
|
|
|
|
describe('if slug exists', () => {
|
|
beforeEach(async () => {
|
|
await create('post', {
|
|
title: 'Pre-existing post',
|
|
slug: 'pre-existing-post'
|
|
}, { headers })
|
|
})
|
|
|
|
it('chooses another slug', async () => {
|
|
const response = await client.request(`mutation {
|
|
CreatePost(
|
|
title: "Pre-existing post",
|
|
content: "Some content"
|
|
) { slug }
|
|
}`)
|
|
expect(response).toEqual({ CreatePost: { slug: 'pre-existing-post-1' } })
|
|
})
|
|
|
|
describe('but if the client requested a slug', () => {
|
|
it('rejects CreatePost', async () => {
|
|
await expect(client.request(`mutation {
|
|
CreatePost(
|
|
title: "Pre-existing post",
|
|
content: "Some content",
|
|
slug: "pre-existing-post"
|
|
) { slug }
|
|
}`)
|
|
).rejects.toThrow('Unique constraint error')
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|