Sketch a test

This commit is contained in:
Robert Schäfer 2019-02-15 00:50:37 +01:00 committed by Matt Rider
parent 151bb28429
commit 5230099e6b

View File

@ -0,0 +1,51 @@
import { request } from 'graphql-request'
import { create, cleanDatabase } from './seed/factories'
import { host } from './jest/helpers'
describe('filter for searchQuery', () => {
const query = (searchQuery) => {
return `
{
findPosts(filter: "${searchQuery}", limit: 10) {
title
}
}
`
}
describe('given some posts', () => {
beforeEach(async () => {
await create('post', {
title: 'Hamlet',
content: 'To be, or not to be: that is the question'
})
await create('post', {
title: 'Threepenny Opera',
content: 'And the shark, it has teeth, And it wears them in the face.'
})
})
afterEach(async () => {
await cleanDatabase()
})
describe('result set', () => {
describe('includes posts if search term', () => {
it('matches title', async () => {
const data = await request(host, query('Hamlet'))
expect(data).toEqual({findPosts: [{title: 'Hamlet'}]})
})
it('matches a part of the title', async () => {
const data = await request(host, query('let'))
expect(data).toEqual({findPosts: [{title: 'Hamlet'}]})
})
it('matches a part of the content', async () => {
const data = await request(host, query('shark'))
expect(data).toEqual({findPosts: [{title: 'Threepenny Opera'}]})
})
})
})
})
})