Refactor tests, next step

This commit is contained in:
Wolfgang Huß 2020-02-19 13:27:01 +01:00
parent 5ffaac193d
commit 3421afe4e0
7 changed files with 78 additions and 80 deletions

View File

@ -58,7 +58,7 @@ const reportMutation = gql`
reasonCategory: $reasonCategory reasonCategory: $reasonCategory
reasonDescription: $reasonDescription reasonDescription: $reasonDescription
) { ) {
id reportId
} }
} }
` `

View File

@ -28,9 +28,7 @@ export default {
dateTime: new Date().toISOString(), dateTime: new Date().toISOString(),
}) })
log(reviewTransactionResponse) log(reviewTransactionResponse)
return reviewTransactionResponse.records.map(record => return reviewTransactionResponse.records.map(record => record.get('review'))
record.get('review'),
)
}) })
const [reviewed] = await reviewWriteTxResultPromise const [reviewed] = await reviewWriteTxResultPromise
// Wolle console.log('reviewed: ', reviewed) // Wolle console.log('reviewed: ', reviewed)

View File

@ -1,15 +1,5 @@
import log from './helpers/databaseLogger' 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 { export default {
Mutation: { Mutation: {
fileReport: async (_parent, params, context, _resolveInfo) => { fileReport: async (_parent, params, context, _resolveInfo) => {
@ -27,8 +17,8 @@ export default {
WITH submitter, resource, report WITH submitter, resource, report
CREATE (report)<-[filed:FILED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter) CREATE (report)<-[filed:FILED {createdAt: $createdAt, reasonCategory: $reasonCategory, reasonDescription: $reasonDescription}]-(submitter)
WITH report, resource {.*, __typename: labels(resource)[0]} AS finalResource WITH filed, report, resource {.*, __typename: labels(resource)[0]} AS finalResource
RETURN {reportId: report.id, resource: properties(finalResource)} AS filedReport RETURN filed {.*, reportId: report.id, resource: properties(finalResource)} AS filedReport
`, `,
{ {
resourceId, resourceId,
@ -40,17 +30,13 @@ export default {
) )
log(fileReportTransactionResponse) log(fileReportTransactionResponse)
// Wolle return fileReportTransactionResponse.records.map(transformReturnType) // Wolle return fileReportTransactionResponse.records.map(transformReturnType)
return fileReportTransactionResponse.records.map(record => return fileReportTransactionResponse.records.map(record => record.get('filedReport'))
record.get('filedReport'),
)
}) })
try { try {
const [filedReport] = await fileReportWriteTxResultPromise const [filedReport] = await fileReportWriteTxResultPromise
console.log('filedReport: ', filedReport) // Wolle console.log('filedReport: ', filedReport)
// Wolle if (!filedReport) return null
return filedReport || null return filedReport || null
} finally { } finally {
console.log('fileReport: session.close !!!')
session.close() session.close()
} }
}, },
@ -71,6 +57,7 @@ export default {
orderByClause = '' orderByClause = ''
} }
// Wolle This should be only for open reports or?
switch (params.reviewed) { switch (params.reviewed) {
case true: case true:
filterClause = 'AND ((report)<-[:REVIEWED]-(:User))' filterClause = 'AND ((report)<-[:REVIEWED]-(:User))'
@ -82,7 +69,18 @@ export default {
filterClause = '' 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 = const offset =
params.offset && typeof params.offset === 'number' ? `SKIP ${params.offset}` : '' params.offset && typeof params.offset === 'number' ? `SKIP ${params.offset}` : ''

View File

@ -52,6 +52,9 @@ describe('file a report on a resource', () => {
reasonCategory: $reasonCategory reasonCategory: $reasonCategory
reasonDescription: $reasonDescription reasonDescription: $reasonDescription
) { ) {
createdAt
reasonCategory
reasonDescription
reportId reportId
resource { resource {
__typename __typename
@ -231,7 +234,7 @@ describe('file a report on a resource', () => {
describe('valid resource', () => { describe('valid resource', () => {
describe('creates report', () => { describe('creates report', () => {
it('which belongs to resource', async () => { 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( await expect(
mutate({ mutate({
mutation: fileReportMutation, mutation: fileReportMutation,
@ -261,7 +264,9 @@ describe('file a report on a resource', () => {
mutation: fileReportMutation, mutation: fileReportMutation,
variables: { ...variables, resourceId: 'abusive-user-id' }, 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 () => { 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() authenticatedUser = await moderator.toJson()
await expect( await expect(
query({ query({
query: reportsQuery query: reportsQuery,
}) }),
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { data: {
reports: [{ reports: [
rule: 'latestReviewUpdatedAtRules', {
}], rule: 'latestReviewUpdatedAtRules',
},
],
}, },
errors: undefined, errors: undefined,
}) })
@ -293,26 +300,28 @@ describe('file a report on a resource', () => {
authenticatedUser = await moderator.toJson() authenticatedUser = await moderator.toJson()
await expect( await expect(
query({ query({
query: reportsQuery query: reportsQuery,
}), }),
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { data: {
reports: [{ reports: [
disable: false, {
}], disable: false,
},
],
}, },
errors: undefined, 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 // first time filling a report to enable a moderator the disable the resource
await mutate({ await mutate({
mutation: fileReportMutation, mutation: fileReportMutation,
variables: { ...variables, resourceId: 'abusive-user-id' }, variables: { ...variables, resourceId: 'abusive-user-id' },
}) })
authenticatedUser = await moderator.toJson() authenticatedUser = await moderator.toJson()
const review = await mutate({ await mutate({
mutation: reviewMutation, mutation: reviewMutation,
variables: { variables: {
resourceId: 'abusive-user-id', resourceId: 'abusive-user-id',
@ -320,30 +329,31 @@ describe('file a report on a resource', () => {
closed: true, closed: true,
}, },
}) })
console.log('review: ', review)
authenticatedUser = await currentUser.toJson() authenticatedUser = await currentUser.toJson()
// second time filling a report to see if the "disabled is true" of the resource is overtaken // second time filling a report to see if the "disabled is true" of the resource is overtaken
await mutate({ await mutate({
mutation: fileReportMutation, mutation: fileReportMutation,
variables: { ...variables, resourceId: 'abusive-user-id' }, variables: { ...variables, resourceId: 'abusive-user-id' },
}) })
// authenticatedUser = await moderator.toJson() authenticatedUser = await moderator.toJson()
// await expect( await expect(
// query({ query({
// query: reportsQuery, query: reportsQuery,
// variables: { closed: false }, variables: { closed: false },
// }), }),
// ).resolves.toMatchObject({ ).resolves.toMatchObject({
// data: { data: {
// reports: [{ reports: [
// disable: true, {
// }], disable: true,
// }, },
// errors: undefined, ],
// }) },
errors: undefined,
})
}) })
}) })
it.todo('creates multiple filed reports') it.todo('creates multiple filed reports')
}) })
@ -385,7 +395,7 @@ describe('file a report on a resource', () => {
}) })
}) })
it('returns the submitter', async () => { it.skip('returns the submitter', async () => {
await expect( await expect(
mutate({ mutate({
mutation: fileReportMutation, 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( await expect(
mutate({ mutate({
mutation: fileReportMutation, mutation: fileReportMutation,
@ -436,11 +446,7 @@ describe('file a report on a resource', () => {
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { data: {
fileReport: { fileReport: {
filed: [ reasonCategory: 'criminal_behavior_violation_german_law',
{
reasonCategory: 'criminal_behavior_violation_german_law',
},
],
}, },
}, },
errors: undefined, errors: undefined,
@ -481,11 +487,7 @@ describe('file a report on a resource', () => {
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { data: {
fileReport: { fileReport: {
filed: [ reasonDescription: 'My reason!',
{
reasonDescription: 'My reason!',
},
],
}, },
}, },
errors: undefined, errors: undefined,
@ -505,11 +507,7 @@ describe('file a report on a resource', () => {
).resolves.toMatchObject({ ).resolves.toMatchObject({
data: { data: {
fileReport: { fileReport: {
filed: [ reasonDescription: 'My reason !',
{
reasonDescription: 'My reason !',
},
],
}, },
}, },
errors: undefined, errors: undefined,

View File

@ -16,3 +16,15 @@ enum ReasonCategory {
advert_products_services_commercial advert_products_services_commercial
criminal_behavior_violation_german_law 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
}

View File

@ -10,21 +10,12 @@ type Report {
resource: ReportedResource resource: ReportedResource
} }
type FiledReport {
reportId: ID!
resource: ReportedResource
}
union ReportedResource = User | Post | Comment union ReportedResource = User | Post | Comment
enum ReportRule { enum ReportRule {
latestReviewUpdatedAtRules latestReviewUpdatedAtRules
} }
type Mutation {
fileReport(resourceId: ID!, reasonCategory: ReasonCategory!, reasonDescription: String!): FiledReport
}
type Query { type Query {
reports(orderBy: ReportOrdering, first: Int, offset: Int, reviewed: Boolean, closed: Boolean): [Report] reports(orderBy: ReportOrdering, first: Int, offset: Int, reviewed: Boolean, closed: Boolean): [Report]
} }

View File

@ -44,10 +44,11 @@ export default {
filterOptions() { filterOptions() {
return [ return [
{ label: this.$t('moderation.reports.filterLabel.all'), value: { reviewed: null } }, { 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'), label: this.$t('moderation.reports.filterLabel.unreviewed'),
value: { reviewed: false }, 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.reviewed'), value: { reviewed: true } },
{ label: this.$t('moderation.reports.filterLabel.closed'), value: { closed: true } }, { label: this.$t('moderation.reports.filterLabel.closed'), value: { closed: true } },
] ]