Skip to content

Commit

Permalink
Orion notifications video liked (#205)
Browse files Browse the repository at this point in the history
* fix: 🐛 Video Liked data unitialized

* fix: 🐛 Video Liked data unitialized

* test: ✅ add test for video liked

* test: ✅ add test for video liked
  • Loading branch information
Ignazio Bovo authored Oct 3, 2023
1 parent 14cc985 commit 8b76e0e
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/tests/integration/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { EntityManager } from 'typeorm'
import { createType } from '@joystream/types'
import { Bytes } from '@polkadot/types'
import { IMemberRemarked, ReactVideo, MemberRemarked } from '@joystream/metadata-protobuf'
import { AnyMetadataClass } from '@joystream/metadata-protobuf/types'
import { clearDb, defaultTestBlock, populateDbWithSeedData } from './testUtils'
import { globalEm } from '../../utils/globalEm'
import { excludeChannelInner } from '../../server-extension/resolvers/ChannelsResolver'
Expand All @@ -14,6 +18,7 @@ import {
Notification,
OwnedNft,
Video,
VideoLiked,
} from '../../model'
import { expect } from 'chai'
import {
Expand All @@ -25,6 +30,12 @@ import { setFeaturedNftsInner } from '../../server-extension/resolvers/AdminReso
import { auctionBidMadeInner } from '../../mappings/content/nft'
import { EntityManagerOverlay } from '../../utils/overlay'
import { Store } from '@subsquid/typeorm-store'
import { processMemberRemarkedEvent } from '../../mappings/membership'
import Long from 'long'

const metadataToBytes = <T>(metaClass: AnyMetadataClass<T>, obj: T): Bytes => {
return createType('Bytes', '0x' + Buffer.from(metaClass.encode(obj).finish()).toString('hex'))
}

const getNextNotificationId = async (em: EntityManager, onchain: boolean) => {
const tag = onchain ? RUNTIME_NOTIFICATION_ID_TAG : OFFCHAIN_NOTIFICATION_ID_TAG
Expand All @@ -40,6 +51,7 @@ const createOverlay = async () => {
}

describe('notifications tests', () => {
let overlay: EntityManagerOverlay
let em: EntityManager
before(async () => {
em = await globalEm
Expand Down Expand Up @@ -171,7 +183,6 @@ describe('notifications tests', () => {
})
describe('New bid made', () => {
let nft: OwnedNft
let overlay: EntityManagerOverlay
const memberId = '5'
const outbiddedMember = '4'
const videoId = '5'
Expand Down Expand Up @@ -231,4 +242,46 @@ describe('notifications tests', () => {
expect(notification?.accountId).to.equal(account?.id)
})
})
describe('Video Liked', () => {
let notificationId: number
const block = { timestamp: 123456 } as any
const indexInBlock = 1
const extrinsicHash = '0x1234567890abcdef'
const metadataMessage: IMemberRemarked = {
reactVideo: {
videoId: Long.fromNumber(1),
reaction: ReactVideo.Reaction.LIKE,
},
}
const event = {
isV2001: true,
asV2001: ['1', metadataToBytes(MemberRemarked, metadataMessage), undefined],
} as any
before(async () => {
overlay = await createOverlay()
notificationId = await getNextNotificationId(em, true)
})
it('should process video liked 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())

expect(notification.notificationType.isTypeOf).to.equal('VideoLiked')
const notificationData = notification.notificationType as VideoLiked
expect(notificationData.videoId).to.equal('1')
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')
})
})
})

0 comments on commit 8b76e0e

Please sign in to comment.