Notifications fixes (#804)
* Emails not sending #795 #722 * Fix for news items not being sent; refactor some events; check for opt-in #722 * Formatting * Remove extra parameter
This commit is contained in:
43
tests/NewsTest.php
Normal file
43
tests/NewsTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\Messages\NewsAdded;
|
||||
use App\Services\NewsService;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class NewsTest extends TestCase
|
||||
{
|
||||
/** @var NewsService */
|
||||
private $newsSvc;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->newsSvc = app(NewsService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that news is added but mainly that notifications are sent out to all users
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function testNewsNotifications()
|
||||
{
|
||||
/** @var User[] $users */
|
||||
$users_opt_in = factory(User::class, 5)->create(['opt_in' => true]);
|
||||
|
||||
/** @var User[] $users */
|
||||
$users_opt_out = factory(User::class, 5)->create(['opt_in' => false]);
|
||||
|
||||
$this->newsSvc->addNews([
|
||||
'user_id' => $users_opt_out[0]->id,
|
||||
'subject' => 'News Item',
|
||||
'body' => 'News!',
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($users_opt_in, NewsAdded::class);
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ use App\Models\Navdata;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Messages\PirepAccepted;
|
||||
use App\Notifications\Messages\PirepSubmitted;
|
||||
use App\Repositories\SettingRepository;
|
||||
use App\Services\AircraftService;
|
||||
use App\Services\BidService;
|
||||
use App\Services\FlightService;
|
||||
use App\Services\PirepService;
|
||||
use App\Services\UserService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
@@ -212,6 +214,38 @@ class PIREPTest extends TestCase
|
||||
$this->assertFalse($pirep_ids->contains($pirep_cancelled->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that a notification has been sent out to admins when a PIREP is submitted
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testPirepNotifications()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
'rank_id' => 1,
|
||||
]);
|
||||
|
||||
$admin = factory(User::class)->create();
|
||||
|
||||
/** @var UserService $userSvc */
|
||||
$userSvc = app(UserService::class);
|
||||
$userSvc->addUserToRole($admin, 'admin');
|
||||
|
||||
$pirep = factory(Pirep::class)->create([
|
||||
'airline_id' => 1,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->pirepSvc->create($pirep);
|
||||
$this->pirepSvc->submit($pirep);
|
||||
|
||||
// Make sure a notification was sent out to the admin
|
||||
Notification::assertSentTo([$admin], PirepSubmitted::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* check the stats/ranks, etc have incremented properly
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user