Add tests for the duplicate PIREP via prefile/API

This commit is contained in:
Nabeel Shahzad
2018-01-02 14:31:00 -06:00
parent 9c319e73f9
commit 7700bd6683
6 changed files with 37 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use Faker\Generator as Faker;
/**
@@ -35,7 +36,7 @@ $factory->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'];
},

View File

@@ -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',

View File

@@ -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;
});

View File

@@ -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'];
}
}

View File

@@ -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...

View File

@@ -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);
}