Check for null/0 value on progress percent

This commit is contained in:
Nabeel Shahzad
2022-03-18 16:43:34 -04:00
parent 12848091a2
commit ca8d96d2b6
2 changed files with 95 additions and 108 deletions

View File

@@ -578,6 +578,34 @@ class PIREPTest extends TestCase
$this->assertNull($user_bid);
}
public function testPirepProgressPercent()
{
$this->updateSetting('units.distance', 'km');
/** @var User $user */
$user = User::factory()->create();
/** @var Pirep $pirep */
$pirep = Pirep::factory()->create([
'user_id' => $user->id,
'distance' => 100,
'planned_distance' => 200,
'flight_time' => 60,
'planned_flight_time' => 90,
]);
$progress = $pirep->progress_percent;
$this->assertEquals(50, $progress);
$pirep->planned_distance = null;
$progress = $pirep->progress_percent;
$this->assertEquals(100, $progress);
$pirep->planned_distance = 0;
$progress = $pirep->progress_percent;
$this->assertEquals(100, $progress);
}
/**
* See that the notifications are properly formatted
*/