Add tests for the duplicate PIREP via prefile/API
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Faker\Generator as Faker;
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,7 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
|
|||||||
'arr_airport_id' => function () {
|
'arr_airport_id' => function () {
|
||||||
return factory(App\Models\Airport::class)->create()->id;
|
return factory(App\Models\Airport::class)->create()->id;
|
||||||
},
|
},
|
||||||
'altitude' => $faker->numberBetween(20, 400),
|
'level' => $faker->numberBetween(20, 400),
|
||||||
'flight_time' => $faker->randomFloat(2),
|
'flight_time' => $faker->randomFloat(2),
|
||||||
'planned_flight_time' => $faker->randomFloat(2),
|
'planned_flight_time' => $faker->randomFloat(2),
|
||||||
'gross_weight' => $faker->randomFloat(2),
|
'gross_weight' => $faker->randomFloat(2),
|
||||||
@@ -45,7 +46,7 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
|
|||||||
'state' => PirepState::PENDING,
|
'state' => PirepState::PENDING,
|
||||||
'status' => PirepStatus::SCHEDULED,
|
'status' => PirepStatus::SCHEDULED,
|
||||||
'raw_data' => $raw_data ?: $raw_data = json_encode(['key' => 'value']),
|
'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) {
|
'updated_at' => function(array $pirep) {
|
||||||
return $pirep['created_at'];
|
return $pirep['created_at'];
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ class PirepController extends AppBaseController
|
|||||||
'arr_airport_id',
|
'arr_airport_id',
|
||||||
'flight_id',
|
'flight_id',
|
||||||
'flight_number',
|
'flight_number',
|
||||||
'route_leg',
|
|
||||||
'route_code',
|
'route_code',
|
||||||
|
'route_leg',
|
||||||
'flight_time',
|
'flight_time',
|
||||||
'planned_flight_time',
|
'planned_flight_time',
|
||||||
'level',
|
'level',
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class ApiAuth
|
|||||||
|
|
||||||
// Set the user to the request
|
// Set the user to the request
|
||||||
Auth::setUser($user);
|
Auth::setUser($user);
|
||||||
$request->merge(['user' => $user]);
|
//$request->merge(['user' => $user]);
|
||||||
$request->setUserResolver(function () use ($user) {
|
$request->setUserResolver(function () use ($user) {
|
||||||
return $user;
|
return $user;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class AcarsTest extends TestCase
|
|||||||
'aircraft_id' => $aircraft->id,
|
'aircraft_id' => $aircraft->id,
|
||||||
'dpt_airport_id' => $airport->icao,
|
'dpt_airport_id' => $airport->icao,
|
||||||
'arr_airport_id' => $airport->icao,
|
'arr_airport_id' => $airport->icao,
|
||||||
'altitude' => 38000,
|
'flight_number' => '6000',
|
||||||
|
'level' => 38000,
|
||||||
'planned_flight_time' => 120,
|
'planned_flight_time' => 120,
|
||||||
'route' => 'POINTA POINTB',
|
'route' => 'POINTA POINTB',
|
||||||
];
|
];
|
||||||
@@ -115,4 +116,24 @@ class AcarsTest extends TestCase
|
|||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
$this->assertEquals($dt, $body[0]['sim_time']);*/
|
$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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,10 +171,7 @@ class PIREPTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDuplicatePireps()
|
public function testDuplicatePireps()
|
||||||
{
|
{
|
||||||
$pirep = factory(Pirep::class)->create([
|
$pirep = factory(Pirep::class)->create();
|
||||||
'created_at' => Carbon::now()->toDateTimeString(),
|
|
||||||
'updated_at' => Carbon::now()->toDateTimeString()
|
|
||||||
]);
|
|
||||||
|
|
||||||
# This should find itself...
|
# This should find itself...
|
||||||
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
||||||
@@ -187,8 +184,7 @@ class PIREPTest extends TestCase
|
|||||||
|
|
||||||
$minutes = setting('pireps.duplicate_check_time') + 1;
|
$minutes = setting('pireps.duplicate_check_time') + 1;
|
||||||
$pirep = factory(Pirep::class)->create([
|
$pirep = factory(Pirep::class)->create([
|
||||||
'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString(),
|
'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString()
|
||||||
'updated_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString()
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
# This should find itself...
|
# This should find itself...
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
return self::$auth_headers;
|
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 = '') {
|
public function __construct($name = null, array $data = [], $dataName = '') {
|
||||||
parent::__construct($name, $data, $dataName);
|
parent::__construct($name, $data, $dataName);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user