1
- import { EntityManager } from 'typeorm'
2
- import { IMemberRemarked , ReactVideo , MemberRemarked } from '@joystream/metadata-protobuf'
1
+ import { IMemberRemarked , MemberRemarked , ReactVideo } from '@joystream/metadata-protobuf'
3
2
import { AnyMetadataClass } from '@joystream/metadata-protobuf/types'
4
- import { defaultTestBlock , populateDbWithSeedData } from './testUtils'
5
- import { globalEm } from '../../utils/globalEm'
6
- import {
7
- excludeChannelService ,
8
- verifyChannelService ,
9
- } from '../../server-extension/resolvers/ChannelsResolver'
3
+ import { Store } from '@subsquid/typeorm-store'
4
+ import { expect } from 'chai'
5
+ import { config as dontenvConfig } from 'dotenv'
6
+ import Long from 'long'
7
+ import path from 'path'
8
+ import { EntityManager } from 'typeorm'
9
+ import { auctionBidMadeInner } from '../../mappings/content/nft'
10
+ import { processMemberRemarkedEvent } from '../../mappings/membership'
11
+ import { backwardCompatibleMetaID } from '../../mappings/utils'
10
12
import {
11
13
Account ,
12
14
Channel ,
@@ -26,21 +28,19 @@ import {
26
28
Video ,
27
29
VideoLiked ,
28
30
} from '../../model'
29
- import { expect } from 'chai'
31
+ import { setFeaturedNftsInner } from '../../server-extension/resolvers/AdminResolver'
32
+ import {
33
+ excludeChannelService ,
34
+ verifyChannelService ,
35
+ } from '../../server-extension/resolvers/ChannelsResolver'
36
+ import { excludeVideoService } from '../../server-extension/resolvers/VideosResolver'
37
+ import { globalEm } from '../../utils/globalEm'
30
38
import {
31
39
OFFCHAIN_NOTIFICATION_ID_TAG ,
32
40
RUNTIME_NOTIFICATION_ID_TAG ,
33
41
} from '../../utils/notification/helpers'
34
- import { setFeaturedNftsInner } from '../../server-extension/resolvers/AdminResolver'
35
- import { auctionBidMadeInner } from '../../mappings/content/nft'
36
- import { EntityManagerOverlay } from '../../utils/overlay'
37
- import { Store } from '@subsquid/typeorm-store'
38
- import { processMemberRemarkedEvent } from '../../mappings/membership'
39
- import Long from 'long'
40
- import { backwardCompatibleMetaID } from '../../mappings/utils'
41
- import { config as dontenvConfig } from 'dotenv'
42
- import path from 'path'
43
- import { excludeVideoService } from '../../server-extension/resolvers/VideosResolver'
42
+ import { AnyEntity , Constructor , EntityManagerOverlay } from '../../utils/overlay'
43
+ import { defaultTestBlock , populateDbWithSeedData } from './testUtils'
44
44
45
45
dontenvConfig ( {
46
46
path : path . resolve ( __dirname , './.env' ) ,
@@ -50,9 +50,19 @@ const metadataToBytes = <T>(metaClass: AnyMetadataClass<T>, obj: T): Uint8Array
50
50
return Buffer . from ( metaClass . encode ( obj ) . finish ( ) )
51
51
}
52
52
53
- const getNextNotificationId = async ( em : EntityManager , onchain : boolean ) => {
53
+ const getNextNotificationId = async (
54
+ store : EntityManager | EntityManagerOverlay ,
55
+ onchain : boolean
56
+ ) => {
54
57
const tag = onchain ? RUNTIME_NOTIFICATION_ID_TAG : OFFCHAIN_NOTIFICATION_ID_TAG
55
- const row = await em . getRepository ( NextEntityId ) . findOneBy ( { entityName : tag } )
58
+ if ( store instanceof EntityManagerOverlay ) {
59
+ const row = await store
60
+ . getRepository ( NextEntityId as Constructor < NextEntityId & AnyEntity > )
61
+ . getOneBy ( { entityName : tag } )
62
+ const id = parseInt ( row ?. nextId . toString ( ) || '1' )
63
+ return id
64
+ }
65
+ const row = await store . getRepository ( NextEntityId ) . findOneBy ( { entityName : tag } )
56
66
const id = parseInt ( row ?. nextId . toString ( ) || '1' )
57
67
return id
58
68
}
@@ -69,6 +79,7 @@ describe('notifications tests', () => {
69
79
let em : EntityManager
70
80
before ( async ( ) => {
71
81
em = await globalEm
82
+ overlay = await createOverlay ( )
72
83
await populateDbWithSeedData ( )
73
84
} )
74
85
describe ( '👉 YPP Verify channel' , ( ) => {
@@ -281,10 +292,9 @@ describe('notifications tests', () => {
281
292
282
293
before ( async ( ) => {
283
294
const bidAmount = BigInt ( 100000 )
284
- nextNotificationIdPre = await getNextNotificationId ( em , true )
295
+ nextNotificationIdPre = await getNextNotificationId ( overlay , true )
285
296
notificationId = RUNTIME_NOTIFICATION_ID_TAG + '-' + nextNotificationIdPre
286
297
nft = await em . getRepository ( OwnedNft ) . findOneByOrFail ( { videoId } )
287
- overlay = await createOverlay ( )
288
298
289
299
await auctionBidMadeInner (
290
300
overlay ,
@@ -368,8 +378,7 @@ describe('notifications tests', () => {
368
378
asV2001 : [ '3' , metadataToBytes ( MemberRemarked , metadataMessage ) , undefined ] ,
369
379
} as any
370
380
before ( async ( ) => {
371
- overlay = await createOverlay ( )
372
- nextNotificationIdPre = await getNextNotificationId ( em , true )
381
+ nextNotificationIdPre = await getNextNotificationId ( overlay , true )
373
382
notificationId = RUNTIME_NOTIFICATION_ID_TAG + '-' + nextNotificationIdPre . toString ( )
374
383
} )
375
384
it ( 'should process video liked and deposit notification' , async ( ) => {
@@ -381,7 +390,7 @@ describe('notifications tests', () => {
381
390
event,
382
391
} )
383
392
384
- const nextNotificationId = await getNextNotificationId ( em , true )
393
+ const nextNotificationId = await getNextNotificationId ( overlay , true )
385
394
notification = ( await overlay
386
395
. getRepository ( Notification )
387
396
. getByIdOrFail ( notificationId ) ) as Notification
@@ -422,8 +431,7 @@ describe('notifications tests', () => {
422
431
asV2001 : [ '2' , metadataToBytes ( MemberRemarked , metadataMessage ) , undefined ] , // avoid comment author == creator
423
432
} as any
424
433
before ( async ( ) => {
425
- overlay = await createOverlay ( )
426
- nextNotificationIdPre = await getNextNotificationId ( em , true )
434
+ nextNotificationIdPre = await getNextNotificationId ( overlay , true )
427
435
notificationId = RUNTIME_NOTIFICATION_ID_TAG + '-' + nextNotificationIdPre . toString ( )
428
436
} )
429
437
it ( 'should process comment to video and deposit notification' , async ( ) => {
@@ -435,7 +443,7 @@ describe('notifications tests', () => {
435
443
event,
436
444
} )
437
445
438
- const nextNotificationId = await getNextNotificationId ( em , true )
446
+ const nextNotificationId = await getNextNotificationId ( overlay , true )
439
447
notification = ( await overlay
440
448
. getRepository ( Notification )
441
449
. getByIdOrFail ( notificationId ) ) as Notification | null
@@ -485,7 +493,7 @@ describe('notifications tests', () => {
485
493
} as any
486
494
487
495
before ( async ( ) => {
488
- nextNotificationIdPre = await getNextNotificationId ( em , true )
496
+ nextNotificationIdPre = await getNextNotificationId ( overlay , true )
489
497
notificationId = RUNTIME_NOTIFICATION_ID_TAG + '-' + nextNotificationIdPre . toString ( )
490
498
491
499
await processMemberRemarkedEvent ( {
@@ -500,7 +508,7 @@ describe('notifications tests', () => {
500
508
describe ( 'should process reply to comment and deposit notification' , ( ) => {
501
509
let nextNotificationId : number
502
510
before ( async ( ) => {
503
- nextNotificationId = await getNextNotificationId ( em , true )
511
+ nextNotificationId = await getNextNotificationId ( overlay , true )
504
512
notification = ( await overlay
505
513
. getRepository ( Notification )
506
514
. getByIdOrFail ( notificationId ) ) as Notification | null
0 commit comments