Fix subfleets not returning proper fare counts #831 (#846)

Fix subfleets not returning proper fare counts #831
This commit is contained in:
Nabeel S
2020-09-29 13:21:24 -04:00
committed by GitHub
parent b6603bd178
commit 98aa362935
3 changed files with 43 additions and 13 deletions

View File

@@ -5,8 +5,10 @@ namespace Tests;
use App\Exceptions\PilotIdNotFound;
use App\Exceptions\UserPilotIdExists;
use App\Models\Airline;
use App\Models\Fare;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Services\FareService;
use App\Services\UserService;
use Illuminate\Support\Facades\Hash;
@@ -86,11 +88,25 @@ class UserTest extends TestCase
*/
public function testGetAllAircraft()
{
$fare_svc = app(FareService::class);
// Add subfleets and aircraft, but also add another
// set of subfleets
$subfleetA = $this->createSubfleetWithAircraft();
$subfleetB = $this->createSubfleetWithAircraft();
$fare = factory(Fare::class)->create([
'price' => 20,
'capacity' => 200,
]);
$overrides = [
'price' => 50,
'capacity' => 400,
];
$fare_svc->setForSubfleet($subfleetA['subfleet'], $fare, $overrides);
$added_aircraft = array_merge(
$subfleetA['aircraft']->pluck('id')->toArray(),
$subfleetB['aircraft']->pluck('id')->toArray()
@@ -114,19 +130,22 @@ class UserTest extends TestCase
$this->assertEquals($added_aircraft, $all_aircraft);
$subfleetACalled = collect($subfleets)->firstWhere('id', $subfleetA['subfleet']->id);
$this->assertEquals($subfleetACalled->fares[0]['price'], $overrides['price']);
$this->assertEquals($subfleetACalled->fares[0]['capacity'], $overrides['capacity']);
/**
* Check via API
*/
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true);
$resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200);
// Get all the aircraft from that subfleet
// Get all the aircraft from that subfleet, check the fares
$body = $resp->json()['data'];
$aircraft_from_api = array_merge(
collect($body[0]['aircraft'])->pluck('id')->toArray(),
collect($body[1]['aircraft'])->pluck('id')->toArray()
);
$this->assertEquals($added_aircraft, $aircraft_from_api);
$subfleetAFromApi = collect($body)->firstWhere('id', $subfleetA['subfleet']->id);
$this->assertEquals($subfleetAFromApi['fares'][0]['price'], $overrides['price']);
$this->assertEquals($subfleetAFromApi['fares'][0]['capacity'], $overrides['capacity']);
}
/**