Add setting to include transfer hours in calculations (#350)

* Add setting to include transfer hours in calculations

* Add some extra tests to check versions

* A couple of more version test cases
This commit is contained in:
Nabeel S
2019-08-08 12:50:43 -04:00
committed by GitHub
parent ff6ba4c29a
commit a08c9db284
12 changed files with 169 additions and 83 deletions

View File

@@ -196,6 +196,8 @@ class PIREPTest extends TestCase
*/
public function testPilotStatsIncr()
{
$this->updateSetting('pilots.count_transfer_hours', false);
$user = factory(User::class)->create([
'flights' => 0,
'flight_time' => 0,
@@ -254,6 +256,41 @@ class PIREPTest extends TestCase
$this->assertNotEquals($last_pirep->id, $latest_pirep->id);
}
/**
* check the stats/ranks, etc have incremented properly
*/
public function testPilotStatsIncrWithTransferHours()
{
$this->updateSetting('pilots.count_transfer_hours', true);
$user = factory(User::class)->create([
'flights' => 0,
'flight_time' => 0,
'transfer_time' => 720,
'rank_id' => 1,
]);
// Submit two PIREPs
// 1 hour flight times, but the rank should bump up because of the transfer hours
$pireps = factory(Pirep::class, 2)->create([
'airline_id' => $user->airline_id,
'aircraft_id' => 1,
'user_id' => $user->id,
'flight_time' => 60,
]);
foreach ($pireps as $pirep) {
$this->pirepSvc->create($pirep);
$this->pirepSvc->accept($pirep);
}
$pilot = User::find($user->id);
$last_pirep = Pirep::where('id', $pilot->last_pirep_id)->first();
// Make sure rank went up
$this->assertGreaterThan($user->rank_id, $pilot->rank_id);
}
/**
* Find and check for any duplicate PIREPs by a user
*/

View File

@@ -14,7 +14,26 @@ class VersionTest extends TestCase
$this->kvpRepo = app(KvpRepository::class);
}
public function testGetLatestVersion()
/**
* Test that the new versions (keys) are properly regarded as new versions
*/
public function testGreaterThanVersionStrings(): void
{
$test = [
'7.0.0' => '6.0.0',
'7.0.0-beta' => '7.0.0-alpha',
'7.0.0-beta.1' => '7.0.0-beta',
'7.0.0-beta.2' => '7.0.0-beta.1',
'7.0.0-beta.1' => '7.0.0-alpha',
];
$versionSvc = app(VersionService::class);
foreach ($test as $newVersion => $currentVersion) {
$this->assertTrue($versionSvc->isGreaterThan($newVersion, $currentVersion));
}
}
public function testGetLatestVersion(): void
{
setting('general.check_prerelease_version', false);
@@ -27,7 +46,7 @@ class VersionTest extends TestCase
$this->assertEquals('7.0.0-alpha2', $this->kvpRepo->get('latest_version_tag'));
}
public function testGetLatestPrereleaseVersion()
public function testGetLatestPrereleaseVersion(): void
{
$this->updateSetting('general.check_prerelease_version', true);
@@ -40,7 +59,7 @@ class VersionTest extends TestCase
$this->assertEquals('7.0.0-beta', $this->kvpRepo->get('latest_version_tag'));
}
public function testNewVersionNotAvailable()
public function testNewVersionNotAvailable(): void
{
$this->updateSetting('general.check_prerelease_version', false);
@@ -59,7 +78,10 @@ class VersionTest extends TestCase
}
}
public function testNewVersionIsAvailable()
/**
* Version in the prerelease releases.json is v7.0.0-beta
*/
public function testNewVersionIsAvailable(): void
{
$this->updateSetting('general.check_prerelease_version', true);