Make sure stdclass is returned in flight fields

This commit is contained in:
Nabeel Shahzad 2020-10-29 12:38:40 -04:00
parent a58237b04b
commit 0fa00206ce
2 changed files with 12 additions and 4 deletions

View File

@ -18,17 +18,17 @@ class Flight extends Resource
private function setFields()
{
/** @var \Illuminate\Support\Collection $field_values */
$return_values = new stdClass();
$field_values = $this->field_values;
if (empty($field_values) || $field_values->count() === 0) {
return new stdClass();
return $return_values;
}
$fields = [];
foreach ($field_values as $field) {
$fields[$field->name] = $field->value;
$return_values->{$field->name} = $field->value;
}
return $fields;
return $return_values;
}
/**

View File

@ -113,12 +113,20 @@ class FlightTest extends TestCase
*/
public function testSearchFlight()
{
/** @var \App\Models\User user */
$this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user);
/** @var \App\Services\FlightService $flightSvc */
$flightSvc = app(FlightService::class);
$flightSvc->updateCustomFields($flight, [
['name' => '0', 'value' => 'value'],
]);
// search specifically for a flight ID
$query = 'flight_id='.$flight->id;
$req = $this->get('/api/flights/search?'.$query);
$body = $req->json(['data']);
$req->assertStatus(200);
}