From 3421afe4e00b5444033979f04346c8aa38873c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 19 Feb 2020 13:27:01 +0100 Subject: [PATCH] Refactor tests, next step --- .../validation/validationMiddleware.spec.js | 2 +- backend/src/schema/resolvers/moderation.js | 4 +- backend/src/schema/resolvers/reports.js | 36 ++++---- backend/src/schema/resolvers/reports.spec.js | 92 +++++++++---------- backend/src/schema/types/type/FILED.gql | 12 +++ backend/src/schema/types/type/Report.gql | 9 -- .../features/ReportList/ReportList.vue | 3 +- 7 files changed, 78 insertions(+), 80 deletions(-) diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index b2c669369..74a343eeb 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -58,7 +58,7 @@ const reportMutation = gql` reasonCategory: $reasonCategory reasonDescription: $reasonDescription ) { - id + reportId } } ` diff --git a/backend/src/schema/resolvers/moderation.js b/backend/src/schema/resolvers/moderation.js index 08a3b6ff3..58090c762 100644 --- a/backend/src/schema/resolvers/moderation.js +++ b/backend/src/schema/resolvers/moderation.js @@ -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) diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 8e6bcf786..6a9366a89 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -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}` : '' diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 6a9df6639..e3c2e659f 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -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,30 +329,31 @@ 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 + // 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, + }) }) }) - + 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( 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, diff --git a/backend/src/schema/types/type/FILED.gql b/backend/src/schema/types/type/FILED.gql index cdce62116..85eca951e 100644 --- a/backend/src/schema/types/type/FILED.gql +++ b/backend/src/schema/types/type/FILED.gql @@ -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 +} \ No newline at end of file diff --git a/backend/src/schema/types/type/Report.gql b/backend/src/schema/types/type/Report.gql index ae8c640fb..092530318 100644 --- a/backend/src/schema/types/type/Report.gql +++ b/backend/src/schema/types/type/Report.gql @@ -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] } diff --git a/webapp/components/features/ReportList/ReportList.vue b/webapp/components/features/ReportList/ReportList.vue index 62a29e66b..9e35fe034 100644 --- a/webapp/components/features/ReportList/ReportList.vue +++ b/webapp/components/features/ReportList/ReportList.vue @@ -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 } }, ]