mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactor tests, next step
This commit is contained in:
parent
5ffaac193d
commit
3421afe4e0
@ -58,7 +58,7 @@ const reportMutation = gql`
|
||||
reasonCategory: $reasonCategory
|
||||
reasonDescription: $reasonDescription
|
||||
) {
|
||||
id
|
||||
reportId
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@ -28,9 +28,7 @@ export default {
|
||||
dateTime: new Date().toISOString(),
|
||||
})
|
||||
log(reviewTransactionResponse)
|
||||
return reviewTransactionResponse.records.map(record =>
|
||||
record.get('review'),
|
||||
)
|
||||
return reviewTransactionResponse.records.map(record => record.get('review'))
|
||||
})
|
||||
const [reviewed] = await reviewWriteTxResultPromise
|
||||
// Wolle console.log('reviewed: ', reviewed)
|
||||
|
||||
@ -1,15 +1,5 @@
|
||||
import log from './helpers/databaseLogger'
|
||||
|
||||
// Wolle const transformReturnType = record => {
|
||||
// return {
|
||||
// ...record.get('report').properties,
|
||||
// resource: {
|
||||
// __typename: record.get('type'),
|
||||
// ...record.get('resource').properties,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
fileReport: async (_parent, params, context, _resolveInfo) => {
|
||||
@ -27,8 +17,8 @@ export default {
|
||||
WITH submitter, resource, report
|
||||
CREATE (report)<-[filed:FILED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter)
|
||||
|
||||
WITH report, resource {.*, __typename: labels(resource)[0]} AS finalResource
|
||||
RETURN {reportId: report.id, resource: properties(finalResource)} AS filedReport
|
||||
WITH filed, report, resource {.*, __typename: labels(resource)[0]} AS finalResource
|
||||
RETURN filed {.*, reportId: report.id, resource: properties(finalResource)} AS filedReport
|
||||
`,
|
||||
{
|
||||
resourceId,
|
||||
@ -40,17 +30,13 @@ export default {
|
||||
)
|
||||
log(fileReportTransactionResponse)
|
||||
// Wolle return fileReportTransactionResponse.records.map(transformReturnType)
|
||||
return fileReportTransactionResponse.records.map(record =>
|
||||
record.get('filedReport'),
|
||||
)
|
||||
return fileReportTransactionResponse.records.map(record => record.get('filedReport'))
|
||||
})
|
||||
try {
|
||||
const [filedReport] = await fileReportWriteTxResultPromise
|
||||
console.log('filedReport: ', filedReport)
|
||||
// Wolle if (!filedReport) return null
|
||||
// Wolle console.log('filedReport: ', filedReport)
|
||||
return filedReport || null
|
||||
} finally {
|
||||
console.log('fileReport: session.close !!!')
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
@ -71,6 +57,7 @@ export default {
|
||||
orderByClause = ''
|
||||
}
|
||||
|
||||
// Wolle This should be only for open reports or?
|
||||
switch (params.reviewed) {
|
||||
case true:
|
||||
filterClause = 'AND ((report)<-[:REVIEWED]-(:User))'
|
||||
@ -82,7 +69,18 @@ export default {
|
||||
filterClause = ''
|
||||
}
|
||||
|
||||
if (params.closed) filterClause = 'AND report.closed = true'
|
||||
// Wolle console.log('params.closed: ', params.closed)
|
||||
// Wolle if (params.closed) filterClause = 'AND report.closed = true'
|
||||
switch (params.closed) {
|
||||
case true:
|
||||
filterClause = 'AND report.closed = true'
|
||||
break
|
||||
case false:
|
||||
filterClause = 'AND report.closed = false'
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
const offset =
|
||||
params.offset && typeof params.offset === 'number' ? `SKIP ${params.offset}` : ''
|
||||
|
||||
@ -52,6 +52,9 @@ describe('file a report on a resource', () => {
|
||||
reasonCategory: $reasonCategory
|
||||
reasonDescription: $reasonDescription
|
||||
) {
|
||||
createdAt
|
||||
reasonCategory
|
||||
reasonDescription
|
||||
reportId
|
||||
resource {
|
||||
__typename
|
||||
@ -231,7 +234,7 @@ describe('file a report on a resource', () => {
|
||||
describe('valid resource', () => {
|
||||
describe('creates report', () => {
|
||||
it('which belongs to resource', async () => {
|
||||
// Wolle it('which belongs to resource now reported by current user', async () => {
|
||||
// Wolle it('which belongs to resource now reported by current user', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: fileReportMutation,
|
||||
@ -261,7 +264,9 @@ describe('file a report on a resource', () => {
|
||||
mutation: fileReportMutation,
|
||||
variables: { ...variables, resourceId: 'abusive-user-id' },
|
||||
})
|
||||
expect(firstReport.data.fileReport.reportId).toEqual(secondReport.data.fileReport.reportId)
|
||||
expect(firstReport.data.fileReport.reportId).toEqual(
|
||||
secondReport.data.fileReport.reportId,
|
||||
)
|
||||
})
|
||||
|
||||
it('with the rule for how the report will be decided', async () => {
|
||||
@ -272,13 +277,15 @@ describe('file a report on a resource', () => {
|
||||
authenticatedUser = await moderator.toJson()
|
||||
await expect(
|
||||
query({
|
||||
query: reportsQuery
|
||||
})
|
||||
query: reportsQuery,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
reports: [{
|
||||
rule: 'latestReviewUpdatedAtRules',
|
||||
}],
|
||||
reports: [
|
||||
{
|
||||
rule: 'latestReviewUpdatedAtRules',
|
||||
},
|
||||
],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
@ -293,26 +300,28 @@ describe('file a report on a resource', () => {
|
||||
authenticatedUser = await moderator.toJson()
|
||||
await expect(
|
||||
query({
|
||||
query: reportsQuery
|
||||
query: reportsQuery,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
reports: [{
|
||||
disable: false,
|
||||
}],
|
||||
reports: [
|
||||
{
|
||||
disable: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it.only('disable is true', async () => {
|
||||
it('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({
|
||||
await mutate({
|
||||
mutation: reviewMutation,
|
||||
variables: {
|
||||
resourceId: 'abusive-user-id',
|
||||
@ -320,27 +329,28 @@ describe('file a report on a resource', () => {
|
||||
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,
|
||||
// })
|
||||
authenticatedUser = await moderator.toJson()
|
||||
await expect(
|
||||
query({
|
||||
query: reportsQuery,
|
||||
variables: { closed: false },
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
reports: [
|
||||
{
|
||||
disable: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
errors: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -385,7 +395,7 @@ describe('file a report on a resource', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('returns the submitter', async () => {
|
||||
it.skip('returns the submitter', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: fileReportMutation,
|
||||
@ -407,7 +417,7 @@ describe('file a report on a resource', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('returns a date', async () => {
|
||||
it('returns a createdAt', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: fileReportMutation,
|
||||
@ -436,11 +446,7 @@ describe('file a report on a resource', () => {
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
fileReport: {
|
||||
filed: [
|
||||
{
|
||||
reasonCategory: 'criminal_behavior_violation_german_law',
|
||||
},
|
||||
],
|
||||
reasonCategory: 'criminal_behavior_violation_german_law',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
@ -481,11 +487,7 @@ describe('file a report on a resource', () => {
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
fileReport: {
|
||||
filed: [
|
||||
{
|
||||
reasonDescription: 'My reason!',
|
||||
},
|
||||
],
|
||||
reasonDescription: 'My reason!',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
@ -505,11 +507,7 @@ describe('file a report on a resource', () => {
|
||||
).resolves.toMatchObject({
|
||||
data: {
|
||||
fileReport: {
|
||||
filed: [
|
||||
{
|
||||
reasonDescription: 'My reason !',
|
||||
},
|
||||
],
|
||||
reasonDescription: 'My reason !',
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
|
||||
@ -16,3 +16,15 @@ enum ReasonCategory {
|
||||
advert_products_services_commercial
|
||||
criminal_behavior_violation_german_law
|
||||
}
|
||||
|
||||
type FiledReport {
|
||||
createdAt: String!
|
||||
reasonCategory: ReasonCategory!
|
||||
reasonDescription: String!
|
||||
reportId: ID!
|
||||
resource: ReportedResource!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
fileReport(resourceId: ID!, reasonCategory: ReasonCategory!, reasonDescription: String!): FiledReport
|
||||
}
|
||||
@ -10,21 +10,12 @@ type Report {
|
||||
resource: ReportedResource
|
||||
}
|
||||
|
||||
type FiledReport {
|
||||
reportId: ID!
|
||||
resource: ReportedResource
|
||||
}
|
||||
|
||||
union ReportedResource = User | Post | Comment
|
||||
|
||||
enum ReportRule {
|
||||
latestReviewUpdatedAtRules
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
fileReport(resourceId: ID!, reasonCategory: ReasonCategory!, reasonDescription: String!): FiledReport
|
||||
}
|
||||
|
||||
type Query {
|
||||
reports(orderBy: ReportOrdering, first: Int, offset: Int, reviewed: Boolean, closed: Boolean): [Report]
|
||||
}
|
||||
|
||||
@ -44,10 +44,11 @@ export default {
|
||||
filterOptions() {
|
||||
return [
|
||||
{ label: this.$t('moderation.reports.filterLabel.all'), value: { reviewed: null } },
|
||||
{
|
||||
{ // Wolle This should be only for open reports or?
|
||||
label: this.$t('moderation.reports.filterLabel.unreviewed'),
|
||||
value: { reviewed: false },
|
||||
},
|
||||
// Wolle This should be only for open reports or?
|
||||
{ label: this.$t('moderation.reports.filterLabel.reviewed'), value: { reviewed: true } },
|
||||
{ label: this.$t('moderation.reports.filterLabel.closed'), value: { closed: true } },
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user