Respond with reporter, resource

This commit is contained in:
Matt Rider 2019-03-07 17:43:00 -03:00
parent d00e4fad39
commit 61a45d39ea
2 changed files with 76 additions and 16 deletions

View File

@ -10,23 +10,38 @@ export default {
createdAt: (new Date()).toISOString(),
description: description
}
await session.run(`
const res = await session.run(`
MATCH (author:User {id: $userId})
MATCH (resource {id: $resourceId})
CREATE (report:Report $reportData)
MERGE (resource)<-[:REPORTED]-(report)
MERGE (report)<-[:REPORTED]-(author)
RETURN report
RETURN report, author, resource
`, {
resourceId: id,
userId: user.id,
reportData
}
)
const [{ report, author, resource }] = res.records.map(r => {
return {
report: r.get('report'),
author: r.get('author'),
resource: r.get('resource')
}
})
session.close()
console.log(report)
console.log(author)
// TODO: output Report compatible object
return reportData
return {
...report.properties,
reporter: author.properties,
user: resource.properties,
type: 'blablabla'
}
}
}
}

View File

@ -5,8 +5,12 @@ import { host, login } from '../jest/helpers'
const factory = Factory()
describe('report', () => {
let mutation
let headers
beforeEach(async () => {
headers = {}
await factory.create('User', {
id: 'u1',
email: 'test@example.org',
password: '1234'
})
@ -16,25 +20,20 @@ describe('report', () => {
role: 'user',
email: 'abusive-user@example.org'
})
mutation = `
mutation {
report(
id: "u2",
description: "I don't like this user"
) { description }
}
`
})
afterEach(async () => {
await factory.cleanDatabase()
})
const mutation = `
mutation {
report(
id: "u2",
description: "I don't like this user"
) { description }
}
`
let headers
beforeEach(async () => {
headers = {}
})
let client
const action = () => {
client = new GraphQLClient(host, { headers })
@ -56,6 +55,52 @@ describe('report', () => {
report: { description: 'I don\'t like this user' }
})
})
it('returns the reporter', async () => {
mutation = `
mutation {
report(
id: "u2",
description: "I don't like this user"
) { reporter {
email
} }
}
`
await expect(action()).resolves.toEqual({
report: { reporter: { email: 'test@example.org' } }
})
})
it('returns type', async () => {
mutation = `
mutation {
report(
id: "u2",
description: "I don't like this user"
) { type }
}
`
await expect(action()).resolves.toEqual({
report: { type: 'User' }
})
})
it('returns user', async () => {
mutation = `
mutation {
report(
id: "u2",
description: "I don't like this user"
) { user {
name
} }
}
`
await expect(action()).resolves.toEqual({
report: { user: { name: 'abusive-user' } }
})
})
})
})
})