mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Fixed an issue and added basic testing for (un)shout
This commit is contained in:
parent
656be9416a
commit
a292a522e9
97
src/resolvers/shout.spec.js
Normal file
97
src/resolvers/shout.spec.js
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import Factory from '../seed/factories'
|
||||||
|
import { GraphQLClient } from 'graphql-request'
|
||||||
|
import { host, login } from '../jest/helpers'
|
||||||
|
|
||||||
|
const factory = Factory()
|
||||||
|
let clientUser1, clientUser2
|
||||||
|
|
||||||
|
const mutationShoutPost = (id) => `
|
||||||
|
mutation {
|
||||||
|
shout(id: "${id}", type: Post)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const mutationUnshoutPost = (id) => `
|
||||||
|
mutation {
|
||||||
|
unshout(id: "${id}", type: Post)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await factory.create('User', {
|
||||||
|
id: 'u1',
|
||||||
|
email: 'test@example.org',
|
||||||
|
password: '1234'
|
||||||
|
})
|
||||||
|
await factory.create('User', {
|
||||||
|
id: 'u2',
|
||||||
|
email: 'test2@example.org',
|
||||||
|
password: '1234'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await factory.cleanDatabase()
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe('shout ', () => {
|
||||||
|
describe('(un)shout foreign post', () => {
|
||||||
|
let headersUser1, headersUser2
|
||||||
|
beforeEach(async () => {
|
||||||
|
headersUser1 = await login({ email: 'test@example.org', password: '1234' })
|
||||||
|
headersUser2 = await login({ email: 'test2@example.org', password: '1234' })
|
||||||
|
clientUser1 = new GraphQLClient(host, { headers: headersUser1 })
|
||||||
|
clientUser2 = new GraphQLClient(host, { headers: headersUser2 })
|
||||||
|
|
||||||
|
await clientUser1.request(`
|
||||||
|
mutation {
|
||||||
|
CreatePost(id: "p1", title: "Post Title 1", content: "Some Post Content 1") {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
await clientUser2.request(`
|
||||||
|
mutation {
|
||||||
|
CreatePost(id: "p2", title: "Post Title 2", content: "Some Post Content 2") {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('I shout a post of another user', async () => {
|
||||||
|
const res = await clientUser1.request(
|
||||||
|
mutationShoutPost('p2')
|
||||||
|
)
|
||||||
|
const expected = {
|
||||||
|
shout: true
|
||||||
|
}
|
||||||
|
expect(res).toMatchObject(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('I unshout a post of another user', async () => {
|
||||||
|
// shout
|
||||||
|
await clientUser1.request(
|
||||||
|
mutationShoutPost('p2')
|
||||||
|
)
|
||||||
|
const expected = {
|
||||||
|
unshout: true
|
||||||
|
}
|
||||||
|
// unshout
|
||||||
|
const res = await clientUser1.request(mutationUnshoutPost('p2'))
|
||||||
|
expect(res).toMatchObject(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('I can`t shout my own post', async () => {
|
||||||
|
const res = await clientUser1.request(
|
||||||
|
mutationShoutPost('p1')
|
||||||
|
)
|
||||||
|
const expected = {
|
||||||
|
shout: false
|
||||||
|
}
|
||||||
|
expect(res).toMatchObject(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -12,7 +12,7 @@ type Mutation {
|
|||||||
report(resource: Resource!, description: String): Report
|
report(resource: Resource!, description: String): Report
|
||||||
|
|
||||||
"Shout the given Type and ID"
|
"Shout the given Type and ID"
|
||||||
shout(id: ID!, type: ShoutTypeEnum): String! @cypher(statement: """
|
shout(id: ID!, type: ShoutTypeEnum): Boolean! @cypher(statement: """
|
||||||
MATCH (n {id: $id})<-[:WROTE]-(wu:User), (u:User {id: $cypherParams.currentUserId})
|
MATCH (n {id: $id})<-[:WROTE]-(wu:User), (u:User {id: $cypherParams.currentUserId})
|
||||||
WHERE $type IN labels(n) AND NOT wu.id = $cypherParams.currentUserId
|
WHERE $type IN labels(n) AND NOT wu.id = $cypherParams.currentUserId
|
||||||
MERGE (u)-[r:SHOUTED]->(n)
|
MERGE (u)-[r:SHOUTED]->(n)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user