Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asantibanez committed Mar 28, 2021
1 parent d9b19ea commit d533d77
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions tests/Feature/HasNotificationSubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,33 @@ public function can_subscribe_to_notification()
$user->subscribe($type);

//Assert
$this->assertEquals(1, NotificationSubscription::count());
$user->refresh();
$this->assertEquals(1, $user->notificationSubscriptions->count());

$this->assertEquals($type, $user->notificationSubscriptions->first()->type);
$this->assertEquals('*', $user->notificationSubscriptions->first()->channel);
}

/** @test */
public function can_subscribe_to_notification_specific_channel()
{
//Arrange
/** @var User $user */
$user = User::factory()->create();

//Act
$user->subscribe('notification', 'sms');

//Assert
$user->refresh();
$this->assertEquals(1, $user->notificationSubscriptions->count());

$this->assertEquals('notification', $user->notificationSubscriptions->first()->type);
$this->assertEquals('sms', $user->notificationSubscriptions->first()->channel);
}

/** @test */
public function can_unsubscribe_to_notification()
public function can_unsubscribe_from_notification()
{
//Arrange
/** @var User $user */
Expand All @@ -46,4 +68,28 @@ public function can_unsubscribe_to_notification()
//Assert
$this->assertNotNull(NotificationSubscription::first()->unsubscribed_at);
}

/** @test */
public function can_unsubscribe_from_notification_specific_channel()
{
//Arrange
/** @var User $user */
$user = User::factory()->create();

$smsNotification = $user->subscribe('notification', 'sms');
$emailNotification = $user->subscribe('notification', 'email');

$this->assertNull($smsNotification->unsubscribed_at);
$this->assertNull($emailNotification->unsubscribed_at);

//Act
$user->unsubscribe('notification', 'sms');

//Assert
$smsNotification->refresh();
$emailNotification->refresh();

$this->assertNotNull($smsNotification->unsubscribed_at);
$this->assertNull($emailNotification->unsubscribed_at);
}
}

0 comments on commit d533d77

Please sign in to comment.