From c702b01a8756f0dc7cf391ea6c30d27cc78af7d2 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Sat, 10 Oct 2020 14:50:00 -0400 Subject: [PATCH] Add tests that rank shouldn't auto change (#840) --- tests/PIREPTest.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index f04df710..87803121 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -11,6 +11,7 @@ use App\Models\Enums\UserState; use App\Models\Flight; use App\Models\Navdata; use App\Models\Pirep; +use App\Models\Rank; use App\Models\User; use App\Notifications\Messages\PirepAccepted; use App\Notifications\Messages\PirepSubmitted; @@ -317,6 +318,46 @@ class PIREPTest extends TestCase $this->assertNotEquals($last_pirep->id, $latest_pirep->id); } + /** + * Assign a rank to a user which is not set to auto-promote; make that that the flight + * hours and submitted PIREP doesn't change the rank + * + * @throws \Exception + */ + public function testPilotDontChangeRank() + { + /** @var Rank $rank */ + $rank = factory(Rank::class)->create([ + 'hours' => 15, + 'auto_promote' => false, + ]); + + // Set the user to the above rank, non-promote, they shouldn't bump down + + /** @var User $user */ + $user = factory(User::class)->create([ + 'flights' => 0, + 'flight_time' => 0, + 'rank_id' => $rank->id, + ]); + + // Submit two PIREPs + $pirep = factory(Pirep::class)->create([ + 'airline_id' => $user->airline_id, + 'aircraft_id' => 1, + 'user_id' => $user->id, + 'flight_time' => 10 * 60, // 10 hours, eligible for Junior First Officer + ]); + + $this->pirepSvc->create($pirep); + $this->pirepSvc->accept($pirep); + + $pilot = User::find($user->id); + + // Make sure rank didn't change + $this->assertEquals($rank->id, $pilot->rank_id); + } + /** * check the stats/ranks, etc have incremented properly */