Refactor broadcast notifications (#1402)
* Refactor broadcast notifications * StyleCI fixes * Fix the planned_distance accidental changes
This commit is contained in:
@@ -14,13 +14,12 @@ use App\Models\Pirep;
|
||||
use App\Models\Rank;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Messages\PirepAccepted;
|
||||
use App\Notifications\Messages\PirepSubmitted;
|
||||
use App\Notifications\Messages\PirepFiled;
|
||||
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 App\Support\Units\Fuel;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
@@ -156,6 +155,7 @@ class PIREPTest extends TestCase
|
||||
*/
|
||||
public function testUnitFields()
|
||||
{
|
||||
/** @var Pirep $pirep */
|
||||
$pirep = $this->createPirep();
|
||||
$pirep->save();
|
||||
|
||||
@@ -251,16 +251,13 @@ class PIREPTest extends TestCase
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
'name' => 'testPirepNotifications user',
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
'rank_id' => 1,
|
||||
]);
|
||||
|
||||
$admin = factory(User::class)->create();
|
||||
|
||||
/** @var UserService $userSvc */
|
||||
$userSvc = app(UserService::class);
|
||||
$userSvc->addUserToRole($admin, 'admin');
|
||||
$admin = $this->createAdminUser(['name' => 'testPirepNotifications Admin']);
|
||||
|
||||
$pirep = factory(Pirep::class)->create([
|
||||
'airline_id' => 1,
|
||||
@@ -271,7 +268,8 @@ class PIREPTest extends TestCase
|
||||
$this->pirepSvc->submit($pirep);
|
||||
|
||||
// Make sure a notification was sent out to the admin
|
||||
Notification::assertSentTo([$admin], PirepSubmitted::class);
|
||||
Notification::assertSentTo([$admin], PirepFiled::class);
|
||||
Notification::assertNotSentTo([$user], PirepFiled::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,6 +279,7 @@ class PIREPTest extends TestCase
|
||||
{
|
||||
$this->updateSetting('pilots.count_transfer_hours', false);
|
||||
|
||||
/** @var User $user */
|
||||
$user = factory(User::class)->create([
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
@@ -304,6 +303,7 @@ class PIREPTest extends TestCase
|
||||
$this->pirepSvc->accept($pirep);
|
||||
}
|
||||
|
||||
/** @var User $pilot */
|
||||
$pilot = User::find($user->id);
|
||||
$last_pirep = Pirep::where('id', $pilot->last_pirep_id)->first();
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Events\UserRegistered;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Messages\AdminUserRegistered;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
@@ -21,13 +20,12 @@ class RegistrationTest extends TestCase
|
||||
*/
|
||||
public function testRegistration()
|
||||
{
|
||||
Event::fake();
|
||||
Notification::fake();
|
||||
$admin = $this->createAdminUser(['name' => 'testRegistration Admin']);
|
||||
|
||||
/** @var UserService $userSvc */
|
||||
$userSvc = app(UserService::class);
|
||||
|
||||
setting('pilots.auto_accept', true);
|
||||
$this->updateSetting('pilots.auto_accept', true);
|
||||
|
||||
$attrs = factory(User::class)->make()->makeVisible(['api_key', 'name', 'email'])->toArray();
|
||||
$attrs['password'] = Hash::make('secret');
|
||||
@@ -35,14 +33,7 @@ class RegistrationTest extends TestCase
|
||||
|
||||
$this->assertEquals(UserState::ACTIVE, $user->state);
|
||||
|
||||
Event::assertDispatched(UserRegistered::class, function ($e) use ($user) {
|
||||
return $e->user->id === $user->id
|
||||
&& $e->user->state === $user->state;
|
||||
});
|
||||
|
||||
/*Notification::assertSentTo(
|
||||
[$user],
|
||||
\App\Notifications\Messages\UserRegistered::class
|
||||
);*/
|
||||
Notification::assertSentTo([$admin], AdminUserRegistered::class);
|
||||
Notification::assertNotSentTo([$user], AdminUserRegistered::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
||||
);
|
||||
|
||||
Artisan::call('database:create', ['--reset' => true]);
|
||||
Artisan::call('migrate:refresh', ['--env' => 'testing', '--force' => true]);
|
||||
Artisan::call('migrate', ['--env' => 'testing', '--force' => true]);
|
||||
|
||||
Notification::fake();
|
||||
// $this->disableExceptionHandling();
|
||||
@@ -71,6 +71,7 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
||||
protected function disableExceptionHandling()
|
||||
{
|
||||
$this->app->instance(ExceptionHandler::class, new class() extends Handler {
|
||||
/** @noinspection PhpMissingParentConstructorInspection */
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Pirep;
|
||||
use App\Models\Role;
|
||||
use App\Models\Subfleet;
|
||||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
use Exception;
|
||||
|
||||
trait TestData
|
||||
@@ -32,6 +33,25 @@ trait TestData
|
||||
], $attrs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an admin user
|
||||
*
|
||||
* @param array $attrs
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function createAdminUser(array $attrs = []): User
|
||||
{
|
||||
/** @var User $admin */
|
||||
$admin = factory(User::class)->create($attrs);
|
||||
|
||||
/** @var UserService $userSvc */
|
||||
$userSvc = app(UserService::class);
|
||||
$userSvc->addUserToRole($admin, 'admin');
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PIREP with a proper subfleet/rank/user and an
|
||||
* aircraft that the user is allowed to fly
|
||||
|
||||
Reference in New Issue
Block a user