mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Update notifications in place
This commit is contained in:
parent
994ab43950
commit
c29ee5e3d3
@ -25,7 +25,9 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
MATCH (user: User)
|
MATCH (user: User)
|
||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
MERGE (post)-[:NOTIFIED {id: apoc.create.uuid(), read: false, reason: $reason, createdAt: $createdAt }]->(user)
|
MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
|
SET notification.read = FALSE
|
||||||
|
SET notification.createdAt = $createdAt
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -36,7 +38,9 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
||||||
MERGE (comment)-[:NOTIFIED {id: apoc.create.uuid(), read: false, reason: $reason, createdAt: $createdAt }]->(user)
|
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
|
SET notification.read = FALSE
|
||||||
|
SET notification.createdAt = $createdAt
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -47,7 +51,9 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
WHERE user.id in $idsOfUsers
|
WHERE user.id in $idsOfUsers
|
||||||
AND NOT (user)<-[:BLOCKED]-(author)
|
AND NOT (user)<-[:BLOCKED]-(author)
|
||||||
AND NOT (author)<-[:BLOCKED]-(user)
|
AND NOT (author)<-[:BLOCKED]-(user)
|
||||||
MERGE (comment)-[:NOTIFIED {id: apoc.create.uuid(), read: false, reason: $reason, createdAt: $createdAt }]->(user)
|
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
|
||||||
|
SET notification.read = FALSE
|
||||||
|
SET notification.createdAt = $createdAt
|
||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,6 +80,7 @@ describe('notifications', () => {
|
|||||||
notifications(read: $read, orderBy: createdAt_desc) {
|
notifications(read: $read, orderBy: createdAt_desc) {
|
||||||
read
|
read
|
||||||
reason
|
reason
|
||||||
|
createdAt
|
||||||
from {
|
from {
|
||||||
__typename
|
__typename
|
||||||
... on Post {
|
... on Post {
|
||||||
@ -160,6 +161,7 @@ describe('notifications', () => {
|
|||||||
notifications: [
|
notifications: [
|
||||||
{
|
{
|
||||||
read: false,
|
read: false,
|
||||||
|
createdAt: expect.any(String),
|
||||||
reason: 'comment_on_post',
|
reason: 'comment_on_post',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Comment',
|
__typename: 'Comment',
|
||||||
@ -250,6 +252,7 @@ describe('notifications', () => {
|
|||||||
notifications: [
|
notifications: [
|
||||||
{
|
{
|
||||||
read: false,
|
read: false,
|
||||||
|
createdAt: expect.any(String),
|
||||||
reason: 'mentioned_in_post',
|
reason: 'mentioned_in_post',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Post',
|
__typename: 'Post',
|
||||||
@ -272,6 +275,9 @@ describe('notifications', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('updates the post and mentions me again', () => {
|
describe('updates the post and mentions me again', () => {
|
||||||
|
const expectedUpdatedContent =
|
||||||
|
'<br>One more mention to<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>and again:<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>and again<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>'
|
||||||
|
|
||||||
const updatePostAction = async () => {
|
const updatePostAction = async () => {
|
||||||
const updatedContent = `
|
const updatedContent = `
|
||||||
One more mention to
|
One more mention to
|
||||||
@ -303,18 +309,17 @@ describe('notifications', () => {
|
|||||||
it('creates no duplicate notification for the same resource', async () => {
|
it('creates no duplicate notification for the same resource', async () => {
|
||||||
await createPostAction()
|
await createPostAction()
|
||||||
await updatePostAction()
|
await updatePostAction()
|
||||||
const expectedContent =
|
|
||||||
'<br>One more mention to<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>and again:<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>and again<br><a data-mention-id="you" class="mention" href="/profile/you" target="_blank"><br>@al-capone<br></a><br>'
|
|
||||||
const expected = expect.objectContaining({
|
const expected = expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
notifications: [
|
notifications: [
|
||||||
{
|
{
|
||||||
read: false,
|
read: false,
|
||||||
|
createdAt: expect.any(String),
|
||||||
reason: 'mentioned_in_post',
|
reason: 'mentioned_in_post',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Post',
|
__typename: 'Post',
|
||||||
id: 'p47',
|
id: 'p47',
|
||||||
content: expectedContent,
|
content: expectedUpdatedContent,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -329,12 +334,67 @@ describe('notifications', () => {
|
|||||||
}),
|
}),
|
||||||
).resolves.toEqual(expected)
|
).resolves.toEqual(expected)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe('if the notification was marked as read earlier', () => {
|
describe('if the notification was marked as read earlier', () => {
|
||||||
|
const markAsReadAction = async () => {
|
||||||
|
const mutation = gql`
|
||||||
|
mutation($id: ID!) {
|
||||||
|
markAsRead(id: $id) {
|
||||||
|
read
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
await mutate({ mutation, variables: { id: 'p47' } })
|
||||||
|
}
|
||||||
|
|
||||||
describe('but the next mentioning happens after the notification was marked as read', () => {
|
describe('but the next mentioning happens after the notification was marked as read', () => {
|
||||||
it.todo('sets the `read` attribute to false again')
|
it('sets the `read` attribute to false again', async () => {
|
||||||
it.todo('updates the `createdAt` attribute')
|
await createPostAction()
|
||||||
|
await markAsReadAction()
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
notifications: [{ read: readBefore }],
|
||||||
|
},
|
||||||
|
} = await query({
|
||||||
|
query: notificationQuery,
|
||||||
|
})
|
||||||
|
await updatePostAction()
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
notifications: [{ read: readAfter }],
|
||||||
|
},
|
||||||
|
} = await query({
|
||||||
|
query: notificationQuery,
|
||||||
|
})
|
||||||
|
expect(readBefore).toEqual(true)
|
||||||
|
expect(readAfter).toEqual(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates the `createdAt` attribute', async () => {
|
||||||
|
await createPostAction()
|
||||||
|
await markAsReadAction()
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
notifications: [{ createdAt: createdAtBefore }],
|
||||||
|
},
|
||||||
|
} = await query({
|
||||||
|
query: notificationQuery,
|
||||||
|
})
|
||||||
|
await updatePostAction()
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
notifications: [{ createdAt: createdAtAfter }],
|
||||||
|
},
|
||||||
|
} = await query({
|
||||||
|
query: notificationQuery,
|
||||||
|
})
|
||||||
|
expect(createdAtBefore).toBeTruthy()
|
||||||
|
expect(Date.parse(createdAtBefore)).toEqual(expect.any(Number))
|
||||||
|
expect(createdAtAfter).toBeTruthy()
|
||||||
|
expect(Date.parse(createdAtAfter)).toEqual(expect.any(Number))
|
||||||
|
expect(createdAtBefore).not.toEqual(createdAtAfter)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -387,6 +447,7 @@ describe('notifications', () => {
|
|||||||
notifications: [
|
notifications: [
|
||||||
{
|
{
|
||||||
read: false,
|
read: false,
|
||||||
|
createdAt: expect.any(String),
|
||||||
reason: 'mentioned_in_comment',
|
reason: 'mentioned_in_comment',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Comment',
|
__typename: 'Comment',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user