@@ -413,6 +413,7 @@ public function it_should_get_all_unread_messages_for_user()
413413 $ message_1 = $ this ->faktory ->build ('message ' , [
414414 'created_at ' => Carbon::now (),
415415 'body ' => 'Message 1 ' ,
416+ 'user_id ' => $ participant_1 ->user_id ,
416417 ]);
417418
418419 $ thread ->participants ()->saveMany ([$ participant_1 , $ participant_2 ]);
@@ -426,28 +427,30 @@ public function it_should_get_all_unread_messages_for_user()
426427 $ message_2 = $ this ->faktory ->build ('message ' , [
427428 'created_at ' => Carbon::now (),
428429 'body ' => 'Message 2 ' ,
430+ 'user_id ' => $ participant_1 ->user_id ,
429431 ]);
430432
431433 $ thread ->messages ()->saveMany ([$ message_2 ]);
432434
433- $ this ->assertEquals ('Message 1 ' , $ thread ->userUnreadMessages (1 )->first ()->body );
434- $ this ->assertCount (2 , $ thread ->userUnreadMessages (1 ));
435+ $ this ->assertCount (0 , $ thread ->userUnreadMessages ($ participant_1 ->user_id ));
435436
436- $ this ->assertEquals ('Message 2 ' , $ thread ->userUnreadMessages (2 )->first ()->body );
437- $ this ->assertCount (1 , $ thread ->userUnreadMessages (2 ));
437+ $ secondParticipantUnreadMessages = $ thread ->userUnreadMessages ($ participant_2 ->user_id );
438+ $ this ->assertCount (1 , $ secondParticipantUnreadMessages );
439+ $ this ->assertEquals ('Message 2 ' , $ secondParticipantUnreadMessages ->first ()->body );
438440 }
439441
440442 /** @test */
441- public function it_should_get_count_of_all_unread_messages_for_user ()
443+ public function it_should_get_all_unread_messages_for_user_when_dates_not_set ()
442444 {
443445 $ thread = $ this ->faktory ->create ('thread ' );
444446
445447 $ participant_1 = $ this ->faktory ->build ('participant ' );
446448 $ participant_2 = $ this ->faktory ->build ('participant ' , ['user_id ' => 2 ]);
447449
448450 $ message_1 = $ this ->faktory ->build ('message ' , [
449- 'created_at ' => Carbon::now (),
451+ // 'created_at' => Carbon::now(),
450452 'body ' => 'Message 1 ' ,
453+ 'user_id ' => $ participant_1 ->user_id ,
451454 ]);
452455
453456 $ thread ->participants ()->saveMany ([$ participant_1 , $ participant_2 ]);
@@ -459,15 +462,18 @@ public function it_should_get_count_of_all_unread_messages_for_user()
459462 sleep (1 );
460463
461464 $ message_2 = $ this ->faktory ->build ('message ' , [
462- 'created_at ' => Carbon::now (),
465+ // 'created_at' => Carbon::now(),
463466 'body ' => 'Message 2 ' ,
467+ 'user_id ' => $ participant_1 ->user_id ,
464468 ]);
465469
466470 $ thread ->messages ()->saveMany ([$ message_2 ]);
467471
468- $ this ->assertEquals ( 2 , $ thread ->userUnreadMessagesCount ( 1 ));
472+ $ this ->assertCount ( 0 , $ thread ->userUnreadMessages ( $ participant_1 -> user_id ));
469473
470- $ this ->assertEquals (1 , $ thread ->userUnreadMessagesCount (2 ));
474+ $ secondParticipantUnreadMessages = $ thread ->userUnreadMessages ($ participant_2 ->user_id );
475+ $ this ->assertCount (1 , $ secondParticipantUnreadMessages );
476+ $ this ->assertEquals ('Message 2 ' , $ secondParticipantUnreadMessages ->first ()->body );
471477 }
472478
473479 /** @test */
0 commit comments