diff --git a/backend/src/models/Comment.js b/backend/src/models/Comment.js index 9b3da22a0..add88cbe0 100644 --- a/backend/src/models/Comment.js +++ b/backend/src/models/Comment.js @@ -31,6 +31,18 @@ export default { target: 'User', direction: 'out', properties: { + createdAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, + updatedAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, read: { type: 'boolean', default: false }, reason: { type: 'string', @@ -41,7 +53,6 @@ export default { 'filed_report_on_resource', ], }, - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, }, }, } diff --git a/backend/src/models/Post.js b/backend/src/models/Post.js index fd1e5b2ac..f4d13b7f4 100644 --- a/backend/src/models/Post.js +++ b/backend/src/models/Post.js @@ -23,12 +23,23 @@ export default { target: 'User', direction: 'out', properties: { + createdAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, + updatedAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, read: { type: 'boolean', default: false }, reason: { type: 'string', valid: ['mentioned_in_post', 'mentioned_in_comment', 'commented_on_post'], }, - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, }, }, createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, diff --git a/backend/src/models/Report.js b/backend/src/models/Report.js index 5678d8ccd..e1d73126c 100644 --- a/backend/src/models/Report.js +++ b/backend/src/models/Report.js @@ -55,7 +55,18 @@ export default { target: 'User', direction: 'out', properties: { - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + createdAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, + updatedAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString() + }, read: { type: 'boolean', default: false }, reason: { type: 'string', diff --git a/backend/src/schema/resolvers/notifications.spec.js b/backend/src/schema/resolvers/notifications.spec.js index 71a60405c..ad7e4482a 100644 --- a/backend/src/schema/resolvers/notifications.spec.js +++ b/backend/src/schema/resolvers/notifications.spec.js @@ -90,37 +90,43 @@ describe('given some notifications', () => { author, postId: 'p4', id: 'c4', - content: 'I am bad content in a bad comment to a bad post !!!', + content: 'I am harassing content in a harassing comment to a bad post !!!', }), ]) await Promise.all([ post1.relateTo(neighbor, 'notified', { createdAt: '2019-08-29T17:33:48.651Z', + updatedAt: '2019-08-29T17:33:48.651Z', read: false, reason: 'mentioned_in_post', }), post2.relateTo(user, 'notified', { createdAt: '2019-08-30T17:33:48.651Z', + updatedAt: '2019-08-30T17:33:48.651Z', read: true, reason: 'mentioned_in_post', }), post3.relateTo(user, 'notified', { createdAt: '2019-08-31T17:33:48.651Z', + updatedAt: '2019-08-31T17:33:48.651Z', read: false, reason: 'mentioned_in_post', }), comment1.relateTo(user, 'notified', { createdAt: '2019-08-30T15:33:48.651Z', + updatedAt: '2019-08-30T15:33:48.651Z', read: true, reason: 'mentioned_in_comment', }), comment2.relateTo(user, 'notified', { createdAt: '2019-08-30T19:33:48.651Z', + updatedAt: '2019-08-30T19:33:48.651Z', read: false, reason: 'mentioned_in_comment', }), comment3.relateTo(neighbor, 'notified', { createdAt: '2019-09-01T17:33:48.651Z', + updatedAt: '2019-09-01T17:33:48.651Z', read: false, reason: 'mentioned_in_comment', }), @@ -161,16 +167,19 @@ describe('given some notifications', () => { await Promise.all([ reportOnUser.relateTo(user, 'notified', { createdAt: '2020-01-15T16:33:48.651Z', + updatedAt: '2020-01-15T16:33:48.651Z', read: false, reason: 'filed_report_on_resource', }), reportOnPost.relateTo(user, 'notified', { createdAt: '2020-01-16T10:33:48.651Z', + updatedAt: '2020-01-16T10:33:48.651Z', read: true, reason: 'filed_report_on_resource', }), reportOnComment.relateTo(user, 'notified', { createdAt: '2020-01-14T12:33:48.651Z', + updatedAt: '2020-01-14T12:33:48.651Z', read: false, reason: 'filed_report_on_resource', }), @@ -182,6 +191,7 @@ describe('given some notifications', () => { query($read: Boolean, $orderBy: NotificationOrdering) { notifications(read: $read, orderBy: $orderBy) { createdAt + updatedAt read reason from { @@ -236,60 +246,9 @@ describe('given some notifications', () => { const expected = { data: { notifications: expect.arrayContaining([ - expect.objectContaining({ - from: { - __typename: 'Comment', - content: 'You have seen this comment mentioning already', - }, - read: true, - createdAt: '2019-08-30T15:33:48.651Z', - }), - expect.objectContaining({ - from: { - __typename: 'Post', - content: 'Already seen post mention', - }, - read: true, - createdAt: '2019-08-30T17:33:48.651Z', - }), - expect.objectContaining({ - from: { - __typename: 'Comment', - content: 'You have been mentioned in a comment', - }, - read: false, - createdAt: '2019-08-30T19:33:48.651Z', - }), - expect.objectContaining({ - from: { - __typename: 'Post', - content: 'You have been mentioned in a post', - }, - read: false, - createdAt: '2019-08-31T17:33:48.651Z', - }), - { - createdAt: '2020-01-15T16:33:48.651Z', - read: false, - reason: 'filed_report_on_resource', - from: { - __typename: 'Report', - id: 'reportOnUser', - filed: [ - { - reasonCategory: 'discrimination_etc', - reasonDescription: 'This user is harassing me with bigoted remarks!', - reportedResource: { - __typename: 'User', - id: 'badWomen', - name: 'Mrs. Badwomen', - }, - }, - ], - }, - }, { createdAt: '2020-01-16T10:33:48.651Z', + updatedAt: '2020-01-16T10:33:48.651Z', read: true, reason: 'filed_report_on_resource', from: { @@ -310,62 +269,9 @@ describe('given some notifications', () => { ], }, }, - { - createdAt: '2020-01-14T12:33:48.651Z', - read: false, - reason: 'filed_report_on_resource', - from: { - __typename: 'Report', - id: 'reportOnComment', - filed: [ - { - reasonCategory: 'discrimination_etc', - reasonDescription: 'This user is harassing me!', - reportedResource: { - __typename: 'Comment', - id: 'c4', - content: 'I am bad content in a bad comment to a bad post !!!', - }, - }, - ], - }, - }, - ]), - }, - errors: undefined, - } - - const response = await query({ query: notificationQuery, variables }) - await expect(response).toMatchObject(expected) - await expect(response.data.notifications.length).toEqual(7) // has to be checked, because of 'arrayContaining' - }) - }) - - describe('filter for read: false', () => { - it('returns only unread notifications of current user', async () => { - const expected = { - data: { - notifications: expect.arrayContaining([ - { - createdAt: '2019-08-30T19:33:48.651Z', - read: false, - reason: 'mentioned_in_comment', - from: { - __typename: 'Comment', - content: 'You have been mentioned in a comment', - }, - }, - { - createdAt: '2019-08-31T17:33:48.651Z', - read: false, - reason: 'mentioned_in_post', - from: { - __typename: 'Post', - content: 'You have been mentioned in a post', - }, - }, { createdAt: '2020-01-15T16:33:48.651Z', + updatedAt: '2020-01-15T16:33:48.651Z', read: false, reason: 'filed_report_on_resource', from: { @@ -386,6 +292,7 @@ describe('given some notifications', () => { }, { createdAt: '2020-01-14T12:33:48.651Z', + updatedAt: '2020-01-14T12:33:48.651Z', read: false, reason: 'filed_report_on_resource', from: { @@ -398,7 +305,121 @@ describe('given some notifications', () => { reportedResource: { __typename: 'Comment', id: 'c4', - content: 'I am bad content in a bad comment to a bad post !!!', + content: 'I am harassing content in a harassing comment to a bad post !!!', + }, + }, + ], + }, + }, + expect.objectContaining({ + createdAt: '2019-08-31T17:33:48.651Z', + updatedAt: '2019-08-31T17:33:48.651Z', + read: false, + from: { + __typename: 'Post', + content: 'You have been mentioned in a post', + }, + }), + expect.objectContaining({ + createdAt: '2019-08-30T19:33:48.651Z', + updatedAt: '2019-08-30T19:33:48.651Z', + read: false, + from: { + __typename: 'Comment', + content: 'You have been mentioned in a comment', + }, + }), + expect.objectContaining({ + createdAt: '2019-08-30T17:33:48.651Z', + updatedAt: '2019-08-30T17:33:48.651Z', + read: true, + from: { + __typename: 'Post', + content: 'Already seen post mention', + }, + }), + expect.objectContaining({ + createdAt: '2019-08-30T15:33:48.651Z', + updatedAt: '2019-08-30T15:33:48.651Z', + read: true, + from: { + __typename: 'Comment', + content: 'You have seen this comment mentioning already', + }, + }), + ]), + }, + errors: undefined, + } + + const response = await query({ query: notificationQuery, variables }) + await expect(response).toMatchObject(expected) + await expect(response.data.notifications.length).toEqual(7) // has to be checked, because of 'arrayContaining' + }) + }) + + describe('filter for read: false', () => { + it('returns only unread notifications of current user', async () => { + const expected = { + data: { + notifications: expect.arrayContaining([ + { + createdAt: '2019-08-30T19:33:48.651Z', + updatedAt: '2019-08-30T19:33:48.651Z', + read: false, + reason: 'mentioned_in_comment', + from: { + __typename: 'Comment', + content: 'You have been mentioned in a comment', + }, + }, + { + createdAt: '2019-08-31T17:33:48.651Z', + updatedAt: '2019-08-31T17:33:48.651Z', + read: false, + reason: 'mentioned_in_post', + from: { + __typename: 'Post', + content: 'You have been mentioned in a post', + }, + }, + { + createdAt: '2020-01-15T16:33:48.651Z', + updatedAt: '2020-01-15T16:33:48.651Z', + read: false, + reason: 'filed_report_on_resource', + from: { + __typename: 'Report', + id: 'reportOnUser', + filed: [ + { + reasonCategory: 'discrimination_etc', + reasonDescription: 'This user is harassing me with bigoted remarks!', + reportedResource: { + __typename: 'User', + id: 'badWomen', + name: 'Mrs. Badwomen', + }, + }, + ], + }, + }, + { + createdAt: '2020-01-14T12:33:48.651Z', + updatedAt: '2020-01-14T12:33:48.651Z', + read: false, + reason: 'filed_report_on_resource', + from: { + __typename: 'Report', + id: 'reportOnComment', + filed: [ + { + reasonCategory: 'discrimination_etc', + reasonDescription: 'This user is harassing me!', + reportedResource: { + __typename: 'Comment', + id: 'c4', + content: 'I am harassing content in a harassing comment to a bad post !!!', }, }, ], diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 1f10ee86d..6fc7d667d 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -1,3 +1,4 @@ +import { undefinedToNullResolver } from './helpers/Resolver' import log from './helpers/databaseLogger' const transformReturnType = record => { @@ -184,9 +185,12 @@ export default { }, }, FILED: { - reasonDescription: async (parent, _params, _context, _resolveInfo) => { - if (typeof parent.reasonDescription !== 'undefined') return parent.reasonDescription - return null - }, + ...undefinedToNullResolver([ + 'reasonDescription', + ]), + // Wolle reasonDescription: async (parent, _params, _context, _resolveInfo) => { + // if (typeof parent.reasonDescription !== 'undefined') return parent.reasonDescription + // return null + // }, }, } diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 9311bead8..a333c6f17 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -371,7 +371,7 @@ When("I log in with the following credentials:", table => { When("open the notification menu and click on the first item", () => { cy.get(".notifications-menu").invoke('show').click(); // "invoke('show')" because of the delay for show the menu - cy.get(".notification-link-for-test") + cy.get('[data-test-id="notification-link"]') .first() .click({ force: true diff --git a/webapp/components/Notification/Notification.vue b/webapp/components/Notification/Notification.vue index 62d2d379f..03d7021d3 100644 --- a/webapp/components/Notification/Notification.vue +++ b/webapp/components/Notification/Notification.vue @@ -27,6 +27,7 @@ { describe('click on a notification', () => { beforeEach(() => { - wrapper.find('.notification-link-for-test').trigger('click') + // Wolle wrapper.find('.notification-link-for-test').trigger('click') + wrapper.getByTestId('notification-link').trigger('click') }) it("emits 'markAsRead' with the id of the notification source", () => { diff --git a/webapp/components/NotificationsTable/NotificationsTable.vue b/webapp/components/NotificationsTable/NotificationsTable.vue index fde59a67a..d7ee6d381 100644 --- a/webapp/components/NotificationsTable/NotificationsTable.vue +++ b/webapp/components/NotificationsTable/NotificationsTable.vue @@ -40,6 +40,7 @@