2018-03-18 01:55:50 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\UserAward;
|
|
|
|
|
|
|
|
class AwardsTest extends TestCase
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
private $awardSvc;
|
|
|
|
private $pirepSvc;
|
2018-03-18 01:55:50 +08:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->awardSvc = app(\App\Services\AwardService::class);
|
|
|
|
$this->pirepSvc = app(\App\Services\PirepService::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure the awards classes are returned
|
|
|
|
*/
|
|
|
|
public function testGetAwardsClasses()
|
|
|
|
{
|
|
|
|
$classes = $this->awardSvc->findAllAwardClasses();
|
|
|
|
$this->assertCount(2, $classes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to make sure that the award is actually given out
|
|
|
|
*/
|
|
|
|
public function testAwardsGiven()
|
|
|
|
{
|
|
|
|
// Create one award that's given out with one flight
|
|
|
|
$award = factory(App\Models\Award::class)->create([
|
2018-08-27 00:40:04 +08:00
|
|
|
'ref_model' => App\Awards\PilotFlightAwards::class,
|
2018-04-02 03:32:01 +08:00
|
|
|
'ref_model_params' => 1,
|
2018-03-18 01:55:50 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$user = factory(App\Models\User::class)->create([
|
|
|
|
'flights' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pirep = factory(App\Models\Pirep::class)->create([
|
|
|
|
'airline_id' => $user->airline->id,
|
2018-08-27 00:40:04 +08:00
|
|
|
'user_id' => $user->id,
|
2018-03-18 01:55:50 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->pirepSvc->create($pirep);
|
|
|
|
$this->pirepSvc->accept($pirep);
|
|
|
|
|
|
|
|
$w = [
|
2018-08-27 00:40:04 +08:00
|
|
|
'user_id' => $user->id,
|
2018-03-18 01:55:50 +08:00
|
|
|
'award_id' => $award->id,
|
|
|
|
];
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Make sure only one is awarded
|
2018-03-18 01:55:50 +08:00
|
|
|
$this->assertEquals(1, UserAward::where($w)->count(['id']));
|
|
|
|
|
|
|
|
$found_award = UserAward::where($w)->first();
|
|
|
|
$this->assertNotNull($found_award);
|
|
|
|
}
|
|
|
|
}
|