phpvms/tests/PIREPTest.php
2017-07-04 01:05:23 -05:00

65 lines
1.9 KiB
PHP

<?php
use App\Models\Pirep;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PIREPTest extends TestCase
{
use WithoutMiddleware;
protected $pirepSvc;
protected $SAMPLE_PIREP
= [
'user_id' => 1,
'flight_id' => 1,
'aircraft_id' => 1,
'dpt_airport_id' => 1,
'arr_airport_id' => 2,
'flight_time' => 21600, # 6 hours
'level' => 320,
'source' => 0, # manual
'notes' => 'just a pilot report',
];
public function setUp()
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->addData('base');
$this->pirepSvc = app('App\Services\PIREPService');
}
public function testAddPirep()
{
$pirep = new Pirep($this->SAMPLE_PIREP);
$pirep->save();
$pirep = $this->pirepSvc->create($pirep, []);
/**
* Check the initial status info
*/
$this->assertEquals($pirep->pilot->flights, 0);
$this->assertEquals($pirep->status, VMSEnums::$pirep_status['PENDING']);
/**
* Now set the PIREP state to ACCEPTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['ACCEPTED']);
$this->assertEquals(1, $pirep->pilot->flights);
$this->assertEquals(21600, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
/**
* Now go from ACCEPTED to REJECTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['REJECTED']);
$this->assertEquals(0, $pirep->pilot->flights);
$this->assertEquals(0, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
}
}