mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Refactor tests, going on
This commit is contained in:
parent
f380915b2c
commit
5ffaac193d
@ -1,20 +1,10 @@
|
||||
const transformReturnType = record => {
|
||||
return {
|
||||
...record.get('review').properties,
|
||||
report: record.get('report').properties,
|
||||
resource: {
|
||||
__typename: record.get('type'),
|
||||
...record.get('resource').properties,
|
||||
},
|
||||
}
|
||||
}
|
||||
import log from './helpers/databaseLogger'
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
review: async (_object, params, context, _resolveInfo) => {
|
||||
const { user: moderator, driver } = context
|
||||
|
||||
let createdRelationshipWithNestedAttributes = null // return value
|
||||
const session = driver.session()
|
||||
try {
|
||||
const cypher = `
|
||||
@ -25,10 +15,11 @@ export default {
|
||||
ON CREATE SET review.createdAt = $dateTime, review.updatedAt = review.createdAt
|
||||
ON MATCH SET review.updatedAt = $dateTime
|
||||
SET review.disable = $params.disable
|
||||
SET report.updatedAt = $dateTime, report.closed = $params.closed
|
||||
SET resource.disabled = review.disable
|
||||
SET report.updatedAt = $dateTime, report.disable = review.disable, report.closed = $params.closed
|
||||
SET resource.disabled = report.disable
|
||||
|
||||
RETURN review, report, resource, labels(resource)[0] AS type
|
||||
WITH review, report, resource {.*, __typename: labels(resource)[0]} AS finalResource
|
||||
RETURN review {.*, report: properties(report), resource: properties(finalResource)}
|
||||
`
|
||||
const reviewWriteTxResultPromise = session.writeTransaction(async txc => {
|
||||
const reviewTransactionResponse = await txc.run(cypher, {
|
||||
@ -36,16 +27,17 @@ export default {
|
||||
moderatorId: moderator.id,
|
||||
dateTime: new Date().toISOString(),
|
||||
})
|
||||
return reviewTransactionResponse.records.map(transformReturnType)
|
||||
log(reviewTransactionResponse)
|
||||
return reviewTransactionResponse.records.map(record =>
|
||||
record.get('review'),
|
||||
)
|
||||
})
|
||||
const txResult = await reviewWriteTxResultPromise
|
||||
if (!txResult[0]) return null
|
||||
createdRelationshipWithNestedAttributes = txResult[0]
|
||||
const [reviewed] = await reviewWriteTxResultPromise
|
||||
// Wolle console.log('reviewed: ', reviewed)
|
||||
return reviewed || null
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
|
||||
return createdRelationshipWithNestedAttributes
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@ export default {
|
||||
const { resourceId, reasonCategory, reasonDescription } = params
|
||||
const { driver, user } = context
|
||||
const session = driver.session()
|
||||
const reportWriteTxResultPromise = session.writeTransaction(async transaction => {
|
||||
const reportTransactionResponse = await transaction.run(
|
||||
const fileReportWriteTxResultPromise = session.writeTransaction(async transaction => {
|
||||
const fileReportTransactionResponse = await transaction.run(
|
||||
`
|
||||
MATCH (submitter:User {id: $submitterId})
|
||||
MATCH (resource {id: $resourceId})
|
||||
@ -38,19 +38,19 @@ export default {
|
||||
reasonDescription,
|
||||
},
|
||||
)
|
||||
log(reportTransactionResponse)
|
||||
// Wolle return reportTransactionResponse.records.map(transformReturnType)
|
||||
return reportTransactionResponse.records.map(record =>
|
||||
log(fileReportTransactionResponse)
|
||||
// Wolle return fileReportTransactionResponse.records.map(transformReturnType)
|
||||
return fileReportTransactionResponse.records.map(record =>
|
||||
record.get('filedReport'),
|
||||
)
|
||||
})
|
||||
try {
|
||||
const [createdRelationshipWithNestedAttributes] = await reportWriteTxResultPromise
|
||||
console.log('createdRelationshipWithNestedAttributes: ', createdRelationshipWithNestedAttributes)
|
||||
if (!createdRelationshipWithNestedAttributes) return null
|
||||
return createdRelationshipWithNestedAttributes
|
||||
const [filedReport] = await fileReportWriteTxResultPromise
|
||||
console.log('filedReport: ', filedReport)
|
||||
// Wolle if (!filedReport) return null
|
||||
return filedReport || null
|
||||
} finally {
|
||||
console.log('session.close !!!')
|
||||
console.log('fileReport: session.close !!!')
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
|
||||
@ -75,18 +75,20 @@ describe('file a report on a resource', () => {
|
||||
reasonDescription: 'Violates code of conduct !!!',
|
||||
}
|
||||
const reportsQuery = gql`
|
||||
query {
|
||||
reports(orderBy: createdAt_desc) {
|
||||
query($closed: Boolean) {
|
||||
reports(orderBy: createdAt_desc, closed: $closed) {
|
||||
id
|
||||
createdAt
|
||||
updatedAt
|
||||
rule
|
||||
disable
|
||||
closed
|
||||
resource {
|
||||
__typename
|
||||
... on User {
|
||||
id
|
||||
# Wolle FOLLOWSfiledUnclosedReportByCurrentUser
|
||||
followedByCurrentUser
|
||||
# Wolle filedUnclosedReportByCurrentUser
|
||||
# Wolle test followedByCurrentUser
|
||||
}
|
||||
... on Post {
|
||||
id
|
||||
@ -106,6 +108,31 @@ describe('file a report on a resource', () => {
|
||||
}
|
||||
}
|
||||
`
|
||||
const reviewMutation = gql`
|
||||
mutation($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
|
||||
review(resourceId: $resourceId, disable: $disable, closed: $closed) {
|
||||
createdAt
|
||||
resource {
|
||||
__typename
|
||||
... on User {
|
||||
id
|
||||
disabled
|
||||
}
|
||||
... on Post {
|
||||
id
|
||||
disabled
|
||||
}
|
||||
... on Comment {
|
||||
id
|
||||
disabled
|
||||
}
|
||||
}
|
||||
report {
|
||||
disable
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
beforeAll(async () => {
|
||||
await cleanDatabase()
|
||||
@ -150,6 +177,17 @@ describe('file a report on a resource', () => {
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
moderator = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
id: 'moderator-id',
|
||||
role: 'moderator',
|
||||
},
|
||||
{
|
||||
email: 'moderator@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
otherReportingUser = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
@ -192,7 +230,8 @@ describe('file a report on a resource', () => {
|
||||
|
||||
describe('valid resource', () => {
|
||||
describe('creates report', () => {
|
||||
it.only('which belongs to resource now reported by current user', async () => {
|
||||
it('which belongs to resource', async () => {
|
||||
// Wolle it('which belongs to resource now reported by current user', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: fileReportMutation,
|
||||
@ -212,7 +251,7 @@ describe('file a report on a resource', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('creates only one report for multiple reports on the same resource', async () => {
|
||||
it('only one report for multiple reports on the same resource', async () => {
|
||||
const firstReport = await mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
@ -222,24 +261,89 @@ describe('file a report on a resource', () => {
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
expect(firstReport.data.fileReport.id).toEqual(secondReport.data.fileReport.id)
|
||||
expect(firstReport.data.fileReport.reportId).toEqual(secondReport.data.fileReport.reportId)
|
||||
})
|
||||
|
||||
it('returns the rule for how the report was decided', async () => {
|
||||
it('with the rule for how the report will be decided', async () => {
|
||||
await mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
authenticatedUser = await moderator.toJson()
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
}),
|
||||
query({
|
||||
query: reportsQuery
|
||||
})
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
fileReport: {
|
||||
reports: [{
|
||||
rule: 'latestReviewUpdatedAtRules',
|
||||
},
|
||||
}],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
describe('with overtaken disabled from resource in disable property', () => {
|
||||
it('disable is false', async () => {
|
||||
await mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
authenticatedUser = await moderator.toJson()
|
||||
await expect(
|
||||
query({
|
||||
query: reportsQuery
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
reports: [{
|
||||
disable: false,
|
||||
}],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it.only('disable is true', async () => {
|
||||
// first time filling a report to enable a moderator the disable the resource
|
||||
await mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
authenticatedUser = await moderator.toJson()
|
||||
const review = await mutate({
|
||||
mutation: reviewMutation,
|
||||
variables: {
|
||||
resourceId: 'abusive-user-id',
|
||||
disable: true,
|
||||
closed: true,
|
||||
},
|
||||
})
|
||||
console.log('review: ', review)
|
||||
authenticatedUser = await currentUser.toJson()
|
||||
// second time filling a report to see if the "disabled is true" of the resource is overtaken
|
||||
await mutate({
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
// authenticatedUser = await moderator.toJson()
|
||||
// await expect(
|
||||
// query({
|
||||
// query: reportsQuery,
|
||||
// variables: { closed: false },
|
||||
// }),
|
||||
// ).resolves.toMatchObject({
|
||||
// data: {
|
||||
// reports: [{
|
||||
// disable: true,
|
||||
// }],
|
||||
// },
|
||||
// errors: undefined,
|
||||
// })
|
||||
})
|
||||
})
|
||||
|
||||
it.todo('creates multiple filed reports')
|
||||
})
|
||||
|
||||
@ -707,7 +811,7 @@ describe('file a report on a resource', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it.only('role "moderator" gets reports', async () => {
|
||||
it('role "moderator" gets reports', async () => {
|
||||
const expected = {
|
||||
reports: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@ -719,7 +823,7 @@ describe('file a report on a resource', () => {
|
||||
__typename: 'User',
|
||||
id: 'abusive-user-1',
|
||||
// Wolle filedUnclosedReportByCurrentUser: false,
|
||||
followedByCurrentUser: false,
|
||||
// Wolle test followedByCurrentUser: false,
|
||||
},
|
||||
filed: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
|
||||
@ -4,7 +4,6 @@ type REVIEWED {
|
||||
disable: Boolean!
|
||||
closed: Boolean!
|
||||
report: Report
|
||||
# @cypher(statement: "MATCH (report:Report)<-[this:REVIEWED]-(:User) RETURN report")
|
||||
moderator: User
|
||||
resource: ReviewedResource
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user