From 463de8d7e73c4ad1b41610a58789423bd371dc5b Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 20 Feb 2018 13:28:53 -0600 Subject: [PATCH] Make sure the rank restriction disabled works closes #170 --- tests/AcarsTest.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- tests/PIREPTest.php | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index bedc40a0..ccf83572 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -2,17 +2,21 @@ use App\Models\Enums\PirepState; use App\Models\Enums\PirepStatus; -use Tests\TestData; +use App\Repositories\SettingRepository; /** * Test API calls and authentication, etc */ class AcarsTest extends TestCase { + protected $settingsRepo; + public function setUp() { parent::setUp(); $this->addData('base'); + + $this->settingsRepo = app(SettingRepository::class); } /** @@ -267,6 +271,45 @@ class AcarsTest extends TestCase $response->assertStatus(201); } + /** + * Test aircraft permissions being ignored + */ + public function testIgnoreAircraftAllowed() + { + $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); + + $airport = factory(App\Models\Airport::class)->create(); + $airline = factory(App\Models\Airline::class)->create(); + + # Add subfleets and aircraft, but also add another set of subfleets + $subfleetA = $this->createSubfleetWithAircraft(1); + + // User not allowed aircraft from this subfleet + $subfleetB = $this->createSubfleetWithAircraft(1); + + $rank = $this->createRank(10, [$subfleetA['subfleet']->id]); + + $this->user = factory(App\Models\User::class)->create([ + 'rank_id' => $rank->id, + ]); + + $uri = '/api/pireps/prefile'; + $pirep = [ + 'airline_id' => $airline->id, + 'aircraft_id' => $subfleetB['aircraft']->random()->id, + 'dpt_airport_id' => $airport->icao, + 'arr_airport_id' => $airport->icao, + 'flight_number' => '6000', + 'level' => 38000, + 'planned_flight_time' => 120, + 'route' => 'POINTA POINTB', + 'source_name' => 'Unit test' + ]; + + $response = $this->post($uri, $pirep); + $response->assertStatus(201); + } + /** * Test publishing multiple, batched updates */ diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index e309ebc7..a365ccaa 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -7,6 +7,7 @@ use App\Models\Enums\AcarsType; use App\Models\Pirep; use App\Models\User; use App\Models\Enums\PirepState; +use App\Repositories\SettingRepository; class PIREPTest extends TestCase {