Implement suggestions of Matt

This commit is contained in:
Wolfgang Huß 2020-01-24 19:23:01 +01:00
parent 28deba79f1
commit 7eeddf2a8f
9 changed files with 178 additions and 117 deletions

View File

@ -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() },
},
},
}

View File

@ -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() },

View File

@ -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',

View File

@ -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 !!!',
},
},
],

View File

@ -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
// },
},
}

View File

@ -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

View File

@ -27,6 +27,7 @@
</client-only>
<ds-space margin-bottom="x-small" />
<nuxt-link
data-test-id="notification-link"
class="notification-link-for-test"
:to="notificationData.linkTo"
@click.native="$emit('read')"

View File

@ -73,7 +73,8 @@ describe('NotificationList.vue', () => {
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", () => {

View File

@ -40,6 +40,7 @@
</template>
<template #post="scope">
<nuxt-link
data-testid="notification-link"
class="notification-link-for-test"
:class="{ 'notification-status': scope.row.read }"
:to="scope.row.linkTo"