From e7fbd169d9ede1a2641853ad58d734d852e325e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 4 Oct 2019 10:23:31 +0200 Subject: [PATCH] Get backend test to work with new properties --- backend/src/schema/resolvers/reports.js | 28 +++++++++++--------- backend/src/schema/resolvers/reports.spec.js | 9 +++++++ backend/src/schema/types/schema.gql | 5 ++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 79cae032b..d8698844f 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -2,19 +2,20 @@ import uuid from 'uuid/v4' export default { Mutation: { - report: async (parent, { id, description }, { driver, req, user }, resolveInfo) => { + report: async (_parent, { id, reasonCategory, description }, { driver, req, user }, _resolveInfo) => { const reportId = uuid() const session = driver.session() - const reportData = { + const reportProperties = { id: reportId, createdAt: new Date().toISOString(), - description: description, + reasonCategory, + description, } const reportQueryRes = await session.run( ` - match (u:User {id:$submitterId}) -[:REPORTED]->(report)-[:REPORTED]-> (resource {id: $resourceId}) - return labels(resource)[0] as label + MATCH (u:User {id:$submitterId})-[:REPORTED]->(report)-[:REPORTED]->(resource {id: $resourceId}) + RETURN labels(resource)[0] as label `, { resourceId: id, @@ -30,20 +31,21 @@ export default { if (rep) { throw new Error(rep.label) } + const res = await session.run( ` - MATCH (submitter:User {id: $userId}) - MATCH (resource {id: $resourceId}) - WHERE resource:User OR resource:Comment OR resource:Post - MERGE (report:Report {id: {reportData}.id }) - MERGE (resource)<-[:REPORTED]-(report) - MERGE (report)<-[:REPORTED]-(submitter) - RETURN report, submitter, resource, labels(resource)[0] as type + MATCH (submitter:User {id: $userId}) + MATCH (resource {id: $resourceId}) + WHERE resource:User OR resource:Comment OR resource:Post + CREATE (report:Report {reportProperties}) + MERGE (resource)<-[:REPORTED]-(report) + MERGE (report)<-[:REPORTED]-(submitter) + RETURN report, submitter, resource, labels(resource)[0] as type `, { resourceId: id, userId: user.id, - reportData, + reportProperties, }, ) diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index cfebbed81..228234ba1 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -121,6 +121,15 @@ describe('report', () => { }) }) + it('returns a date', async () => { + returnedObject = '{ createdAt }' + await expect(action()).resolves.toEqual(expect.objectContaining({ + report: { + createdAt: expect.any(String), + }, + })) + }) + it('returns the reason category', async () => { variables = { ...variables, diff --git a/backend/src/schema/types/schema.gql b/backend/src/schema/types/schema.gql index 0adb72d85..2bb3fdace 100644 --- a/backend/src/schema/types/schema.gql +++ b/backend/src/schema/types/schema.gql @@ -37,11 +37,12 @@ type Mutation { type Report { id: ID! + createdAt: String! + reasonCategory: String! + description: String! submitter: User @relation(name: "REPORTED", direction: "IN") - description: String type: String! @cypher(statement: "MATCH (resource)<-[:REPORTED]-(this) RETURN labels(resource)[0]") - createdAt: String comment: Comment @relation(name: "REPORTED", direction: "OUT") post: Post @relation(name: "REPORTED", direction: "OUT") user: User @relation(name: "REPORTED", direction: "OUT")