From 2d4488969419a743c1cebddc9a2f96ecc0fbffd1 Mon Sep 17 00:00:00 2001 From: Ignazio Bovo Date: Mon, 16 Oct 2023 11:07:34 +0200 Subject: [PATCH] fix: comment id not added to notification data --- src/mappings/content/commentsAndReactions.ts | 1 + src/tests/integration/notifications.test.ts | 55 ++++++++++++++++++++ src/tests/integration/testUtils.ts | 1 + 3 files changed, 57 insertions(+) diff --git a/src/mappings/content/commentsAndReactions.ts b/src/mappings/content/commentsAndReactions.ts index 578bab856..d34c4fae9 100644 --- a/src/mappings/content/commentsAndReactions.ts +++ b/src/mappings/content/commentsAndReactions.ts @@ -525,6 +525,7 @@ export async function processCreateCommentMessage( videoId: video.id, videoTitle: parseVideoTitle(video), memberHandle: authorHandle, + comentId: comment.id, } await addNotification( overlay, diff --git a/src/tests/integration/notifications.test.ts b/src/tests/integration/notifications.test.ts index 448c59675..6b03156e5 100644 --- a/src/tests/integration/notifications.test.ts +++ b/src/tests/integration/notifications.test.ts @@ -10,6 +10,7 @@ import { Account, Channel, ChannelRecipient, + CommentPostedToVideo, Exclusion, MemberRecipient, NextEntityId, @@ -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 = (metaClass: AnyMetadataClass, obj: T): Bytes => { return createType('Bytes', '0x' + Buffer.from(metaClass.encode(obj).finish()).toString('hex')) @@ -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') + }) + }) + }) }) diff --git a/src/tests/integration/testUtils.ts b/src/tests/integration/testUtils.ts index e6dd8ca0f..7406fa0f8 100644 --- a/src/tests/integration/testUtils.ts +++ b/src/tests/integration/testUtils.ts @@ -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,