From 60cec870f6d13ae8fe274b2d474e0044b0f8f54b Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 14 Feb 2022 12:53:12 -0500 Subject: [PATCH] Add aircraft ident to API response --- app/Http/Resources/Aircraft.php | 10 ++++++++++ tests/ApiTest.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/app/Http/Resources/Aircraft.php b/app/Http/Resources/Aircraft.php index 86d6c225..235eff0a 100644 --- a/app/Http/Resources/Aircraft.php +++ b/app/Http/Resources/Aircraft.php @@ -4,6 +4,16 @@ namespace App\Http\Resources; use App\Contracts\Resource; +/** + * @mixin \App\Models\Aircraft + */ class Aircraft extends Resource { + public function toArray($request) + { + $res = parent::toArray($request); + $res['ident'] = $this->ident; + + return $res; + } } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 7a11d557..aff9435a 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -279,6 +279,9 @@ class ApiTest extends TestCase } $this->assertCount($size, $subfleet['aircraft']); + foreach ($subfleet['aircraft'] as $aircraft) { + $this->assertNotEmpty($aircraft['ident']); + } } } @@ -314,6 +317,7 @@ class ApiTest extends TestCase $this->assertEquals($body['id'], $aircraft->id); $this->assertEquals($body['name'], $aircraft->name); + $this->assertNotEmpty($body['ident']); $this->assertEquals($body['mtow'], $aircraft->mtow); $this->assertEquals($body['zfw'], $aircraft->zfw); @@ -325,6 +329,9 @@ class ApiTest extends TestCase $this->assertEquals($body['mtow'], $aircraft->mtow); $this->assertEquals($body['zfw'], $aircraft->zfw); + $this->assertNotEmpty($body['ident']); + $this->assertEquals($body['ident'], $aircraft->ident); + $resp = $this->get('/api/fleet/aircraft/'.$aircraft->id.'?icao='.$aircraft->icao); $body = $resp->json()['data'];