From 61a45d39eafbadddd9642473567dc0b74f280989 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Thu, 7 Mar 2019 17:43:00 -0300 Subject: [PATCH] Respond with reporter, resource --- src/resolvers/reports.js | 21 +++++++++-- src/resolvers/reports.spec.js | 71 ++++++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/resolvers/reports.js b/src/resolvers/reports.js index 79bab6646..7c60bb88f 100644 --- a/src/resolvers/reports.js +++ b/src/resolvers/reports.js @@ -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' + } } } } diff --git a/src/resolvers/reports.spec.js b/src/resolvers/reports.spec.js index 07cfc92eb..eebc335bc 100644 --- a/src/resolvers/reports.spec.js +++ b/src/resolvers/reports.spec.js @@ -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' } } + }) + }) }) }) })