Add tests that rank shouldn't auto change (#840)

This commit is contained in:
Nabeel S 2020-10-10 14:50:00 -04:00 committed by GitHub
parent 0a5194b92e
commit c702b01a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ use App\Models\Enums\UserState;
use App\Models\Flight; use App\Models\Flight;
use App\Models\Navdata; use App\Models\Navdata;
use App\Models\Pirep; use App\Models\Pirep;
use App\Models\Rank;
use App\Models\User; use App\Models\User;
use App\Notifications\Messages\PirepAccepted; use App\Notifications\Messages\PirepAccepted;
use App\Notifications\Messages\PirepSubmitted; use App\Notifications\Messages\PirepSubmitted;
@ -317,6 +318,46 @@ class PIREPTest extends TestCase
$this->assertNotEquals($last_pirep->id, $latest_pirep->id); $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 * check the stats/ranks, etc have incremented properly
*/ */