2017-12-14 01:29:14 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SubfleetTest extends TestCase
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
protected $ac_svc;
|
|
|
|
protected $ICAO = 'B777';
|
2017-12-14 01:29:14 +08:00
|
|
|
|
2019-05-12 23:50:38 +08:00
|
|
|
public function setUp(): void
|
2017-12-14 01:29:14 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->addData('base');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSubfleetFaresNoOverride()
|
|
|
|
{
|
|
|
|
$fare_svc = app('App\Services\FareService');
|
|
|
|
|
|
|
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
|
|
|
$fare = factory(App\Models\Fare::class)->create();
|
|
|
|
|
|
|
|
$fare_svc->setForSubfleet($subfleet, $fare);
|
|
|
|
$subfleet_fares = $fare_svc->getForSubfleet($subfleet);
|
|
|
|
|
|
|
|
$this->assertCount(1, $subfleet_fares);
|
|
|
|
$this->assertEquals($fare->price, $subfleet_fares->get(0)->price);
|
|
|
|
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
//
|
|
|
|
// set an override now
|
|
|
|
//
|
2017-12-14 01:29:14 +08:00
|
|
|
$fare_svc->setForSubfleet($subfleet, $fare, [
|
2018-08-27 00:40:04 +08:00
|
|
|
'price' => 50, 'capacity' => 400,
|
2017-12-14 01:29:14 +08:00
|
|
|
]);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// look for them again
|
2017-12-14 01:29:14 +08:00
|
|
|
$subfleet_fares = $fare_svc->getForSubfleet($subfleet);
|
|
|
|
|
|
|
|
$this->assertCount(1, $subfleet_fares);
|
|
|
|
$this->assertEquals(50, $subfleet_fares[0]->price);
|
|
|
|
$this->assertEquals(400, $subfleet_fares[0]->capacity);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// delete
|
2018-01-07 23:19:46 +08:00
|
|
|
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
2017-12-14 01:29:14 +08:00
|
|
|
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSubfleetFaresOverride()
|
|
|
|
{
|
|
|
|
$fare_svc = app('App\Services\FareService');
|
|
|
|
|
|
|
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
|
|
|
$fare = factory(App\Models\Fare::class)->create();
|
|
|
|
|
|
|
|
$fare_svc->setForSubfleet($subfleet, $fare, [
|
2018-08-27 00:40:04 +08:00
|
|
|
'price' => 50, 'capacity' => 400,
|
2017-12-14 01:29:14 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals(50, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals(400, $ac_fares[0]->capacity);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
//
|
|
|
|
// update the override to a different amount and make sure it updates
|
|
|
|
//
|
2017-12-14 01:29:14 +08:00
|
|
|
|
|
|
|
$fare_svc->setForSubfleet($subfleet, $fare, [
|
2018-08-27 00:40:04 +08:00
|
|
|
'price' => 150, 'capacity' => 50,
|
2017-12-14 01:29:14 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals(150, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals(50, $ac_fares[0]->capacity);
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// delete
|
2018-01-07 23:19:46 +08:00
|
|
|
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
2017-12-14 01:29:14 +08:00
|
|
|
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
|
|
|
}
|
|
|
|
}
|