@@ -376,7 +376,7 @@ describe('FediverseBridge', () => {
376376 author . apFollowers = new URL ( 'https://example.com/user/foo/followers' ) ;
377377
378378 const post = Object . create ( Post ) ;
379- post . id = 'post-123' ;
379+ post . id = 456 ;
380380 post . author = author ;
381381 post . type = PostType . Note ;
382382 post . content = 'Note content' ;
@@ -385,11 +385,14 @@ describe('FediverseBridge', () => {
385385 post . uuid = 'cb1e7e92-5560-4ceb-9272-7e9d0e2a7da4' ;
386386 post . publishedAt = new Date ( '2025-01-01T00:00:00Z' ) ;
387387
388- const event = new PostCreatedEvent ( post ) ;
388+ vi . mocked ( postRepository . getById ) . mockResolvedValue ( post ) ;
389+
390+ const event = new PostCreatedEvent ( post . id as number ) ;
389391 events . emit ( PostCreatedEvent . getName ( ) , event ) ;
390392
391393 await nextTick ( ) ;
392394
395+ expect ( postRepository . getById ) . toHaveBeenCalledWith ( post . id ) ;
393396 expect ( sendActivity ) . toHaveBeenCalledOnce ( ) ;
394397 expect ( context . data . globaldb . set ) . toHaveBeenCalled ( ) ;
395398
@@ -417,7 +420,7 @@ describe('FediverseBridge', () => {
417420 mentionedAccount . isInternal = true ;
418421
419422 const post = Object . create ( Post ) ;
420- post . id = 'post-123' ;
423+ post . id = 789 ;
421424 post . author = author ;
422425 post . type = PostType . Note ;
423426 post . content = 'Hello! @test@example.com' ;
@@ -426,11 +429,15 @@ describe('FediverseBridge', () => {
426429 post . uuid = 'cb1e7e92-5560-4ceb-9272-7e9d0e2a7da4' ;
427430 post . publishedAt = new Date ( '2025-01-01T00:00:00Z' ) ;
428431
429- const event = new PostCreatedEvent ( post ) ;
432+ vi . mocked ( postRepository . getById ) . mockResolvedValue ( post ) ;
433+
434+ const event = new PostCreatedEvent ( post . id as number ) ;
430435 events . emit ( PostCreatedEvent . getName ( ) , event ) ;
431436
432437 await nextTick ( ) ;
433438
439+ expect ( postRepository . getById ) . toHaveBeenCalledWith ( post . id ) ;
440+
434441 const storedActivity = await globalDbSet . mock . calls [ 0 ] [ 1 ] ;
435442 await expect ( storedActivity ) . toMatchFileSnapshot (
436443 './__snapshots__/publish-note-create-activity-with-mentions.json' ,
@@ -451,23 +458,26 @@ describe('FediverseBridge', () => {
451458 author . apFollowers = new URL ( 'https://example.com/user/foo/followers' ) ;
452459
453460 const post = Object . create ( Post ) ;
454- post . id = 'post-123' ;
461+ post . id = 456 ;
455462 post . author = author ;
456463 post . type = PostType . Article ;
457464 post . title = 'Post title' ;
458465 post . content = 'Post content' ;
459466 post . excerpt = 'Post excerpt' ;
460- post . imageUrl = new URL ( 'https://example.com/img/post-123_feature .jpg' ) ;
467+ post . imageUrl = new URL ( 'https://example.com/img/456_feature .jpg' ) ;
461468 post . publishedAt = new Date ( '2025-01-12T10:30:00Z' ) ;
462- post . url = new URL ( 'https://example.com/post/post-123 ' ) ;
463- post . apId = new URL ( 'https://example.com/article/post-123 ' ) ;
469+ post . url = new URL ( 'https://example.com/post/456 ' ) ;
470+ post . apId = new URL ( 'https://example.com/article/456 ' ) ;
464471 post . uuid = 'cb1e7e92-5560-4ceb-9272-7e9d0e2a7da4' ;
465472
466- const event = new PostCreatedEvent ( post ) ;
473+ vi . mocked ( postRepository . getById ) . mockResolvedValue ( post ) ;
474+
475+ const event = new PostCreatedEvent ( post . id as number ) ;
467476 events . emit ( PostCreatedEvent . getName ( ) , event ) ;
468477
469478 await nextTick ( ) ;
470479
480+ expect ( postRepository . getById ) . toHaveBeenCalledWith ( post . id ) ;
471481 expect ( sendActivity ) . toHaveBeenCalledOnce ( ) ;
472482 expect ( context . data . globaldb . set ) . toHaveBeenCalled ( ) ;
473483
@@ -489,15 +499,36 @@ describe('FediverseBridge', () => {
489499 author . isInternal = false ;
490500
491501 const post = Object . create ( Post ) ;
502+ post . id = 456 ;
492503 post . author = author ;
493504 post . type = PostType . Note ;
494505 post . content = 'Test content' ;
495506
496- const event = new PostCreatedEvent ( post ) ;
507+ vi . mocked ( postRepository . getById ) . mockResolvedValue ( post ) ;
508+
509+ const event = new PostCreatedEvent ( post . id as number ) ;
510+ events . emit ( PostCreatedEvent . getName ( ) , event ) ;
511+
512+ await nextTick ( ) ;
513+
514+ expect ( postRepository . getById ) . toHaveBeenCalledWith ( post . id ) ;
515+ expect ( sendActivity ) . not . toHaveBeenCalled ( ) ;
516+ expect ( context . data . globaldb . set ) . not . toHaveBeenCalled ( ) ;
517+ } ) ;
518+
519+ it ( 'should not create or send activities if post is not found on the PostCreatedEvent' , async ( ) => {
520+ await bridge . init ( ) ;
521+
522+ const sendActivity = vi . spyOn ( context , 'sendActivity' ) ;
523+
524+ vi . mocked ( postRepository . getById ) . mockResolvedValue ( null ) ;
525+
526+ const event = new PostCreatedEvent ( 123 ) ;
497527 events . emit ( PostCreatedEvent . getName ( ) , event ) ;
498528
499529 await nextTick ( ) ;
500530
531+ expect ( postRepository . getById ) . toHaveBeenCalledWith ( 123 ) ;
501532 expect ( sendActivity ) . not . toHaveBeenCalled ( ) ;
502533 expect ( context . data . globaldb . set ) . not . toHaveBeenCalled ( ) ;
503534 } ) ;
0 commit comments