mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-01-17 18:31:20 +00:00
Refactor filterBubble spec
This commit is contained in:
parent
2d67c5f172
commit
36ba4cc208
@ -1,10 +1,16 @@
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { host, login } from '../../jest/helpers'
|
||||
import { gql } from '../../jest/helpers'
|
||||
import Factory from '../../seed/factories'
|
||||
import { neode } from '../../bootstrap/neo4j'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
import createServer from '../../server'
|
||||
import { neode as getNeode, getDriver } from '../../bootstrap/neo4j'
|
||||
|
||||
const factory = Factory()
|
||||
const instance = neode()
|
||||
const neode = getNeode()
|
||||
const driver = getDriver()
|
||||
|
||||
let authenticatedUser
|
||||
let user
|
||||
let query
|
||||
|
||||
const currentUserParams = {
|
||||
id: 'u1',
|
||||
@ -26,24 +32,42 @@ const randomAuthorParams = {
|
||||
const categoryIds = ['cat9']
|
||||
|
||||
beforeEach(async () => {
|
||||
await Promise.all([
|
||||
const [currentUser, followedAuthor, randomAuthor] = await Promise.all([
|
||||
factory.create('User', currentUserParams),
|
||||
factory.create('User', followedAuthorParams),
|
||||
factory.create('User', randomAuthorParams),
|
||||
])
|
||||
await instance.create('Category', {
|
||||
user = currentUser
|
||||
await neode.create('Category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
})
|
||||
const [asYourself, asFollowedUser, asSomeoneElse] = await Promise.all([
|
||||
Factory().authenticateAs(currentUserParams),
|
||||
Factory().authenticateAs(followedAuthorParams),
|
||||
Factory().authenticateAs(randomAuthorParams),
|
||||
])
|
||||
await asYourself.follow({ id: 'u2', type: 'User' })
|
||||
await asFollowedUser.create('Post', { title: 'This is the post of a followed user', categoryIds })
|
||||
await asSomeoneElse.create('Post', { title: 'This is some random post', categoryIds })
|
||||
await currentUser.relateTo(followedAuthor, 'following')
|
||||
await factory.create('Post', {
|
||||
author: followedAuthor,
|
||||
title: 'This is the post of a followed user',
|
||||
categoryIds,
|
||||
})
|
||||
await factory.create('Post', {
|
||||
author: randomAuthor,
|
||||
title: 'This is some random post',
|
||||
categoryIds,
|
||||
})
|
||||
})
|
||||
|
||||
beforeAll(() => {
|
||||
const { server } = createServer({
|
||||
context: () => {
|
||||
return {
|
||||
driver,
|
||||
neode,
|
||||
user: authenticatedUser,
|
||||
}
|
||||
},
|
||||
})
|
||||
const client = createTestClient(server)
|
||||
query = client.query
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@ -52,33 +76,44 @@ afterEach(async () => {
|
||||
|
||||
describe('Filter posts by author is followed by sb.', () => {
|
||||
describe('given an authenticated user', () => {
|
||||
let authenticatedClient
|
||||
|
||||
beforeEach(async () => {
|
||||
const headers = await login(currentUserParams)
|
||||
authenticatedClient = new GraphQLClient(host, { headers })
|
||||
authenticatedUser = await user.toJson()
|
||||
})
|
||||
|
||||
describe('no filter bubble', () => {
|
||||
it('returns all posts', async () => {
|
||||
const query = '{ Post(filter: { }) { title } }'
|
||||
const postQuery = gql`
|
||||
{
|
||||
Post(filter: {}) {
|
||||
title
|
||||
}
|
||||
}
|
||||
`
|
||||
const expected = {
|
||||
Post: [
|
||||
{ title: 'This is some random post' },
|
||||
{ title: 'This is the post of a followed user' },
|
||||
],
|
||||
data: {
|
||||
Post: [
|
||||
{ title: 'This is some random post' },
|
||||
{ title: 'This is the post of a followed user' },
|
||||
],
|
||||
},
|
||||
}
|
||||
await expect(authenticatedClient.request(query)).resolves.toEqual(expected)
|
||||
await expect(query({ query: postQuery })).resolves.toMatchObject(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('filtering for posts of followed users only', () => {
|
||||
it('returns only posts authored by followed users', async () => {
|
||||
const query = '{ Post( filter: { author: { followedBy_some: { id: "u1" } } }) { title } }'
|
||||
const postQuery = gql`
|
||||
{
|
||||
Post(filter: { author: { followedBy_some: { id: "u1" } } }) {
|
||||
title
|
||||
}
|
||||
}
|
||||
`
|
||||
const expected = {
|
||||
Post: [{ title: 'This is the post of a followed user' }],
|
||||
data: { Post: [{ title: 'This is the post of a followed user' }] },
|
||||
}
|
||||
await expect(authenticatedClient.request(query)).resolves.toEqual(expected)
|
||||
await expect(query({ query: postQuery })).resolves.toMatchObject(expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user