Skip to content

Commit

Permalink
fix: comment id not added to notification data (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignazio Bovo authored Oct 16, 2023
1 parent 8b76e0e commit a20a3d9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mappings/content/commentsAndReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ export async function processCreateCommentMessage(
videoId: video.id,
videoTitle: parseVideoTitle(video),
memberHandle: authorHandle,
comentId: comment.id,
}
await addNotification(
overlay,
Expand Down
55 changes: 55 additions & 0 deletions src/tests/integration/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Account,
Channel,
ChannelRecipient,
CommentPostedToVideo,
Exclusion,
MemberRecipient,
NextEntityId,
Expand All @@ -32,6 +33,7 @@ import { EntityManagerOverlay } from '../../utils/overlay'
import { Store } from '@subsquid/typeorm-store'
import { processMemberRemarkedEvent } from '../../mappings/membership'
import Long from 'long'
import { backwardCompatibleMetaID } from '../../mappings/utils'

const metadataToBytes = <T>(metaClass: AnyMetadataClass<T>, obj: T): Bytes => {
return createType('Bytes', '0x' + Buffer.from(metaClass.encode(obj).finish()).toString('hex'))
Expand Down Expand Up @@ -284,4 +286,57 @@ describe('notifications tests', () => {
expect(notification!.recipient.isTypeOf).to.equal('ChannelRecipient')
})
})
describe('Comment Posted To Video', () => {
let notificationId: number
const block = { timestamp: 123456 } as any
const indexInBlock = 1
const extrinsicHash = '0x1234567890abcdef'
const metadataMessage: IMemberRemarked = {
createComment: {
videoId: Long.fromNumber(1),
parentCommentId: null,
body: 'test',
},
}
const event = {
isV2001: true,
asV2001: ['2', metadataToBytes(MemberRemarked, metadataMessage), undefined], // avoid comment author == creator
} as any
before(async () => {
overlay = await createOverlay()
notificationId = await getNextNotificationId(em, true)
})
it('should process comment to video and deposit notification', async () => {
await processMemberRemarkedEvent({
overlay,
block,
indexInBlock,
extrinsicHash,
event,
})

const nextNotificationId = await getNextNotificationId(em, true)
const notification = await overlay
.getRepository(Notification)
.getByIdOrFail(RUNTIME_NOTIFICATION_ID_TAG + '-' + notificationId.toString())

it('notification type is comment posted to video', () => {
expect(notification.notificationType.isTypeOf).to.equal('CommentPostedToVideo')
})
it('notification data for comment posted to video should be ok', () => {
const notificationData = notification.notificationType as CommentPostedToVideo
expect(notificationData.videoId).to.equal('1')
expect(notificationData.comentId).to.equal(backwardCompatibleMetaID(block, indexInBlock))
expect(notificationData.memberHandle).to.equal('handle-2')
expect(notificationData.videoTitle).to.equal('test-video-1')
})

it('general notification creation setting should be as default', () => {
expect(notification!.status.isTypeOf).to.equal('Unread')
expect(notification!.inApp).to.be.true
expect(nextNotificationId.toString()).to.equal((notificationId + 1).toString())
expect(notification!.recipient.isTypeOf).to.equal('ChannelRecipient')
})
})
})
})
1 change: 1 addition & 0 deletions src/tests/integration/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function populateDbWithSeedData() {
})
const video = new Video({
id: i.toString(),
title: `test-video-${i}`,
createdAt: new Date(),
channelId: channel.id,
isCensored: false,
Expand Down

0 comments on commit a20a3d9

Please sign in to comment.