WIP - Tests for notifications
This commit is contained in:
@@ -73,18 +73,6 @@ class NewIncidentNotification extends Notification
|
|||||||
'name' => $this->incident->name,
|
'name' => $this->incident->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dd(new MailMessage())
|
|
||||||
->subject(trans('notifications.incident.new.mail.subject'))
|
|
||||||
->markdown('notifications.incident.new', [
|
|
||||||
'incident' => $this->incident,
|
|
||||||
'content' => $content,
|
|
||||||
'actionText' => trans('notifications.incident.new.mail.action'),
|
|
||||||
'actionUrl' => cachet_route('incident', [$this->incident]),
|
|
||||||
'unsubscribeText' => trans('cachet.subscriber.unsubscribe'),
|
|
||||||
'unsubscribeUrl' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code),
|
|
||||||
'manageSubscriptionText' => trans('cachet.subscriber.manage_subscription'),
|
|
||||||
'manageSubscriptionUrl' => cachet_route('subscribe.manage', $notifiable->verify_code),
|
|
||||||
]);
|
|
||||||
return (new MailMessage())
|
return (new MailMessage())
|
||||||
->subject(trans('notifications.incident.new.mail.subject'))
|
->subject(trans('notifications.incident.new.mail.subject'))
|
||||||
->markdown('notifications.incident.new', [
|
->markdown('notifications.incident.new', [
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ use CachetHQ\Tests\Cachet\AbstractTestCase;
|
|||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use CachetHQ\Cachet\Settings\Repository as SettingsRepository;
|
use CachetHQ\Cachet\Settings\Repository as SettingsRepository;
|
||||||
use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand;
|
use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand;
|
||||||
use Mail;
|
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand;
|
||||||
|
use CachetHQ\Cachet\Notifications\Incident\NewIncidentNotification;
|
||||||
|
use CachetHQ\Cachet\Notifications\IncidentUpdate\IncidentUpdatedNotification;
|
||||||
|
use CachetHQ\Cachet\Models\Subscriber;
|
||||||
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class MailTest extends AbstractTestCase
|
class MailTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
@@ -31,6 +37,11 @@ class MailTest extends AbstractTestCase
|
|||||||
*/
|
*/
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array[]|null
|
||||||
|
*/
|
||||||
|
protected $incidents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -58,26 +69,64 @@ class MailTest extends AbstractTestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->app->make(SettingsRepository::class)->set('app_name', $this->appName);
|
$this->app->make(SettingsRepository::class)->set('app_name', $this->appName);
|
||||||
$this->app->config->set('setting.app_name', $this->appName);
|
$this->app->config->set('setting.app_name', $this->appName);
|
||||||
}
|
$this->incidents = [
|
||||||
|
['title' => 'Foo '.Str::random(16), 'description' => 'Foo Bar Baz '.Str::random(32)],
|
||||||
public function createSubscriber()
|
['title' => 'Foe '.Str::random(16), 'description' => 'Foe Baz Bar '.Str::random(32)],
|
||||||
{
|
];
|
||||||
dispatch(new SubscribeSubscriberCommand(
|
|
||||||
$this->fakerFactory->safeEmail,
|
|
||||||
true
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a notification to subscribers when a new incident
|
* Create a new subscriber.
|
||||||
|
*/
|
||||||
|
public function createSubscriber($subscriberEmail)
|
||||||
|
{
|
||||||
|
dispatch(new SubscribeSubscriberCommand(
|
||||||
|
$subscriberEmail,
|
||||||
|
true
|
||||||
|
));
|
||||||
|
|
||||||
|
return Subscriber::where('email', '=', $subscriberEmail)->firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $incident
|
||||||
|
* @param array $meta
|
||||||
|
*
|
||||||
|
* @return Incident
|
||||||
|
*/
|
||||||
|
protected function createIncident(array $incident)
|
||||||
|
{
|
||||||
|
$name = $incident['title'];
|
||||||
|
$message = $incident['description'];
|
||||||
|
|
||||||
|
dispatch(new CreateIncidentCommand(
|
||||||
|
$name,
|
||||||
|
$this->fakerFactory->numberBetween(0, 3),
|
||||||
|
$message,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
$this->fakerFactory->date('Y-m-d H:i'),
|
||||||
|
null,
|
||||||
|
[]
|
||||||
|
));
|
||||||
|
|
||||||
|
return Incident::where('name', '=', $name)->where('message', '=', $message)->firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email notification to subscribers when a new incident
|
||||||
* is added.
|
* is added.
|
||||||
*/
|
*/
|
||||||
public function testNotificationSentForNewIncident()
|
public function testEmailNotificationSentForNewIncident()
|
||||||
{
|
{
|
||||||
Mail::fake();
|
Notification::fake();
|
||||||
|
|
||||||
$this->signIn();
|
$this->signIn();
|
||||||
$this->createSubscriber();
|
|
||||||
|
$subscriber = $this->createSubscriber($this->fakerFactory->safeEmail);
|
||||||
|
|
||||||
$response = $this->post('dashboard/incidents/create', [
|
$response = $this->post('dashboard/incidents/create', [
|
||||||
'name' => $this->fakerFactory->word,
|
'name' => $this->fakerFactory->word,
|
||||||
@@ -87,6 +136,55 @@ class MailTest extends AbstractTestCase
|
|||||||
'notify' => 1
|
'notify' => 1
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Mail::assertSent(NewIncidentNotification::class);
|
Notification::assertSentTo(
|
||||||
|
[$subscriber], NewIncidentNotification::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not send an email if notify not checked.
|
||||||
|
*/
|
||||||
|
public function testEmailNotificationNotSentWhenNotifyNotCheckedForNewIncident()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->signIn();
|
||||||
|
|
||||||
|
$subscriber = $this->createSubscriber($this->fakerFactory->safeEmail);
|
||||||
|
|
||||||
|
$response = $this->post('dashboard/incidents/create', [
|
||||||
|
'name' => $this->fakerFactory->word,
|
||||||
|
'status' => 1,
|
||||||
|
'visible' => 1,
|
||||||
|
'message' => $this->fakerFactory->paragraph,
|
||||||
|
'notify' => 0
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertNotSentTo(
|
||||||
|
[$subscriber], NewIncidentNotification::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an email notification to subscribers when an incident
|
||||||
|
* update is added.
|
||||||
|
*/
|
||||||
|
public function testEmailNotificationSentForIncidentUpdate()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->signIn();
|
||||||
|
|
||||||
|
$incident = $this->createIncident($this->incidents[1]);
|
||||||
|
$subscriber = $this->createSubscriber($this->fakerFactory->safeEmail);
|
||||||
|
|
||||||
|
$response = $this->post('dashboard/incidents/'.$incident->id.'/updates/create', [
|
||||||
|
'status' => 1,
|
||||||
|
'message' => $this->fakerFactory->paragraph,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertSentTo(
|
||||||
|
[$subscriber], IncidentUpdatedNotification::class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user