Permalink
Browse files

Episode 47

  • Loading branch information...
JeffreyWay committed May 25, 2017
1 parent 6429238 commit 7c9cee4c74d9ba40f231c696af8a59cb1e867a5e
Showing with 30 additions and 3 deletions.
  1. +12 −3 app/Thread.php
  2. +18 −0 tests/Unit/ThreadTest.php
@@ -93,13 +93,22 @@ public function addReply($reply)
{
$reply = $this->replies()->create($reply);
// Prepare notifications for all subscribers.
$this->notifySubscribers($reply);
return $reply;
}
/**
* Notify all thread subscribers about a new reply.
*
* @param \App\Reply $reply
*/
public function notifySubscribers($reply)
{
$this->subscriptions
->where('user_id', '!=', $reply->user_id)
->each
->notify($reply);
return $reply;
}
/**
@@ -2,7 +2,9 @@
namespace Tests\Unit;
use App\Notifications\ThreadWasUpdated;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class ThreadTest extends TestCase
@@ -53,6 +55,22 @@ public function a_thread_can_add_a_reply()
$this->assertCount(1, $this->thread->replies);
}
/** @test */
function a_thread_notifies_all_registered_subscribers_when_a_reply_is_added()
{
Notification::fake();
$this->signIn()
->thread
->subscribe()
->addReply([
'body' => 'Foobar',
'user_id' => 999
]);
Notification::assertSentTo(auth()->user(), ThreadWasUpdated::class);
}
/** @test */
function a_thread_belongs_to_a_channel()
{

0 comments on commit 7c9cee4

Please sign in to comment.