-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests notifications #3816
Merged
Merged
Tests notifications #3816
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Cachet. | ||
* | ||
* (c) Alt Three Services Limited | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CachetHQ\Tests\Cachet\Functional\Notifications; | ||
|
||
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand; | ||
use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand; | ||
use CachetHQ\Cachet\Models\Incident; | ||
use CachetHQ\Cachet\Models\Subscriber; | ||
use CachetHQ\Cachet\Notifications\Incident\NewIncidentNotification; | ||
use CachetHQ\Cachet\Notifications\IncidentUpdate\IncidentUpdatedNotification; | ||
use CachetHQ\Cachet\Settings\Repository as SettingsRepository; | ||
use CachetHQ\Tests\Cachet\AbstractTestCase; | ||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Illuminate\Support\Facades\Notification; | ||
use Illuminate\Support\Str; | ||
|
||
class MailTest extends AbstractTestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
/** | ||
* @var \Faker\Generator | ||
*/ | ||
protected $fakerFactory; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $appName; | ||
|
||
/** | ||
* @var array[]|null | ||
*/ | ||
protected $incidents; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $subscriber; | ||
|
||
/** | ||
* MailTest constructor. | ||
* | ||
* @param null $name | ||
* @param array $data | ||
* @param string $dataName | ||
*/ | ||
public function __construct($name = null, array $data = [], $dataName = '') | ||
{ | ||
parent::__construct($name, $data, $dataName); | ||
$this->fakerFactory = \Faker\Factory::create(); | ||
$this->appName = 'MailTest'; | ||
} | ||
|
||
/** | ||
* Setup the application. | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->app->make(SettingsRepository::class)->set('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)], | ||
['title' => 'Foe '.Str::random(16), 'description' => 'Foe Baz Bar '.Str::random(32)], | ||
]; | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public function testEmailNotificationSentForNewIncident() | ||
{ | ||
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' => 1 | ||
]); | ||
|
||
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 | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Data-Kiss Could it be a stray space?