mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
specs for userData resolver
This commit is contained in:
parent
f0354c337f
commit
2eff1ab97b
@ -5,7 +5,7 @@ export default {
|
|||||||
const cypher = `
|
const cypher = `
|
||||||
MATCH (u:User { id: $id })
|
MATCH (u:User { id: $id })
|
||||||
WITH u AS user
|
WITH u AS user
|
||||||
MATCH (p:Post)
|
OPTIONAL MATCH (p:Post)
|
||||||
WHERE (p)<-[:COMMENTS]-(:Comment)<-[:WROTE]-(user)
|
WHERE (p)<-[:COMMENTS]-(:Comment)<-[:WROTE]-(user)
|
||||||
OR (user)-[:WROTE]->(p)
|
OR (user)-[:WROTE]->(p)
|
||||||
RETURN { user: properties(user), posts: collect(properties(p)) }
|
RETURN { user: properties(user), posts: collect(properties(p)) }
|
||||||
|
|||||||
164
backend/src/schema/resolvers/userData.spec.js
Normal file
164
backend/src/schema/resolvers/userData.spec.js
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
import Factory, { cleanDatabase } from '../../db/factories'
|
||||||
|
import { gql } from '../../helpers/jest'
|
||||||
|
import { getNeode, getDriver } from '../../db/neo4j'
|
||||||
|
import createServer from '../../server'
|
||||||
|
import { createTestClient } from 'apollo-server-testing'
|
||||||
|
|
||||||
|
let query, authenticatedUser
|
||||||
|
|
||||||
|
const driver = getDriver()
|
||||||
|
const neode = getNeode()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await cleanDatabase()
|
||||||
|
const user = await Factory.build('user', {
|
||||||
|
id: 'a-user',
|
||||||
|
name: 'John Doe',
|
||||||
|
slug: 'john-doe',
|
||||||
|
})
|
||||||
|
authenticatedUser = await user.toJson()
|
||||||
|
const { server } = createServer({
|
||||||
|
context: () => {
|
||||||
|
return {
|
||||||
|
driver,
|
||||||
|
neode,
|
||||||
|
user: authenticatedUser,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
query = createTestClient(server).query
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await cleanDatabase()
|
||||||
|
})
|
||||||
|
|
||||||
|
const userDataQuery = gql`
|
||||||
|
query($id: ID!) {
|
||||||
|
userData(id: $id) {
|
||||||
|
user {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
posts {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
content
|
||||||
|
comments {
|
||||||
|
content
|
||||||
|
author {
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
describe('resolvers/userData', () => {
|
||||||
|
const variables = { id: 'a-user' }
|
||||||
|
|
||||||
|
describe('given one user who did not write anything so far', () => {
|
||||||
|
it("returns the user's data and no posts", async () => {
|
||||||
|
await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
userData: {
|
||||||
|
user: {
|
||||||
|
id: 'a-user',
|
||||||
|
name: 'John Doe',
|
||||||
|
slug: 'john-doe',
|
||||||
|
},
|
||||||
|
posts: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('the user writes a post', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await Factory.build(
|
||||||
|
'post',
|
||||||
|
{
|
||||||
|
id: 'a-post',
|
||||||
|
title: 'A post',
|
||||||
|
content: 'A post',
|
||||||
|
},
|
||||||
|
{ authorId: 'a-user' },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the user's data and the post", async () => {
|
||||||
|
await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
userData: {
|
||||||
|
user: {
|
||||||
|
id: 'a-user',
|
||||||
|
name: 'John Doe',
|
||||||
|
slug: 'john-doe',
|
||||||
|
},
|
||||||
|
posts: [
|
||||||
|
{
|
||||||
|
id: 'a-post',
|
||||||
|
title: 'A post',
|
||||||
|
content: 'A post',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('the user comments another post', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await Factory.build('post', {
|
||||||
|
id: 'b-post',
|
||||||
|
title: 'B post',
|
||||||
|
content: 'B post',
|
||||||
|
})
|
||||||
|
await Factory.build(
|
||||||
|
'comment',
|
||||||
|
{
|
||||||
|
content: 'A comment to post B',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
postId: 'b-post',
|
||||||
|
authorId: 'a-user',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns the written post and the commented post', async () => {
|
||||||
|
await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
userData: {
|
||||||
|
user: {
|
||||||
|
id: 'a-user',
|
||||||
|
name: 'John Doe',
|
||||||
|
slug: 'john-doe',
|
||||||
|
},
|
||||||
|
posts: [
|
||||||
|
{
|
||||||
|
id: 'a-post',
|
||||||
|
title: 'A post',
|
||||||
|
content: 'A post',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'b-post',
|
||||||
|
title: 'B post',
|
||||||
|
content: 'B post',
|
||||||
|
comments: [
|
||||||
|
{
|
||||||
|
content: 'A comment to post B',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user