diff --git a/app/Database/factories/PirepFactory.php b/app/Database/factories/PirepFactory.php index 3a1ed5ae..1f5dcf27 100644 --- a/app/Database/factories/PirepFactory.php +++ b/app/Database/factories/PirepFactory.php @@ -1,5 +1,6 @@ define(App\Models\Pirep::class, function (Faker $faker) { 'arr_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'altitude' => $faker->numberBetween(20, 400), + 'level' => $faker->numberBetween(20, 400), 'flight_time' => $faker->randomFloat(2), 'planned_flight_time' => $faker->randomFloat(2), 'gross_weight' => $faker->randomFloat(2), @@ -45,7 +46,7 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) { 'state' => PirepState::PENDING, 'status' => PirepStatus::SCHEDULED, 'raw_data' => $raw_data ?: $raw_data = json_encode(['key' => 'value']), - 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), + 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => function(array $pirep) { return $pirep['created_at']; }, diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index 19d77e2c..08107a3e 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -37,8 +37,8 @@ class PirepController extends AppBaseController 'arr_airport_id', 'flight_id', 'flight_number', - 'route_leg', 'route_code', + 'route_leg', 'flight_time', 'planned_flight_time', 'level', diff --git a/app/Http/Middleware/ApiAuth.php b/app/Http/Middleware/ApiAuth.php index 8e411b28..4fcac986 100644 --- a/app/Http/Middleware/ApiAuth.php +++ b/app/Http/Middleware/ApiAuth.php @@ -38,7 +38,7 @@ class ApiAuth // Set the user to the request Auth::setUser($user); - $request->merge(['user' => $user]); + //$request->merge(['user' => $user]); $request->setUserResolver(function () use ($user) { return $user; }); diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index 2109fece..f0ecbe93 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -37,7 +37,8 @@ class AcarsTest extends TestCase 'aircraft_id' => $aircraft->id, 'dpt_airport_id' => $airport->icao, 'arr_airport_id' => $airport->icao, - 'altitude' => 38000, + 'flight_number' => '6000', + 'level' => 38000, 'planned_flight_time' => 120, 'route' => 'POINTA POINTB', ]; @@ -115,4 +116,24 @@ class AcarsTest extends TestCase $body = $response->json(); $this->assertEquals($dt, $body[0]['sim_time']);*/ } + + /** + * Try to refile the same PIREP + */ + public function testDuplicatePirep() + { + $uri = '/api/pireps/prefile'; + $user = factory(App\Models\User::class)->create(); + $pirep = factory(App\Models\Pirep::class)->make(['id' => ''])->toArray(); + + $response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep); +// $response = $this->withHeaders($this->headers($user->api_key))->post($uri, $pirep); + $response->assertStatus(201); + $pirep = $response->json(); + + $response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep); + $response->assertStatus(200); + $body = $response->json(); + echo $body['id']; + } } diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index ad2c25dc..27321e5c 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -171,10 +171,7 @@ class PIREPTest extends TestCase */ public function testDuplicatePireps() { - $pirep = factory(Pirep::class)->create([ - 'created_at' => Carbon::now()->toDateTimeString(), - 'updated_at' => Carbon::now()->toDateTimeString() - ]); + $pirep = factory(Pirep::class)->create(); # This should find itself... $dupe_pirep = $this->pirepSvc->findDuplicate($pirep); @@ -187,8 +184,7 @@ class PIREPTest extends TestCase $minutes = setting('pireps.duplicate_check_time') + 1; $pirep = factory(Pirep::class)->create([ - 'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString(), - 'updated_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString() + 'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString() ]); # This should find itself... diff --git a/tests/TestCase.php b/tests/TestCase.php index 21c559f5..cea732ca 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,6 +27,14 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase return self::$auth_headers; } + public function headers($api_key) + { + return [ + 'content-type' => 'application/json', + 'x-api-key' => $api_key + ]; + } + public function __construct($name = null, array $data = [], $dataName = '') { parent::__construct($name, $data, $dataName); }