Skip to content

Commit

Permalink
Add tests that rank shouldn't auto change (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Oct 10, 2020
1 parent 0a5194b commit c702b01
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/PIREPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -317,6 +318,46 @@ public function testPilotStatsIncr()
$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
*/
Expand Down

0 comments on commit c702b01

Please sign in to comment.