mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Sketch a test
This commit is contained in:
parent
151bb28429
commit
5230099e6b
51
src/schema.graphql.spec.js
Normal file
51
src/schema.graphql.spec.js
Normal 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'}]})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user