Get backend test to work with new properties

This commit is contained in:
Wolfgang Huß 2019-10-04 10:23:31 +02:00
parent 5458d6640e
commit e7fbd169d9
3 changed files with 27 additions and 15 deletions

View File

@ -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,
},
)

View File

@ -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,

View File

@ -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")