Apply fixes from StyleCI
This commit is contained in:
committed by
StyleCI Bot
parent
20f46adbc4
commit
9596d88b48
@@ -77,19 +77,18 @@ class AcarsTest extends TestCase
|
||||
*/
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'_airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'_airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_flight_time' => 120,
|
||||
'route' => 'POINTA POINTB',
|
||||
'route' => 'POINTA POINTB',
|
||||
];
|
||||
|
||||
$response = $this->post($uri, $pirep);
|
||||
$response->assertStatus(400);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +145,7 @@ class AcarsTest extends TestCase
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
$aircraft = factory(App\Models\Aircraft::class)->create([
|
||||
'airport_id' => 'KAUS'
|
||||
'airport_id' => 'KAUS',
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -192,22 +191,22 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_distance' => 400,
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_distance' => 400,
|
||||
'planned_flight_time' => 120,
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'UnitTest',
|
||||
'fields' => [
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'UnitTest',
|
||||
'fields' => [
|
||||
'custom_field' => 'custom_value',
|
||||
],
|
||||
'fares' => [
|
||||
[
|
||||
'id' => $fare->id,
|
||||
'id' => $fare->id,
|
||||
'count' => $fare->capacity,
|
||||
],
|
||||
],
|
||||
@@ -217,7 +216,7 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(201);
|
||||
$pirep = $response->json('data');
|
||||
|
||||
# See that the fields and fares were set
|
||||
// See that the fields and fares were set
|
||||
$fares = \App\Models\PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$this->assertCount(1, $fares);
|
||||
$saved_fare = $fares->first();
|
||||
@@ -225,7 +224,7 @@ class AcarsTest extends TestCase
|
||||
$this->assertEquals($fare->id, $saved_fare['fare_id']);
|
||||
$this->assertEquals($fare->capacity, $saved_fare['count']);
|
||||
|
||||
# Check saved fields
|
||||
// Check saved fields
|
||||
$saved_fields = \App\Models\PirepFieldValue::where('pirep_id', $pirep['id'])->get();
|
||||
$this->assertCount(1, $saved_fields);
|
||||
$field = $saved_fields->first();
|
||||
@@ -240,7 +239,7 @@ class AcarsTest extends TestCase
|
||||
$update = [
|
||||
'fares' => [
|
||||
[
|
||||
'id' => $fare->id,
|
||||
'id' => $fare->id,
|
||||
'count' => $fare->capacity,
|
||||
],
|
||||
],
|
||||
@@ -250,7 +249,7 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
$updated_pirep = $response->json('data');
|
||||
|
||||
# Make sure there are no duplicates
|
||||
// Make sure there are no duplicates
|
||||
$fares = \App\Models\PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$this->assertCount(1, $fares);
|
||||
$saved_fare = $fares->first();
|
||||
@@ -279,17 +278,17 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_distance' => 400,
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_distance' => 400,
|
||||
'planned_flight_time' => 120,
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'AcarsTest::testAcarsUpdates',
|
||||
'fields' => [
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'AcarsTest::testAcarsUpdates',
|
||||
'fields' => [
|
||||
'custom_field' => 'custom_value',
|
||||
],
|
||||
];
|
||||
@@ -297,7 +296,7 @@ class AcarsTest extends TestCase
|
||||
$response = $this->post($uri, $pirep);
|
||||
$response->assertStatus(201);
|
||||
|
||||
# Get the PIREP ID
|
||||
// Get the PIREP ID
|
||||
$body = $response->json();
|
||||
$pirep_id = $body['data']['id'];
|
||||
|
||||
@@ -305,12 +304,12 @@ class AcarsTest extends TestCase
|
||||
$this->assertNotNull($pirep_id);
|
||||
$this->assertEquals($body['data']['user_id'], $this->user->id);
|
||||
|
||||
# Check the PIREP state and status
|
||||
// Check the PIREP state and status
|
||||
$pirep = $this->getPirep($pirep_id);
|
||||
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
||||
$this->assertEquals(PirepStatus::INITIATED, $pirep['status']);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Check the fields
|
||||
*/
|
||||
$this->assertHasKeys($pirep, ['fields']);
|
||||
@@ -334,16 +333,15 @@ class AcarsTest extends TestCase
|
||||
/**
|
||||
* Add some position updates
|
||||
*/
|
||||
|
||||
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
||||
|
||||
# Test missing positions field
|
||||
# Post an ACARS update
|
||||
// Test missing positions field
|
||||
// Post an ACARS update
|
||||
$update = [];
|
||||
$response = $this->post($uri, $update);
|
||||
$response->assertStatus(400);
|
||||
|
||||
# Post an ACARS update
|
||||
// Post an ACARS update
|
||||
$acars = factory(App\Models\Acars::class)->make(['pirep_id' => $pirep_id])->toArray();
|
||||
|
||||
$acars = $this->transformData($acars);
|
||||
@@ -352,13 +350,13 @@ class AcarsTest extends TestCase
|
||||
$response = $this->post($uri, $update);
|
||||
$response->assertStatus(200)->assertJson(['count' => 1]);
|
||||
|
||||
# Read that if the ACARS record posted
|
||||
// Read that if the ACARS record posted
|
||||
$acars_data = $this->get($uri)->json()['data'][0];
|
||||
$this->assertEquals(round($acars['lat'], 2), round($acars_data['lat'], 2));
|
||||
$this->assertEquals(round($acars['lon'], 2), round($acars_data['lon'], 2));
|
||||
$this->assertEquals($acars['log'], $acars_data['log']);
|
||||
|
||||
# Make sure PIREP state moved into ENROUTE
|
||||
// Make sure PIREP state moved into ENROUTE
|
||||
$pirep = $this->getPirep($pirep_id);
|
||||
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
||||
$this->assertEquals(PirepStatus::AIRBORNE, $pirep['status']);
|
||||
@@ -372,8 +370,8 @@ class AcarsTest extends TestCase
|
||||
$this->assertEquals(round($acars['lat'], 2), round($body[0]['lat'], 2));
|
||||
$this->assertEquals(round($acars['lon'], 2), round($body[0]['lon'], 2));
|
||||
|
||||
# Update fields standalone
|
||||
$uri = '/api/pireps/' . $pirep_id . '/fields';
|
||||
// Update fields standalone
|
||||
$uri = '/api/pireps/'.$pirep_id.'/fields';
|
||||
$response = $this->post($uri, [
|
||||
'fields' => [
|
||||
'Departure Gate' => 'G26',
|
||||
@@ -384,7 +382,7 @@ class AcarsTest extends TestCase
|
||||
$body = $response->json('data');
|
||||
$this->assertEquals('G26', $body['Departure Gate']);
|
||||
|
||||
# File the PIREP now
|
||||
// File the PIREP now
|
||||
$uri = '/api/pireps/'.$pirep_id.'/file';
|
||||
$response = $this->post($uri, []);
|
||||
$response->assertStatus(400); // missing field
|
||||
@@ -394,14 +392,14 @@ class AcarsTest extends TestCase
|
||||
|
||||
$response = $this->post($uri, [
|
||||
'flight_time' => 130,
|
||||
'fuel_used' => 8000.19,
|
||||
'distance' => 400,
|
||||
'fuel_used' => 8000.19,
|
||||
'distance' => 400,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json();
|
||||
|
||||
# Add a comment
|
||||
// Add a comment
|
||||
$uri = '/api/pireps/'.$pirep_id.'/comments';
|
||||
$response = $this->post($uri, ['comment' => 'A comment']);
|
||||
$response->assertStatus(201);
|
||||
@@ -431,23 +429,23 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'source_name' => 'AcarsTest::testFilePirepApi',
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $aircraft->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'source_name' => 'AcarsTest::testFilePirepApi',
|
||||
];
|
||||
|
||||
$response = $this->post($uri, $pirep);
|
||||
$response->assertStatus(201);
|
||||
|
||||
# Get the PIREP ID
|
||||
// Get the PIREP ID
|
||||
$body = $response->json();
|
||||
$pirep_id = $body['data']['id'];
|
||||
|
||||
# File the PIREP now
|
||||
// File the PIREP now
|
||||
$uri = '/api/pireps/'.$pirep_id.'/file';
|
||||
|
||||
$response = $this->post($uri, [
|
||||
@@ -458,12 +456,12 @@ class AcarsTest extends TestCase
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
# Check the block_off_time and block_on_time being set
|
||||
// Check the block_off_time and block_on_time being set
|
||||
$body = $this->get('/api/pireps/'.$pirep_id)->json('data');
|
||||
$this->assertNotNull($body['block_off_time']);
|
||||
$this->assertNotNull($body['block_on_time']);
|
||||
|
||||
# make sure the time matches up
|
||||
// make sure the time matches up
|
||||
/*$block_on = new Carbon($body['block_on_time'], 'UTC');
|
||||
$block_off = new Carbon($body['block_off_time'], 'UTC');
|
||||
$this->assertEquals($block_on->subMinutes($body['flight_time']), $block_off);*/
|
||||
@@ -479,7 +477,7 @@ class AcarsTest extends TestCase
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
|
||||
# Add subfleets and aircraft, but also add another set of subfleets
|
||||
// Add subfleets and aircraft, but also add another set of subfleets
|
||||
$subfleetA = $this->createSubfleetWithAircraft(1);
|
||||
|
||||
// User not allowed aircraft from this subfleet
|
||||
@@ -495,15 +493,15 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_flight_time' => 120,
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'Unit test',
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'Unit test',
|
||||
];
|
||||
|
||||
$response = $this->post($uri, $pirep);
|
||||
@@ -525,7 +523,7 @@ class AcarsTest extends TestCase
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
|
||||
# Add subfleets and aircraft, but also add another set of subfleets
|
||||
// Add subfleets and aircraft, but also add another set of subfleets
|
||||
$subfleetA = $this->createSubfleetWithAircraft(1);
|
||||
|
||||
// User not allowed aircraft from this subfleet
|
||||
@@ -541,15 +539,15 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$pirep = [
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'airline_id' => $airline->id,
|
||||
'aircraft_id' => $subfleetB['aircraft']->random()->id,
|
||||
'dpt_airport_id' => $airport->icao,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
'flight_number' => '6000',
|
||||
'level' => 38000,
|
||||
'planned_flight_time' => 120,
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'Unit test',
|
||||
'route' => 'POINTA POINTB',
|
||||
'source_name' => 'Unit test',
|
||||
];
|
||||
|
||||
$response = $this->post($uri, $pirep);
|
||||
@@ -571,7 +569,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
||||
|
||||
# Post an ACARS update
|
||||
// Post an ACARS update
|
||||
$acars_count = \random_int(2, 10);
|
||||
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id' => ''])->toArray();
|
||||
|
||||
@@ -583,9 +581,6 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(200)->assertJsonCount($acars_count, 'data');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testNonExistentPirepGet()
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
@@ -595,9 +590,6 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testNonExistentPirepStore()
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
@@ -608,9 +600,6 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testAcarsIsoDate()
|
||||
{
|
||||
$pirep = $this->createPirep()->toArray();
|
||||
@@ -695,9 +684,6 @@ class AcarsTest extends TestCase
|
||||
$this->assertEquals(1, $body['count']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testAcarsRoutePost()
|
||||
{
|
||||
$pirep = $this->createPirep()->toArray();
|
||||
@@ -714,13 +700,13 @@ class AcarsTest extends TestCase
|
||||
foreach ($route as $position) {
|
||||
$post_route[] = [
|
||||
'order' => $order,
|
||||
'id' => $position->id,
|
||||
'name' => $position->id,
|
||||
'lat' => $position->lat,
|
||||
'lon' => $position->lon,
|
||||
'id' => $position->id,
|
||||
'name' => $position->id,
|
||||
'lat' => $position->lat,
|
||||
'lon' => $position->lon,
|
||||
];
|
||||
|
||||
++$order;
|
||||
$order++;
|
||||
}
|
||||
|
||||
$uri = '/api/pireps/'.$pirep_id.'/route';
|
||||
@@ -730,7 +716,6 @@ class AcarsTest extends TestCase
|
||||
/**
|
||||
* Get
|
||||
*/
|
||||
|
||||
$uri = '/api/pireps/'.$pirep_id.'/route';
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200)->assertJsonCount($route_count, 'data');
|
||||
@@ -762,7 +747,7 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(201);
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
# try readding
|
||||
// try readding
|
||||
$response = $this->post($uri, $pirep);
|
||||
$response->assertStatus(200);
|
||||
$dupe_pirep_id = $response->json()['data']['id'];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
#use Swagger\Serializer;
|
||||
//use Swagger\Serializer;
|
||||
use App\Models\User;
|
||||
use App\Services\FareService;
|
||||
|
||||
@@ -49,13 +49,10 @@ class ApiTest extends TestCase
|
||||
->assertJson(['data' => ['id' => $user->id]]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testApiDeniedOnInactiveUser()
|
||||
{
|
||||
$this->user = factory(User::class)->create([
|
||||
'state' => UserState::PENDING
|
||||
'state' => UserState::PENDING,
|
||||
]);
|
||||
|
||||
$uri = '/api/user';
|
||||
@@ -74,14 +71,11 @@ class ApiTest extends TestCase
|
||||
$this->assertTrue(array_key_exists('user', $response['data'][0]));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testGetAirlines()
|
||||
{
|
||||
$size = \random_int(5, 10);
|
||||
$this->user = factory(App\Models\User::class)->create([
|
||||
'airline_id' => 0
|
||||
'airline_id' => 0,
|
||||
]);
|
||||
|
||||
$airlines = factory(App\Models\Airline::class, $size)->create();
|
||||
@@ -104,7 +98,7 @@ class ApiTest extends TestCase
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
|
||||
$response = $this->get('/api/airports/' . $airport->icao);
|
||||
$response = $this->get('/api/airports/'.$airport->icao);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['icao' => $airport->icao]]);
|
||||
@@ -156,19 +150,19 @@ class ApiTest extends TestCase
|
||||
$subfleetA_size = \random_int(2, 10);
|
||||
$subfleetB_size = \random_int(2, 10);
|
||||
factory(App\Models\Aircraft::class, $subfleetA_size)->create([
|
||||
'subfleet_id' => $subfleetA->id
|
||||
'subfleet_id' => $subfleetA->id,
|
||||
]);
|
||||
|
||||
factory(App\Models\Aircraft::class, $subfleetB_size)->create([
|
||||
'subfleet_id' => $subfleetB->id
|
||||
'subfleet_id' => $subfleetB->id,
|
||||
]);
|
||||
|
||||
$response = $this->get('/api/fleet');
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json()['data'];
|
||||
|
||||
foreach($body as $subfleet) {
|
||||
if($subfleet['id'] === $subfleetA->id) {
|
||||
foreach ($body as $subfleet) {
|
||||
if ($subfleet['id'] === $subfleetA->id) {
|
||||
$size = $subfleetA_size;
|
||||
} else {
|
||||
$size = $subfleetB_size;
|
||||
@@ -188,28 +182,28 @@ class ApiTest extends TestCase
|
||||
$fare_svc = app(FareService::class);
|
||||
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create([
|
||||
'airline_id' => $this->user->airline_id
|
||||
'airline_id' => $this->user->airline_id,
|
||||
]);
|
||||
|
||||
$fare = factory(App\Models\Fare::class)->create();
|
||||
|
||||
$fare_svc->setForSubfleet($subfleet, $fare);
|
||||
$aircraft = factory(App\Models\Aircraft::class)->create([
|
||||
'subfleet_id' => $subfleet->id
|
||||
'subfleet_id' => $subfleet->id,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Just try retrieving by ID
|
||||
*/
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id);
|
||||
$resp = $this->get('/api/fleet/aircraft/'.$aircraft->id);
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?registration=' . $aircraft->registration);
|
||||
$resp = $this->get('/api/fleet/aircraft/'.$aircraft->id.'?registration='.$aircraft->registration);
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?icao=' . $aircraft->icao);
|
||||
$resp = $this->get('/api/fleet/aircraft/'.$aircraft->id.'?icao='.$aircraft->icao);
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
trait ApiTestTrait
|
||||
{
|
||||
public function assertApiResponse(Array $actualData)
|
||||
public function assertApiResponse(array $actualData)
|
||||
{
|
||||
$this->assertApiSuccess();
|
||||
|
||||
@@ -19,10 +19,10 @@ trait ApiTestTrait
|
||||
$this->seeJson(['success' => true]);
|
||||
}
|
||||
|
||||
public function assertModelData(Array $actualData, Array $expectedData)
|
||||
public function assertModelData(array $actualData, array $expectedData)
|
||||
{
|
||||
foreach ($actualData as $key => $value) {
|
||||
$this->assertEquals($actualData[$key], $expectedData[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ use App\Models\UserAward;
|
||||
|
||||
class AwardsTest extends TestCase
|
||||
{
|
||||
private $awardSvc,
|
||||
$pirepSvc;
|
||||
private $awardSvc;
|
||||
private $pirepSvc;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -30,7 +30,7 @@ class AwardsTest extends TestCase
|
||||
{
|
||||
// Create one award that's given out with one flight
|
||||
$award = factory(App\Models\Award::class)->create([
|
||||
'ref_model' => App\Awards\PilotFlightAwards::class,
|
||||
'ref_model' => App\Awards\PilotFlightAwards::class,
|
||||
'ref_model_params' => 1,
|
||||
]);
|
||||
|
||||
@@ -40,18 +40,18 @@ class AwardsTest extends TestCase
|
||||
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'airline_id' => $user->airline->id,
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->pirepSvc->create($pirep);
|
||||
$this->pirepSvc->accept($pirep);
|
||||
|
||||
$w = [
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'award_id' => $award->id,
|
||||
];
|
||||
|
||||
# Make sure only one is awarded
|
||||
// Make sure only one is awarded
|
||||
$this->assertEquals(1, UserAward::where($w)->count(['id']));
|
||||
|
||||
$found_award = UserAward::where($w)->first();
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
use App\Models\Enums\ExpenseType;
|
||||
use App\Repositories\ExpenseRepository;
|
||||
use App\Services\PirepService;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\FareService;
|
||||
use App\Services\Finance\PirepFinanceService;
|
||||
use App\Services\FleetService;
|
||||
use App\Services\PirepService;
|
||||
use App\Support\Math;
|
||||
use App\Support\Money;
|
||||
|
||||
class FinanceTest extends TestCase
|
||||
{
|
||||
private $expenseRepo,
|
||||
$fareSvc,
|
||||
$financeSvc,
|
||||
$fleetSvc,
|
||||
$pirepSvc;
|
||||
private $expenseRepo;
|
||||
private $fareSvc;
|
||||
private $financeSvc;
|
||||
private $fleetSvc;
|
||||
private $pirepSvc;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
@@ -36,8 +36,10 @@ class FinanceTest extends TestCase
|
||||
/**
|
||||
* Create a user and a PIREP, that has all of the data filled out
|
||||
* so that we can test all of the disparate parts of the finances
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function createFullPirep()
|
||||
{
|
||||
@@ -55,7 +57,7 @@ class FinanceTest extends TestCase
|
||||
$this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank);
|
||||
|
||||
$airport = factory(App\Models\Airport::class)->create([
|
||||
'ground_handling_cost' => 10
|
||||
'ground_handling_cost' => 10,
|
||||
]);
|
||||
|
||||
$user = factory(App\Models\User::class)->create([
|
||||
@@ -63,20 +65,20 @@ class FinanceTest extends TestCase
|
||||
]);
|
||||
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $user->airline_id,
|
||||
'airline_id' => $user->airline_id,
|
||||
'arr_airport_id' => $airport->icao,
|
||||
]);
|
||||
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'flight_number' => $flight->flight_number,
|
||||
'route_code' => $flight->route_code,
|
||||
'route_leg' => $flight->route_leg,
|
||||
'flight_number' => $flight->flight_number,
|
||||
'route_code' => $flight->route_code,
|
||||
'route_leg' => $flight->route_leg,
|
||||
'arr_airport_id' => $airport->id,
|
||||
'user_id' => $user->id,
|
||||
'airline_id' => $user->airline_id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'flight_time' => 120,
|
||||
'user_id' => $user->id,
|
||||
'airline_id' => $user->airline_id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'flight_time' => 120,
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -84,8 +86,8 @@ class FinanceTest extends TestCase
|
||||
* to the PIREP when it's saved, and set the capacity
|
||||
*/
|
||||
$fares = factory(App\Models\Fare::class, 3)->create([
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'capacity' => 10,
|
||||
]);
|
||||
|
||||
@@ -93,17 +95,17 @@ class FinanceTest extends TestCase
|
||||
$this->fareSvc->setForSubfleet($subfleet['subfleet'], $fare);
|
||||
}
|
||||
|
||||
# Add an expense
|
||||
// Add an expense
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'airline_id' => null,
|
||||
'amount' => 100
|
||||
'amount' => 100,
|
||||
]);
|
||||
|
||||
# Add a subfleet expense
|
||||
// Add a subfleet expense
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'ref_model' => \App\Models\Subfleet::class,
|
||||
'ref_model' => \App\Models\Subfleet::class,
|
||||
'ref_model_id' => $subfleet['subfleet']->id,
|
||||
'amount' => 200
|
||||
'amount' => 200,
|
||||
]);
|
||||
|
||||
$pirep = $this->pirepSvc->create($pirep, []);
|
||||
@@ -111,9 +113,6 @@ class FinanceTest extends TestCase
|
||||
return [$user, $pirep, $fares];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testFlightFaresNoOverride()
|
||||
{
|
||||
$flight = factory(App\Models\Flight::class)->create();
|
||||
@@ -126,21 +125,21 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals($fare->price, $subfleet_fares->get(0)->price);
|
||||
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
||||
|
||||
#
|
||||
# set an override now
|
||||
#
|
||||
//
|
||||
// set an override now
|
||||
//
|
||||
$this->fareSvc->setForFlight($flight, $fare, [
|
||||
'price' => 50, 'capacity' => 400
|
||||
'price' => 50, 'capacity' => 400,
|
||||
]);
|
||||
|
||||
# look for them again
|
||||
// look for them again
|
||||
$subfleet_fares = $this->fareSvc->getForFlight($flight);
|
||||
|
||||
$this->assertCount(1, $subfleet_fares);
|
||||
$this->assertEquals(50, $subfleet_fares[0]->price);
|
||||
$this->assertEquals(400, $subfleet_fares[0]->capacity);
|
||||
|
||||
# delete
|
||||
// delete
|
||||
$this->fareSvc->delFareFromFlight($flight, $fare);
|
||||
$this->assertCount(0, $this->fareSvc->getForFlight($flight));
|
||||
}
|
||||
@@ -162,8 +161,8 @@ class FinanceTest extends TestCase
|
||||
$new_capacity = Math::addPercent($fare->capacity, $percent_200);
|
||||
|
||||
$this->fareSvc->setForFlight($flight, $fare, [
|
||||
'price' => $percent_incr,
|
||||
'cost' => $percent_decr,
|
||||
'price' => $percent_incr,
|
||||
'cost' => $percent_decr,
|
||||
'capacity' => $percent_200,
|
||||
]);
|
||||
|
||||
@@ -187,21 +186,21 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals($fare->price, $subfleet_fares->get(0)->price);
|
||||
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
||||
|
||||
#
|
||||
# set an override now
|
||||
#
|
||||
//
|
||||
// set an override now
|
||||
//
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 50, 'capacity' => 400
|
||||
'price' => 50, 'capacity' => 400,
|
||||
]);
|
||||
|
||||
# look for them again
|
||||
// look for them again
|
||||
$subfleet_fares = $this->fareSvc->getForSubfleet($subfleet);
|
||||
|
||||
$this->assertCount(1, $subfleet_fares);
|
||||
$this->assertEquals(50, $subfleet_fares[0]->price);
|
||||
$this->assertEquals(400, $subfleet_fares[0]->capacity);
|
||||
|
||||
# delete
|
||||
// delete
|
||||
$this->fareSvc->delFareFromSubfleet($subfleet, $fare);
|
||||
$this->assertCount(0, $this->fareSvc->getForSubfleet($subfleet));
|
||||
}
|
||||
@@ -212,7 +211,7 @@ class FinanceTest extends TestCase
|
||||
$fare = factory(App\Models\Fare::class)->create();
|
||||
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 50, 'capacity' => 400
|
||||
'price' => 50, 'capacity' => 400,
|
||||
]);
|
||||
|
||||
$ac_fares = $this->fareSvc->getForSubfleet($subfleet);
|
||||
@@ -221,12 +220,12 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(50, $ac_fares[0]->price);
|
||||
$this->assertEquals(400, $ac_fares[0]->capacity);
|
||||
|
||||
#
|
||||
# update the override to a different amount and make sure it updates
|
||||
#
|
||||
//
|
||||
// update the override to a different amount and make sure it updates
|
||||
//
|
||||
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 150, 'capacity' => 50
|
||||
'price' => 150, 'capacity' => 50,
|
||||
]);
|
||||
|
||||
$ac_fares = $this->fareSvc->getForSubfleet($subfleet);
|
||||
@@ -235,7 +234,7 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(150, $ac_fares[0]->price);
|
||||
$this->assertEquals(50, $ac_fares[0]->capacity);
|
||||
|
||||
# delete
|
||||
// delete
|
||||
$this->fareSvc->delFareFromSubfleet($subfleet, $fare);
|
||||
$this->assertCount(0, $this->fareSvc->getForSubfleet($subfleet));
|
||||
}
|
||||
@@ -257,8 +256,8 @@ class FinanceTest extends TestCase
|
||||
$new_capacity = Math::addPercent($fare->capacity, $percent_200);
|
||||
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => $percent_incr,
|
||||
'cost' => $percent_decr,
|
||||
'price' => $percent_incr,
|
||||
'cost' => $percent_decr,
|
||||
'capacity' => $percent_200,
|
||||
]);
|
||||
|
||||
@@ -280,33 +279,33 @@ class FinanceTest extends TestCase
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||
[$fare1, $fare2, $fare3, $fare4] = factory(App\Models\Fare::class, 4)->create();
|
||||
|
||||
# add to the subfleet, and just override one of them
|
||||
// add to the subfleet, and just override one of them
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare1);
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare2, [
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'capacity' => 25,
|
||||
]);
|
||||
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare3);
|
||||
|
||||
# Now set the last one to the flight and then override stuff
|
||||
// Now set the last one to the flight and then override stuff
|
||||
$this->fareSvc->setForFlight($flight, $fare3, [
|
||||
'price' => '300%',
|
||||
'cost' => 250,
|
||||
'cost' => 250,
|
||||
]);
|
||||
|
||||
$fare3_price = Math::addPercent($fare3->price, 300);
|
||||
|
||||
# Assign another one to the flight, that's not on the subfleet
|
||||
# This one should NOT be returned in the list of fares
|
||||
// Assign another one to the flight, that's not on the subfleet
|
||||
// This one should NOT be returned in the list of fares
|
||||
$this->fareSvc->setForFlight($flight, $fare4);
|
||||
|
||||
$fares = $this->fareSvc->getAllFares($flight, $subfleet);
|
||||
$this->assertCount(3, $fares);
|
||||
|
||||
foreach($fares as $fare) {
|
||||
switch($fare->id) {
|
||||
foreach ($fares as $fare) {
|
||||
switch ($fare->id) {
|
||||
case $fare1->id:
|
||||
$this->assertEquals($fare->price, $fare1->price);
|
||||
$this->assertEquals($fare->cost, $fare1->cost);
|
||||
@@ -333,11 +332,11 @@ class FinanceTest extends TestCase
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||
[$fare1, $fare2, $fare3] = factory(App\Models\Fare::class, 3)->create();
|
||||
|
||||
# add to the subfleet, and just override one of them
|
||||
// add to the subfleet, and just override one of them
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare1);
|
||||
$this->fareSvc->setForSubfleet($subfleet, $fare2, [
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'price' => 100,
|
||||
'cost' => 50,
|
||||
'capacity' => 25,
|
||||
]);
|
||||
|
||||
@@ -383,9 +382,9 @@ class FinanceTest extends TestCase
|
||||
]);
|
||||
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'source' => PirepSource::ACARS,
|
||||
]);
|
||||
|
||||
$rate = $this->financeSvc->getPilotPayRateForPirep($pirep);
|
||||
@@ -410,15 +409,15 @@ class FinanceTest extends TestCase
|
||||
]);
|
||||
|
||||
$pirep_acars = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'source' => PirepSource::ACARS,
|
||||
]);
|
||||
|
||||
$rate = $this->financeSvc->getPilotPayRateForPirep($pirep_acars);
|
||||
$this->assertEquals($acars_pay_rate, $rate);
|
||||
|
||||
# Change to a percentage
|
||||
// Change to a percentage
|
||||
$manual_pay_rate = '50%';
|
||||
$manual_pay_adjusted = Math::addPercent(
|
||||
$rank->manual_base_pay_rate, $manual_pay_rate);
|
||||
@@ -428,15 +427,15 @@ class FinanceTest extends TestCase
|
||||
]);
|
||||
|
||||
$pirep_manual = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::MANUAL,
|
||||
'source' => PirepSource::MANUAL,
|
||||
]);
|
||||
|
||||
$rate = $this->financeSvc->getPilotPayRateForPirep($pirep_manual);
|
||||
$this->assertEquals($manual_pay_adjusted, $rate);
|
||||
|
||||
# And make sure the original acars override still works
|
||||
// And make sure the original acars override still works
|
||||
$rate = $this->financeSvc->getPilotPayRateForPirep($pirep_acars);
|
||||
$this->assertEquals($acars_pay_rate, $rate);
|
||||
}
|
||||
@@ -459,9 +458,9 @@ class FinanceTest extends TestCase
|
||||
]);
|
||||
|
||||
$pirep_acars = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'source' => PirepSource::ACARS,
|
||||
'flight_time' => 60,
|
||||
]);
|
||||
|
||||
@@ -469,9 +468,9 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(100, $payment->getValue());
|
||||
|
||||
$pirep_acars = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->user->id,
|
||||
'aircraft_id' => $subfleet['aircraft']->random(),
|
||||
'source' => PirepSource::ACARS,
|
||||
'source' => PirepSource::ACARS,
|
||||
'flight_time' => 90,
|
||||
]);
|
||||
|
||||
@@ -500,7 +499,7 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(100, $balance->getValue());
|
||||
$this->assertEquals(100, $journal->balance->getValue());
|
||||
|
||||
# add another transaction
|
||||
// add another transaction
|
||||
|
||||
$journalRepo->post(
|
||||
$journal,
|
||||
@@ -513,7 +512,7 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(125, $balance->getValue());
|
||||
$this->assertEquals(125, $journal->balance->getValue());
|
||||
|
||||
# debit an amount
|
||||
// debit an amount
|
||||
$journalRepo->post(
|
||||
$journal,
|
||||
null,
|
||||
@@ -525,7 +524,7 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(100, $balance->getValue());
|
||||
$this->assertEquals(100, $journal->balance->getValue());
|
||||
|
||||
# find all transactions
|
||||
// find all transactions
|
||||
$transactions = $journalRepo->getAllForObject($user);
|
||||
|
||||
$this->assertCount(3, $transactions['transactions']);
|
||||
@@ -534,20 +533,19 @@ class FinanceTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testPirepFares()
|
||||
{
|
||||
[$user, $pirep, $fares] = $this->createFullPirep();
|
||||
|
||||
# Override the fares
|
||||
// Override the fares
|
||||
$fare_counts = [];
|
||||
foreach ($fares as $fare) {
|
||||
$fare_counts[] = [
|
||||
'fare_id' => $fare->id,
|
||||
'price' => $fare->price,
|
||||
'count' => round($fare->capacity / 2),
|
||||
'price' => $fare->price,
|
||||
'count' => round($fare->capacity / 2),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -555,7 +553,7 @@ class FinanceTest extends TestCase
|
||||
$all_fares = $this->financeSvc->getReconciledFaresForPirep($pirep);
|
||||
|
||||
$fare_counts = collect($fare_counts);
|
||||
foreach($all_fares as $fare) {
|
||||
foreach ($all_fares as $fare) {
|
||||
$set_fare = $fare_counts->where('fare_id', $fare->id)->first();
|
||||
$this->assertEquals($set_fare['count'], $fare->count);
|
||||
$this->assertEquals($set_fare['price'], $fare->price);
|
||||
@@ -571,15 +569,15 @@ class FinanceTest extends TestCase
|
||||
$airline2 = factory(App\Models\Airline::class)->create();
|
||||
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'airline_id' => $airline->id
|
||||
'airline_id' => $airline->id,
|
||||
]);
|
||||
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'airline_id' => $airline2->id
|
||||
'airline_id' => $airline2->id,
|
||||
]);
|
||||
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'airline_id' => null
|
||||
'airline_id' => null,
|
||||
]);
|
||||
|
||||
$expenses = $this->expenseRepo->getAllForType(
|
||||
@@ -605,8 +603,8 @@ class FinanceTest extends TestCase
|
||||
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||
factory(App\Models\Expense::class)->create([
|
||||
'airline_id' => null,
|
||||
'ref_model' => \App\Models\Subfleet::class,
|
||||
'airline_id' => null,
|
||||
'ref_model' => \App\Models\Subfleet::class,
|
||||
'ref_model_id' => $subfleet->id,
|
||||
]);
|
||||
|
||||
@@ -625,7 +623,6 @@ class FinanceTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testPirepFinances()
|
||||
@@ -635,19 +632,19 @@ class FinanceTest extends TestCase
|
||||
[$user, $pirep, $fares] = $this->createFullPirep();
|
||||
$user->airline->initJournal(config('phpvms.currency'));
|
||||
|
||||
# Override the fares
|
||||
// Override the fares
|
||||
$fare_counts = [];
|
||||
foreach ($fares as $fare) {
|
||||
$fare_counts[] = [
|
||||
'fare_id' => $fare->id,
|
||||
'price' => $fare->price,
|
||||
'count' => 100,
|
||||
'price' => $fare->price,
|
||||
'count' => 100,
|
||||
];
|
||||
}
|
||||
|
||||
$this->fareSvc->saveForPirep($pirep, $fare_counts);
|
||||
|
||||
# This should process all of the
|
||||
// This should process all of the
|
||||
$pirep = $this->pirepSvc->accept($pirep);
|
||||
|
||||
$transactions = $journalRepo->getAllForObject($pirep);
|
||||
@@ -656,17 +653,17 @@ class FinanceTest extends TestCase
|
||||
$this->assertEquals(3020, $transactions['credits']->getValue());
|
||||
$this->assertEquals(1860, $transactions['debits']->getValue());
|
||||
|
||||
# Check that all the different transaction types are there
|
||||
# test by the different groups that exist
|
||||
// Check that all the different transaction types are there
|
||||
// test by the different groups that exist
|
||||
$transaction_tags = [
|
||||
'expense' => 1,
|
||||
'subfleet' => 2,
|
||||
'fare' => 3,
|
||||
'ground_handling' => 1,
|
||||
'pilot_pay' => 2, # debit on the airline, credit to the pilot
|
||||
'expense' => 1,
|
||||
'subfleet' => 2,
|
||||
'fare' => 3,
|
||||
'ground_handling' => 1,
|
||||
'pilot_pay' => 2, // debit on the airline, credit to the pilot
|
||||
];
|
||||
|
||||
foreach($transaction_tags as $type => $count) {
|
||||
foreach ($transaction_tags as $type => $count) {
|
||||
$find = $transactions['transactions']->where('tags', $type);
|
||||
$this->assertEquals($count, $find->count());
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Bid;
|
||||
use App\Models\Enums\Days;
|
||||
use App\Models\Flight;
|
||||
use App\Models\User;
|
||||
use App\Models\Bid;
|
||||
use App\Repositories\SettingRepository;
|
||||
use App\Services\FlightService;
|
||||
|
||||
class FlightTest extends TestCase
|
||||
{
|
||||
protected $flightSvc, $settingsRepo;
|
||||
protected $flightSvc;
|
||||
protected $settingsRepo;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -23,13 +24,13 @@ class FlightTest extends TestCase
|
||||
public function addFlight($user)
|
||||
{
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $user->airline_id
|
||||
'airline_id' => $user->airline_id,
|
||||
]);
|
||||
|
||||
$flight->subfleets()->syncWithoutDetaching([
|
||||
factory(App\Models\Subfleet::class)->create([
|
||||
'airline_id' => $user->airline_id
|
||||
])->id
|
||||
'airline_id' => $user->airline_id,
|
||||
])->id,
|
||||
]);
|
||||
|
||||
return $flight;
|
||||
@@ -55,7 +56,7 @@ class FlightTest extends TestCase
|
||||
|
||||
$this->assertTrue($this->flightSvc->isFlightDuplicate($flight_dupe));
|
||||
|
||||
# same flight but diff airline shouldn't be a dupe
|
||||
// same flight but diff airline shouldn't be a dupe
|
||||
$new_airline = factory(App\Models\Airline::class)->create();
|
||||
$flight_dupe = new Flight([
|
||||
'airline_id' => $new_airline->airline_id,
|
||||
@@ -66,7 +67,7 @@ class FlightTest extends TestCase
|
||||
|
||||
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_dupe));
|
||||
|
||||
# add another flight with a code
|
||||
// add another flight with a code
|
||||
$flight_leg = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $flight->airline_id,
|
||||
'flight_number' => $flight->flight_number,
|
||||
@@ -91,7 +92,7 @@ class FlightTest extends TestCase
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
$flight = $this->addFlight($this->user);
|
||||
|
||||
$req = $this->get('/api/flights/' . $flight->id);
|
||||
$req = $this->get('/api/flights/'.$flight->id);
|
||||
$req->assertStatus(200);
|
||||
|
||||
$body = $req->json()['data'];
|
||||
@@ -99,7 +100,7 @@ class FlightTest extends TestCase
|
||||
$this->assertEquals($flight->dpt_airport_id, $body['dpt_airport_id']);
|
||||
$this->assertEquals($flight->arr_airport_id, $body['arr_airport_id']);
|
||||
|
||||
# Distance conversion
|
||||
// Distance conversion
|
||||
$this->assertHasKeys($body['distance'], ['mi', 'nmi', 'km']);
|
||||
|
||||
$this->get('/api/flights/INVALID', self::$auth_headers)
|
||||
@@ -114,9 +115,9 @@ class FlightTest extends TestCase
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
$flight = $this->addFlight($this->user);
|
||||
|
||||
# search specifically for a flight ID
|
||||
$query = 'flight_id=' . $flight->id;
|
||||
$req = $this->get('/api/flights/search?' . $query);
|
||||
// search specifically for a flight ID
|
||||
$query = 'flight_id='.$flight->id;
|
||||
$req = $this->get('/api/flights/search?'.$query);
|
||||
$req->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ class FlightTest extends TestCase
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
factory(App\Models\Flight::class, 20)->create([
|
||||
'airline_id' => $this->user->airline_id
|
||||
'airline_id' => $this->user->airline_id,
|
||||
]);
|
||||
|
||||
$res = $this->get('/api/flights');
|
||||
@@ -178,15 +179,15 @@ class FlightTest extends TestCase
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
factory(App\Models\Flight::class, 20)->create([
|
||||
'airline_id' => $this->user->airline_id
|
||||
'airline_id' => $this->user->airline_id,
|
||||
]);
|
||||
|
||||
$saved_flight = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $this->user->airline_id,
|
||||
'days' => Days::getDaysMask([
|
||||
'days' => Days::getDaysMask([
|
||||
Days::SUNDAY,
|
||||
Days::THURSDAY
|
||||
])
|
||||
Days::THURSDAY,
|
||||
]),
|
||||
]);
|
||||
|
||||
$flight = Flight::findByDays([Days::SUNDAY])->first();
|
||||
@@ -234,9 +235,6 @@ class FlightTest extends TestCase
|
||||
$this->assertNull($flights);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testDayOfWeekTests(): void
|
||||
{
|
||||
$mask = 127;
|
||||
@@ -326,28 +324,22 @@ class FlightTest extends TestCase
|
||||
$this->assertNull($flights);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testFlightSearchApi()
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
$flights = factory(App\Models\Flight::class, 10)->create([
|
||||
'airline_id' => $this->user->airline_id
|
||||
'airline_id' => $this->user->airline_id,
|
||||
]);
|
||||
|
||||
$flight = $flights->random();
|
||||
|
||||
$query = 'flight_number=' . $flight->flight_number;
|
||||
$req = $this->get('/api/flights/search?' . $query);
|
||||
$query = 'flight_number='.$flight->flight_number;
|
||||
$req = $this->get('/api/flights/search?'.$query);
|
||||
$body = $req->json();
|
||||
|
||||
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testAddSubfleet()
|
||||
{
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||
@@ -360,7 +352,7 @@ class FlightTest extends TestCase
|
||||
$found = $flight->subfleets()->get();
|
||||
$this->assertCount(1, $found);
|
||||
|
||||
# Make sure it hasn't been added twice
|
||||
// Make sure it hasn't been added twice
|
||||
$fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
||||
$flight->refresh();
|
||||
$found = $flight->subfleets()->get();
|
||||
@@ -369,6 +361,7 @@ class FlightTest extends TestCase
|
||||
|
||||
/**
|
||||
* Add/remove a bid, test the API, etc
|
||||
*
|
||||
* @throws \App\Services\Exception
|
||||
*/
|
||||
public function testBids()
|
||||
@@ -387,11 +380,11 @@ class FlightTest extends TestCase
|
||||
$this->assertEquals($flight->id, $bid->flight_id);
|
||||
$this->assertTrue($flight->has_bid);
|
||||
|
||||
# Refresh
|
||||
// Refresh
|
||||
$flight = Flight::find($flight->id);
|
||||
$this->assertTrue($flight->has_bid);
|
||||
|
||||
# Check the table and make sure the entry is there
|
||||
// Check the table and make sure the entry is there
|
||||
$bid_retrieved = $this->flightSvc->addBid($flight, $user);
|
||||
$this->assertEquals($bid->id, $bid_retrieved->id);
|
||||
|
||||
@@ -399,13 +392,13 @@ class FlightTest extends TestCase
|
||||
$bids = $user->bids;
|
||||
$this->assertEquals(1, $bids->count());
|
||||
|
||||
# Query the API and see that the user has the bids
|
||||
# And pull the flight details for the user/bids
|
||||
// Query the API and see that the user has the bids
|
||||
// And pull the flight details for the user/bids
|
||||
$req = $this->get('/api/user', $headers);
|
||||
$req->assertStatus(200);
|
||||
|
||||
$body = $req->json()['data'];
|
||||
$this->assertEquals(1, sizeof($body['bids']));
|
||||
$this->assertEquals(1, count($body['bids']));
|
||||
$this->assertEquals($flight->id, $body['bids'][0]['flight_id']);
|
||||
|
||||
$req = $this->get('/api/users/'.$user->id.'/bids', $headers);
|
||||
@@ -414,21 +407,21 @@ class FlightTest extends TestCase
|
||||
$req->assertStatus(200);
|
||||
$this->assertEquals($flight->id, $body[0]['flight_id']);
|
||||
|
||||
# have a second user bid on it
|
||||
// have a second user bid on it
|
||||
$bid_user2 = $this->flightSvc->addBid($flight, $user2);
|
||||
$this->assertNotNull($bid_user2);
|
||||
$this->assertNotEquals($bid_retrieved->id, $bid_user2->id);
|
||||
|
||||
# Now remove the flight and check API
|
||||
// Now remove the flight and check API
|
||||
|
||||
$this->flightSvc->removeBid($flight, $user);
|
||||
|
||||
$flight = Flight::find($flight->id);
|
||||
|
||||
# user2 still has a bid on it
|
||||
// user2 still has a bid on it
|
||||
$this->assertTrue($flight->has_bid);
|
||||
|
||||
# Remove it from 2nd user
|
||||
// Remove it from 2nd user
|
||||
$this->flightSvc->removeBid($flight, $user2);
|
||||
$flight->refresh();
|
||||
$this->assertFalse($flight->has_bid);
|
||||
@@ -442,7 +435,7 @@ class FlightTest extends TestCase
|
||||
|
||||
$body = $req->json()['data'];
|
||||
$this->assertEquals($user->id, $body['id']);
|
||||
$this->assertEquals(0, sizeof($body['bids']));
|
||||
$this->assertEquals(0, count($body['bids']));
|
||||
|
||||
$req = $this->get('/api/users/'.$user->id.'/bids', $headers);
|
||||
$req->assertStatus(200);
|
||||
@@ -451,24 +444,21 @@ class FlightTest extends TestCase
|
||||
$this->assertCount(0, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testMultipleBidsSingleFlight()
|
||||
{
|
||||
$this->settingsRepo->store('bids.disable_flight_on_bid', true);
|
||||
|
||||
$user1 = factory(User::class)->create();
|
||||
$user2 = factory(User::class)->create([
|
||||
'airline_id' => $user1->airline_id
|
||||
'airline_id' => $user1->airline_id,
|
||||
]);
|
||||
|
||||
$flight = $this->addFlight($user1);
|
||||
|
||||
# Put bid on the flight to block it off
|
||||
// Put bid on the flight to block it off
|
||||
$this->flightSvc->addBid($flight, $user1);
|
||||
|
||||
# Try adding again, should throw an exception
|
||||
// Try adding again, should throw an exception
|
||||
$this->expectException(\App\Exceptions\BidExists::class);
|
||||
$this->flightSvc->addBid($flight, $user2);
|
||||
}
|
||||
@@ -490,12 +480,12 @@ class FlightTest extends TestCase
|
||||
|
||||
$this->assertEquals($body['flight_id'], $flight->id);
|
||||
|
||||
# Now try to have the second user bid on it
|
||||
# Should return a 409 error
|
||||
// Now try to have the second user bid on it
|
||||
// Should return a 409 error
|
||||
$response = $this->put($uri, $data, [], $user2);
|
||||
$response->assertStatus(409);
|
||||
|
||||
# Try now deleting the bid from the user
|
||||
// Try now deleting the bid from the user
|
||||
$response = $this->delete($uri, $data);
|
||||
$body = $response->json('data');
|
||||
$this->assertCount(0, $body);
|
||||
@@ -521,13 +511,13 @@ class FlightTest extends TestCase
|
||||
$empty_flight = Flight::find($flight->id);
|
||||
$this->assertNull($empty_flight);
|
||||
|
||||
# Make sure no bids exist
|
||||
// Make sure no bids exist
|
||||
$user_bids = Bid::where('flight_id', $flight->id)->get();
|
||||
|
||||
#$this->assertEquals(0, $user_bid->count());
|
||||
//$this->assertEquals(0, $user_bid->count());
|
||||
|
||||
# Query the API and see that the user has the bids
|
||||
# And pull the flight details for the user/bids
|
||||
// Query the API and see that the user has the bids
|
||||
// And pull the flight details for the user/bids
|
||||
$req = $this->get('/api/user', $headers);
|
||||
$req->assertStatus(200);
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ class GeoTest extends TestCase
|
||||
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 41.15169x-3.604667
|
||||
* [2017-12-21 00:54:10] dev.INFO: name: SIE - 52.15527x22.200833
|
||||
*/
|
||||
# Start at ATL
|
||||
// Start at ATL
|
||||
$start_point = [36.58106, 26.375603];
|
||||
|
||||
# These are all SIE
|
||||
// These are all SIE
|
||||
$potential_points = [
|
||||
[39.0955, -74.800344],
|
||||
[41.15169, -3.604667],
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
use App\Services\FareService;
|
||||
use App\Models\Enums\FlightType;
|
||||
use App\Services\FareService;
|
||||
|
||||
/**
|
||||
* Class ImporterTest
|
||||
*/
|
||||
class ImporterTest extends TestCase
|
||||
{
|
||||
private $importBaseClass,
|
||||
$importSvc,
|
||||
$fareSvc;
|
||||
private $importBaseClass;
|
||||
private $importSvc;
|
||||
private $fareSvc;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -24,6 +24,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Add some of the basic data needed to properly import the flights.csv file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function insertFlightsScaffoldData()
|
||||
@@ -38,14 +39,14 @@ class ImporterTest extends TestCase
|
||||
$airline = factory(App\Models\Airline::class)->create($al);
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
|
||||
|
||||
# Add the economy class
|
||||
// Add the economy class
|
||||
$fare_economy = factory(App\Models\Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
|
||||
$fare_svc->setForSubfleet($subfleet, $fare_economy);
|
||||
|
||||
$fare_business = factory(App\Models\Fare::class)->create(['code' => 'B', 'capacity' => 20]);
|
||||
$fare_svc->setForSubfleet($subfleet, $fare_business);
|
||||
|
||||
# Add first class
|
||||
// Add first class
|
||||
$fare_first = factory(App\Models\Fare::class)->create(['code' => 'F', 'capacity' => 10]);
|
||||
$fare_svc->setForSubfleet($subfleet, $fare_first);
|
||||
|
||||
@@ -60,79 +61,79 @@ class ImporterTest extends TestCase
|
||||
{
|
||||
$tests = [
|
||||
[
|
||||
'input' => '',
|
||||
'input' => '',
|
||||
'expected' => [],
|
||||
],
|
||||
[
|
||||
'input' => 'gate',
|
||||
'expected' => ['gate']
|
||||
'input' => 'gate',
|
||||
'expected' => ['gate'],
|
||||
],
|
||||
[
|
||||
'input' => 'gate;cost index',
|
||||
'input' => 'gate;cost index',
|
||||
'expected' => [
|
||||
'gate',
|
||||
'cost index',
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'gate=B32;cost index=100',
|
||||
'input' => 'gate=B32;cost index=100',
|
||||
'expected' => [
|
||||
'gate' => 'B32',
|
||||
'cost index' => '100'
|
||||
]
|
||||
'gate' => 'B32',
|
||||
'cost index' => '100',
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'Y?price=200&cost=100; F?price=1200',
|
||||
'input' => 'Y?price=200&cost=100; F?price=1200',
|
||||
'expected' => [
|
||||
'Y' => [
|
||||
'price' => 200,
|
||||
'cost' => 100,
|
||||
'cost' => 100,
|
||||
],
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'Y?price&cost; F?price=1200',
|
||||
'input' => 'Y?price&cost; F?price=1200',
|
||||
'expected' => [
|
||||
'Y' => [
|
||||
'price',
|
||||
'cost',
|
||||
],
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'Y; F?price=1200',
|
||||
'expected' => [
|
||||
0 => 'Y',
|
||||
0 => 'Y',
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'Y?;F?price=1200',
|
||||
'expected' => [
|
||||
'Y' => [],
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'input' => 'Departure Gate=4;Arrival Gate=C61',
|
||||
'input' => 'Departure Gate=4;Arrival Gate=C61',
|
||||
'expected' => [
|
||||
'Departure Gate' => '4',
|
||||
'Arrival Gate' => 'C61',
|
||||
]
|
||||
'Arrival Gate' => 'C61',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach($tests as $test) {
|
||||
foreach ($tests as $test) {
|
||||
$parsed = $this->importBaseClass->parseMultiColumnValues($test['input']);
|
||||
$this->assertEquals($test['expected'], $parsed);
|
||||
}
|
||||
@@ -146,12 +147,12 @@ class ImporterTest extends TestCase
|
||||
{
|
||||
$tests = [
|
||||
[
|
||||
'input' => '',
|
||||
'expected' => ''
|
||||
'input' => '',
|
||||
'expected' => '',
|
||||
],
|
||||
[
|
||||
'input' => ['gate'],
|
||||
'expected' => 'gate',
|
||||
'input' => ['gate'],
|
||||
'expected' => 'gate',
|
||||
],
|
||||
[
|
||||
'input' => [
|
||||
@@ -163,7 +164,7 @@ class ImporterTest extends TestCase
|
||||
[
|
||||
'input' => [
|
||||
'gate' => 'B32',
|
||||
'cost index' => '100'
|
||||
'cost index' => '100',
|
||||
],
|
||||
'expected' => 'gate=B32;cost index=100',
|
||||
],
|
||||
@@ -174,8 +175,8 @@ class ImporterTest extends TestCase
|
||||
'cost' => 100,
|
||||
],
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
'expected' => 'Y?price=200&cost=100;F?price=1200',
|
||||
],
|
||||
@@ -186,18 +187,18 @@ class ImporterTest extends TestCase
|
||||
'cost',
|
||||
],
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
'expected' => 'Y?price&cost;F?price=1200',
|
||||
],
|
||||
[
|
||||
'input' => [
|
||||
'input' => [
|
||||
'Y' => [
|
||||
'price',
|
||||
'cost',
|
||||
],
|
||||
'F' => []
|
||||
'F' => [],
|
||||
],
|
||||
'expected' => 'Y?price&cost;F',
|
||||
],
|
||||
@@ -205,8 +206,8 @@ class ImporterTest extends TestCase
|
||||
'input' => [
|
||||
0 => 'Y',
|
||||
'F' => [
|
||||
'price' => 1200
|
||||
]
|
||||
'price' => 1200,
|
||||
],
|
||||
],
|
||||
'expected' => 'Y;F?price=1200',
|
||||
],
|
||||
@@ -284,9 +285,9 @@ class ImporterTest extends TestCase
|
||||
$fareF = \App\Models\Fare::where('code', 'F')->first();
|
||||
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $airline->id,
|
||||
'airline_id' => $airline->id,
|
||||
'flight_type' => 'J',
|
||||
'days' => \App\Models\Enums\Days::getDaysMask([
|
||||
'days' => \App\Models\Enums\Days::getDaysMask([
|
||||
\App\Models\Enums\Days::TUESDAY,
|
||||
\App\Models\Enums\Days::SUNDAY,
|
||||
]),
|
||||
@@ -301,14 +302,14 @@ class ImporterTest extends TestCase
|
||||
// Add some custom fields
|
||||
\App\Models\FlightFieldValue::create([
|
||||
'flight_id' => $flight->id,
|
||||
'name' => 'Departure Gate',
|
||||
'value' => '4'
|
||||
'name' => 'Departure Gate',
|
||||
'value' => '4',
|
||||
]);
|
||||
|
||||
\App\Models\FlightFieldValue::create([
|
||||
'flight_id' => $flight->id,
|
||||
'name' => 'Arrival Gate',
|
||||
'value' => 'C41'
|
||||
'value' => 'C41',
|
||||
]);
|
||||
|
||||
// Test the conversion
|
||||
@@ -334,6 +335,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Try importing the aicraft in the airports. Should fail
|
||||
*
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testInvalidFileImport(): void
|
||||
@@ -356,6 +358,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Test the importing of expenses
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testExpenseImporter(): void
|
||||
@@ -363,7 +366,7 @@ class ImporterTest extends TestCase
|
||||
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']);
|
||||
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => '744-3X-RB211']);
|
||||
$aircraft = factory(App\Models\Aircraft::class)->create([
|
||||
'subfleet_id' => $subfleet->id,
|
||||
'subfleet_id' => $subfleet->id,
|
||||
'registration' => '001Z',
|
||||
]);
|
||||
|
||||
@@ -434,6 +437,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Test the flight importer
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testFlightImporter(): void
|
||||
@@ -449,7 +453,7 @@ class ImporterTest extends TestCase
|
||||
// See if it imported
|
||||
$flight = \App\Models\Flight::where([
|
||||
'airline_id' => $airline->id,
|
||||
'flight_number' => '1972'
|
||||
'flight_number' => '1972',
|
||||
])->first();
|
||||
|
||||
$this->assertNotNull($flight);
|
||||
@@ -467,7 +471,7 @@ class ImporterTest extends TestCase
|
||||
$this->assertEquals('Just a flight', $flight->notes);
|
||||
$this->assertEquals(true, $flight->active);
|
||||
|
||||
# Test that the days were set properly
|
||||
// Test that the days were set properly
|
||||
$this->assertTrue($flight->on_day(\App\Models\Enums\Days::MONDAY));
|
||||
$this->assertTrue($flight->on_day(\App\Models\Enums\Days::FRIDAY));
|
||||
$this->assertFalse($flight->on_day(\App\Models\Enums\Days::TUESDAY));
|
||||
@@ -505,6 +509,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Test the flight importer
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testFlightImporterEmptyCustomFields(): void
|
||||
@@ -520,7 +525,7 @@ class ImporterTest extends TestCase
|
||||
// See if it imported
|
||||
$flight = \App\Models\Flight::where([
|
||||
'airline_id' => $airline->id,
|
||||
'flight_number' => '1972'
|
||||
'flight_number' => '1972',
|
||||
])->first();
|
||||
|
||||
$this->assertNotNull($flight);
|
||||
@@ -600,6 +605,7 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Test importing the subfleets
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testSubfleetImporter(): void
|
||||
|
||||
@@ -4,7 +4,8 @@ use App\Support\Math;
|
||||
|
||||
class MathTest extends TestCase
|
||||
{
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,9 +26,8 @@ class MathTest extends TestCase
|
||||
['expected' => 88, 'fn' => Math::addPercent('100', '-12%')],
|
||||
];
|
||||
|
||||
foreach($tests as $test) {
|
||||
foreach ($tests as $test) {
|
||||
$this->assertEquals($test['expected'], $test['fn']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class MetarTest extends TestCase
|
||||
$metar =
|
||||
'KJFK 042151Z 28026G39KT 10SM FEW055 SCT095 BKN110 BKN230 12/M04 A2958 RMK AO2 PK WND 27045/2128 PRESRR SLP018 T01221044';
|
||||
|
||||
#$m = new Metar($metar);
|
||||
#$parsed = $m->result;
|
||||
//$m = new Metar($metar);
|
||||
//$parsed = $m->result;
|
||||
$parsed = Metar::parse($metar);
|
||||
|
||||
/*
|
||||
@@ -76,7 +76,6 @@ class MetarTest extends TestCase
|
||||
$this->assertEquals(0.87, $parsed['barometer_in']);
|
||||
|
||||
$this->assertEquals('AO2 PK WND 27045/2128 PRESRR SLP018 T01221044', $parsed['remarks']);
|
||||
|
||||
}
|
||||
|
||||
public function testMetarTrends()
|
||||
@@ -90,7 +89,6 @@ class MetarTest extends TestCase
|
||||
* Altimeter is 29.70. Remarks: automated station with precipitation discriminator sea level
|
||||
* pressure 1005.6 hectopascals hourly temp 7.8°C dewpoint 6.7°C
|
||||
*/
|
||||
|
||||
$parsed = Metar::parse($metar);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ use Carbon\Carbon;
|
||||
|
||||
class PIREPTest extends TestCase
|
||||
{
|
||||
protected $pirepSvc, $settingsRepo;
|
||||
protected $pirepSvc;
|
||||
protected $settingsRepo;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -48,21 +49,19 @@ class PIREPTest extends TestCase
|
||||
return $saved_route;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testAddPirep()
|
||||
{
|
||||
$user = factory(App\Models\User::class)->create();
|
||||
$route = $this->createNewRoute();
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'route' => implode(' ', $route)
|
||||
'route' => implode(' ', $route),
|
||||
]);
|
||||
|
||||
$pirep = $this->pirepSvc->create($pirep, []);
|
||||
$this->pirepSvc->saveRoute($pirep);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Check the initial state info
|
||||
*/
|
||||
$this->assertEquals($pirep->state, PirepState::PENDING);
|
||||
@@ -79,11 +78,11 @@ class PIREPTest extends TestCase
|
||||
$this->assertEquals($new_flight_time, $pirep->pilot->flight_time);
|
||||
$this->assertEquals($pirep->arr_airport_id, $pirep->pilot->curr_airport_id);
|
||||
|
||||
# Check the location of the current aircraft
|
||||
// Check the location of the current aircraft
|
||||
$this->assertEquals($pirep->aircraft->airport_id, $pirep->arr_airport_id);
|
||||
|
||||
# Also check via API:
|
||||
$this->get('/api/fleet/aircraft/' . $pirep->aircraft_id, [], $user)
|
||||
// Also check via API:
|
||||
$this->get('/api/fleet/aircraft/'.$pirep->aircraft_id, [], $user)
|
||||
->assertJson(['data' => ['airport_id' => $pirep->arr_airport_id]]);
|
||||
|
||||
/**
|
||||
@@ -110,7 +109,7 @@ class PIREPTest extends TestCase
|
||||
$pirep->route = implode(' ', $route);
|
||||
$pirep->save();
|
||||
|
||||
# this should delete the old route from the acars table
|
||||
// this should delete the old route from the acars table
|
||||
$this->pirepSvc->saveRoute($pirep);
|
||||
|
||||
$saved_route = $this->getAcarsRoute($pirep);
|
||||
@@ -143,25 +142,22 @@ class PIREPTest extends TestCase
|
||||
$this->assertEquals($pirep->planned_distance['nmi'], $body['planned_distance']['nmi']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testGetUserPireps()
|
||||
{
|
||||
$this->user = factory(App\Models\User::class)->create();
|
||||
$pirep_done = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'state' => PirepState::ACCEPTED
|
||||
'state' => PirepState::ACCEPTED,
|
||||
]);
|
||||
|
||||
$pirep_in_progress = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'state' => PirepState::IN_PROGRESS
|
||||
'state' => PirepState::IN_PROGRESS,
|
||||
]);
|
||||
|
||||
$pirep_cancelled = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'state' => PirepState::CANCELLED
|
||||
'state' => PirepState::CANCELLED,
|
||||
]);
|
||||
|
||||
$pireps = $this->get('/api/user/pireps')
|
||||
@@ -191,17 +187,17 @@ class PIREPTest extends TestCase
|
||||
public function testPilotStatsIncr()
|
||||
{
|
||||
$user = factory(User::class)->create([
|
||||
'airline_id' => 1,
|
||||
'flights' => 0,
|
||||
'airline_id' => 1,
|
||||
'flights' => 0,
|
||||
'flight_time' => 0,
|
||||
'rank_id' => 1,
|
||||
'rank_id' => 1,
|
||||
]);
|
||||
|
||||
# Submit two PIREPs
|
||||
// Submit two PIREPs
|
||||
$pireps = factory(Pirep::class, 2)->create([
|
||||
'airline_id' => 1,
|
||||
'user_id' => $user->id,
|
||||
# 360min == 6 hours, rank should bump up
|
||||
'user_id' => $user->id,
|
||||
// 360min == 6 hours, rank should bump up
|
||||
'flight_time' => 360,
|
||||
]);
|
||||
|
||||
@@ -213,33 +209,33 @@ class PIREPTest extends TestCase
|
||||
$pilot = User::find($user->id);
|
||||
$last_pirep = Pirep::where('id', $pilot->last_pirep_id)->first();
|
||||
|
||||
# Make sure rank went up
|
||||
// Make sure rank went up
|
||||
$this->assertGreaterThan($user->rank_id, $pilot->rank_id);
|
||||
$this->assertEquals($last_pirep->arr_airport_id, $pilot->curr_airport_id);
|
||||
|
||||
#
|
||||
# Submit another PIREP, adding another 6 hours
|
||||
# it should automatically be accepted
|
||||
#
|
||||
//
|
||||
// Submit another PIREP, adding another 6 hours
|
||||
// it should automatically be accepted
|
||||
//
|
||||
$pirep = factory(Pirep::class)->create([
|
||||
'airline_id' => 1,
|
||||
'user_id' => $user->id,
|
||||
# 120min == 2 hours, currently at 9 hours
|
||||
# Rank bumps up at 10 hours
|
||||
'user_id' => $user->id,
|
||||
// 120min == 2 hours, currently at 9 hours
|
||||
// Rank bumps up at 10 hours
|
||||
'flight_time' => 120,
|
||||
]);
|
||||
|
||||
# Pilot should be at rank 2, where accept should be automatic
|
||||
// Pilot should be at rank 2, where accept should be automatic
|
||||
$this->pirepSvc->create($pirep);
|
||||
$this->pirepSvc->submit($pirep);
|
||||
|
||||
$pilot->refresh();
|
||||
$latest_pirep = Pirep::where('id', $pilot->last_pirep_id)->first();
|
||||
|
||||
# Make sure PIREP was auto updated
|
||||
// Make sure PIREP was auto updated
|
||||
$this->assertEquals(PirepState::ACCEPTED, $latest_pirep->state);
|
||||
|
||||
# Make sure latest PIREP was updated
|
||||
// Make sure latest PIREP was updated
|
||||
$this->assertNotEquals($last_pirep->id, $latest_pirep->id);
|
||||
}
|
||||
|
||||
@@ -250,10 +246,10 @@ class PIREPTest extends TestCase
|
||||
{
|
||||
$user = factory(App\Models\User::class)->create();
|
||||
$pirep = factory(Pirep::class)->create([
|
||||
'user_id' => $user->id
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
# This should find itself...
|
||||
// This should find itself...
|
||||
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
||||
$this->assertNotFalse($dupe_pirep);
|
||||
$this->assertEquals($pirep->id, $dupe_pirep->id);
|
||||
@@ -261,20 +257,16 @@ class PIREPTest extends TestCase
|
||||
/**
|
||||
* Create a PIREP outside of the check time interval
|
||||
*/
|
||||
|
||||
$minutes = setting('pireps.duplicate_check_time') + 1;
|
||||
$pirep = factory(Pirep::class)->create([
|
||||
'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString()
|
||||
'created_at' => Carbon::now()->subMinutes($minutes)->toDateTimeString(),
|
||||
]);
|
||||
|
||||
# This should find itself...
|
||||
// This should find itself...
|
||||
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
||||
$this->assertFalse($dupe_pirep);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testCancelViaAPI()
|
||||
{
|
||||
$pirep = $this->createPirep()->toArray();
|
||||
@@ -283,21 +275,21 @@ class PIREPTest extends TestCase
|
||||
$response = $this->post($uri, $pirep);
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$uri = '/api/pireps/' . $pirep_id . '/acars/position';
|
||||
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
||||
$acars = factory(App\Models\Acars::class)->make()->toArray();
|
||||
$response = $this->post($uri, [
|
||||
'positions' => [$acars]
|
||||
'positions' => [$acars],
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
# Cancel it
|
||||
$uri = '/api/pireps/' . $pirep_id . '/cancel';
|
||||
// Cancel it
|
||||
$uri = '/api/pireps/'.$pirep_id.'/cancel';
|
||||
$response = $this->delete($uri, $acars);
|
||||
$response->assertStatus(200);
|
||||
|
||||
# Should get a 400 when posting an ACARS update
|
||||
$uri = '/api/pireps/' . $pirep_id . '/acars/position';
|
||||
// Should get a 400 when posting an ACARS update
|
||||
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
|
||||
$acars = factory(App\Models\Acars::class)->make()->toArray();
|
||||
|
||||
$response = $this->post($uri, $acars);
|
||||
@@ -318,14 +310,14 @@ class PIREPTest extends TestCase
|
||||
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
'route_code' => null,
|
||||
'route_leg' => null,
|
||||
'route_leg' => null,
|
||||
]);
|
||||
|
||||
$flightSvc->addBid($flight, $user);
|
||||
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'airline_id' => $flight->airline_id,
|
||||
'user_id' => $user->id,
|
||||
'airline_id' => $flight->airline_id,
|
||||
'flight_number' => $flight->flight_number,
|
||||
]);
|
||||
|
||||
@@ -333,7 +325,7 @@ class PIREPTest extends TestCase
|
||||
$this->pirepSvc->changeState($pirep, PirepState::ACCEPTED);
|
||||
|
||||
$user_bid = Bid::where([
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'flight_id' => $flight->id,
|
||||
])->first();
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
class SubfleetTest extends TestCase
|
||||
{
|
||||
protected $ac_svc,
|
||||
$ICAO = 'B777';
|
||||
protected $ac_svc;
|
||||
protected $ICAO = 'B777';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -26,21 +26,21 @@ class SubfleetTest extends TestCase
|
||||
$this->assertEquals($fare->price, $subfleet_fares->get(0)->price);
|
||||
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
||||
|
||||
#
|
||||
# set an override now
|
||||
#
|
||||
//
|
||||
// set an override now
|
||||
//
|
||||
$fare_svc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 50, 'capacity' => 400
|
||||
'price' => 50, 'capacity' => 400,
|
||||
]);
|
||||
|
||||
# look for them again
|
||||
// look for them again
|
||||
$subfleet_fares = $fare_svc->getForSubfleet($subfleet);
|
||||
|
||||
$this->assertCount(1, $subfleet_fares);
|
||||
$this->assertEquals(50, $subfleet_fares[0]->price);
|
||||
$this->assertEquals(400, $subfleet_fares[0]->capacity);
|
||||
|
||||
# delete
|
||||
// delete
|
||||
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
||||
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class SubfleetTest extends TestCase
|
||||
$fare = factory(App\Models\Fare::class)->create();
|
||||
|
||||
$fare_svc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 50, 'capacity' => 400
|
||||
'price' => 50, 'capacity' => 400,
|
||||
]);
|
||||
|
||||
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
||||
@@ -62,12 +62,12 @@ class SubfleetTest extends TestCase
|
||||
$this->assertEquals(50, $ac_fares[0]->price);
|
||||
$this->assertEquals(400, $ac_fares[0]->capacity);
|
||||
|
||||
#
|
||||
# update the override to a different amount and make sure it updates
|
||||
#
|
||||
//
|
||||
// update the override to a different amount and make sure it updates
|
||||
//
|
||||
|
||||
$fare_svc->setForSubfleet($subfleet, $fare, [
|
||||
'price' => 150, 'capacity' => 50
|
||||
'price' => 150, 'capacity' => 50,
|
||||
]);
|
||||
|
||||
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
||||
@@ -76,7 +76,7 @@ class SubfleetTest extends TestCase
|
||||
$this->assertEquals(150, $ac_fares[0]->price);
|
||||
$this->assertEquals(50, $ac_fares[0]->capacity);
|
||||
|
||||
# delete
|
||||
// delete
|
||||
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
||||
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
protected $user;
|
||||
|
||||
protected static $auth_headers = [
|
||||
'x-api-key' => 'testadminapikey'
|
||||
'x-api-key' => 'testadminapikey',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -39,11 +39,12 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Creates the application. Required to be implemented
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
return $app;
|
||||
}
|
||||
@@ -51,14 +52,15 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
/**
|
||||
* @param $user
|
||||
* @param array $headers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function headers($user=null, array $headers = []): array
|
||||
public function headers($user = null, array $headers = []): array
|
||||
{
|
||||
if($user !== null) {
|
||||
if ($user !== null) {
|
||||
$headers['x-api-key'] = $user->api_key;
|
||||
} else {
|
||||
if($this->user !== null) {
|
||||
if ($this->user !== null) {
|
||||
$headers['x-api-key'] = $this->user->api_key;
|
||||
}
|
||||
}
|
||||
@@ -68,12 +70,14 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Import data from a YML file
|
||||
*
|
||||
* @param $file
|
||||
*/
|
||||
public function addData($file)
|
||||
{
|
||||
$svc = app(DatabaseService::class);
|
||||
$file_path = base_path('tests/data/' . $file . '.yml');
|
||||
$file_path = base_path('tests/data/'.$file.'.yml');
|
||||
|
||||
try {
|
||||
$svc->seed_from_yaml_file($file_path);
|
||||
} catch (Exception $e) {
|
||||
@@ -82,12 +86,13 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Make sure an object has the list of keys
|
||||
*
|
||||
* @param $obj
|
||||
* @param array $keys
|
||||
*/
|
||||
public function assertHasKeys($obj, $keys=[])
|
||||
public function assertHasKeys($obj, $keys = [])
|
||||
{
|
||||
foreach($keys as $key) {
|
||||
foreach ($keys as $key) {
|
||||
$this->assertArrayHasKey($key, $obj);
|
||||
}
|
||||
}
|
||||
@@ -95,11 +100,14 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
/**
|
||||
* So we can test private/protected methods
|
||||
* http://bit.ly/1mr5hMq
|
||||
*
|
||||
* @param $object
|
||||
* @param $methodName
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws ReflectionException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = [])
|
||||
{
|
||||
@@ -113,13 +121,15 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
/**
|
||||
* Transform any data that's passed in. E.g, make sure that any mutator
|
||||
* classes (e.g, units) are not passed in as the mutator class
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function transformData(&$data)
|
||||
{
|
||||
foreach($data as $key => &$value) {
|
||||
if(is_array($value)) {
|
||||
foreach ($data as $key => &$value) {
|
||||
if (is_array($value)) {
|
||||
$this->transformData($value);
|
||||
}
|
||||
|
||||
@@ -127,7 +137,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
$data[$key] = $value->__toString();
|
||||
}
|
||||
|
||||
if($value instanceof DateTime) {
|
||||
if ($value instanceof DateTimeImmutable) {
|
||||
$data[$key] = $value->format(DATE_ATOM);
|
||||
} elseif ($value instanceof Carbon) {
|
||||
$data[$key] = $value->toIso8601ZuluString();
|
||||
@@ -139,16 +149,18 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Override the GET call to inject the user API key
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
*
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function get($uri, array $headers=[], $user=null): \Illuminate\Foundation\Testing\TestResponse
|
||||
public function get($uri, array $headers = [], $user = null): \Illuminate\Foundation\Testing\TestResponse
|
||||
{
|
||||
$req = parent::get($uri, $this->headers($user, $headers));
|
||||
if($req->isClientError() || $req->isServerError()) {
|
||||
Log::error('GET Error: ' . $uri, $req->json());
|
||||
if ($req->isClientError() || $req->isServerError()) {
|
||||
Log::error('GET Error: '.$uri, $req->json());
|
||||
}
|
||||
|
||||
return $req;
|
||||
@@ -156,18 +168,20 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Override the POST calls to inject the user API key
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
*
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function post($uri, array $data = [], array $headers = [], $user=null)
|
||||
public function post($uri, array $data = [], array $headers = [], $user = null)
|
||||
{
|
||||
$data = $this->transformData($data);
|
||||
$req = parent::post($uri, $data, $this->headers($user, $headers));
|
||||
if ($req->isClientError() || $req->isServerError()) {
|
||||
Log::error('POST Error: ' . $uri, $req->json());
|
||||
Log::error('POST Error: '.$uri, $req->json());
|
||||
}
|
||||
|
||||
return $req;
|
||||
@@ -175,17 +189,19 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Override the PUT calls to inject the user API key
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
*
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function put($uri, array $data = [], array $headers = [], $user = null)
|
||||
{
|
||||
$req = parent::put($uri, $this->transformData($data), $this->headers($user, $headers));
|
||||
if ($req->isClientError() || $req->isServerError()) {
|
||||
Log::error('PUT Error: ' . $uri, $req->json());
|
||||
Log::error('PUT Error: '.$uri, $req->json());
|
||||
}
|
||||
|
||||
return $req;
|
||||
@@ -193,17 +209,19 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
|
||||
/**
|
||||
* Override the DELETE calls to inject the user API key
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
*
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function delete($uri, array $data = [], array $headers = [], $user=null)
|
||||
public function delete($uri, array $data = [], array $headers = [], $user = null)
|
||||
{
|
||||
$req = parent::delete($uri, $this->transformData($data), $this->headers($user, $headers));
|
||||
if ($req->isClientError() || $req->isServerError()) {
|
||||
Log::error('DELETE Error: ' . $uri, $req->json());
|
||||
Log::error('DELETE Error: '.$uri, $req->json());
|
||||
}
|
||||
|
||||
return $req;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Tests;
|
||||
|
||||
@@ -10,6 +7,7 @@ trait TestData
|
||||
/**
|
||||
* Create a new PIREP with a proper subfleet/rank/user and an
|
||||
* aircraft that the user is allowed to fly
|
||||
*
|
||||
* @return \App\Models\Pirep
|
||||
*/
|
||||
protected function createPirep()
|
||||
@@ -17,12 +15,12 @@ trait TestData
|
||||
$subfleet = $this->createSubfleetWithAircraft(2);
|
||||
$rank = $this->createRank(10, [$subfleet['subfleet']->id]);
|
||||
$this->user = factory(\App\Models\User::class)->create([
|
||||
'rank_id' => $rank->id
|
||||
'rank_id' => $rank->id,
|
||||
]);
|
||||
|
||||
// Return a Pirep model
|
||||
$pirep = factory(\App\Models\Pirep::class)->make([
|
||||
'aircraft_id' => $subfleet['aircraft']->random()->id
|
||||
'aircraft_id' => $subfleet['aircraft']->random()->id,
|
||||
]);
|
||||
|
||||
return $pirep;
|
||||
@@ -30,20 +28,22 @@ trait TestData
|
||||
|
||||
/**
|
||||
* Create a rank and associate the given subfleet IDs with it
|
||||
* @param int $hours
|
||||
*
|
||||
* @param int $hours
|
||||
* @param array $subfleet_ids
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createRank($hours=0, array $subfleet_ids)
|
||||
public function createRank($hours, array $subfleet_ids)
|
||||
{
|
||||
$attrs = [];
|
||||
|
||||
if($hours === null) {
|
||||
if ($hours === null) {
|
||||
$attrs['hours'] = $hours;
|
||||
}
|
||||
|
||||
$rank = factory(\App\Models\Rank::class)->create($attrs);
|
||||
if(!empty($subfleet_ids)) {
|
||||
if (!empty($subfleet_ids)) {
|
||||
$rank->subfleets()->syncWithoutDetaching($subfleet_ids);
|
||||
}
|
||||
|
||||
@@ -52,23 +52,25 @@ trait TestData
|
||||
|
||||
/**
|
||||
* Create a subfleet with a number of aircraft assigned
|
||||
*
|
||||
* @param null $aircraft_count
|
||||
* @param null $airport_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createSubfleetWithAircraft($aircraft_count = null, $airport_id=null)
|
||||
public function createSubfleetWithAircraft($aircraft_count = null, $airport_id = null)
|
||||
{
|
||||
$subfleet = factory(\App\Models\Subfleet::class)->create([
|
||||
'ground_handling_multiplier' => '100',
|
||||
]);
|
||||
|
||||
if($aircraft_count === null) {
|
||||
if ($aircraft_count === null) {
|
||||
$aircraft_count = \random_int(2, 10);
|
||||
}
|
||||
|
||||
$aircraft = factory(\App\Models\Aircraft::class, $aircraft_count)->create([
|
||||
'subfleet_id' => $subfleet->id,
|
||||
'airport_id' => $airport_id,
|
||||
'airport_id' => $airport_id,
|
||||
]);
|
||||
|
||||
return [
|
||||
|
||||
@@ -5,7 +5,8 @@ use App\Services\UserService;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
protected $settingsRepo, $userSvc;
|
||||
protected $settingsRepo;
|
||||
protected $userSvc;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -20,8 +21,8 @@ class UserTest extends TestCase
|
||||
*/
|
||||
public function testRankSubfleets()
|
||||
{
|
||||
# Add subfleets and aircraft, but also add another
|
||||
# set of subfleets
|
||||
// Add subfleets and aircraft, but also add another
|
||||
// set of subfleets
|
||||
$subfleetA = $this->createSubfleetWithAircraft();
|
||||
$this->createSubfleetWithAircraft();
|
||||
|
||||
@@ -46,38 +47,37 @@ class UserTest extends TestCase
|
||||
$resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200);
|
||||
$body = $resp->json()['data'];
|
||||
|
||||
# Get the subfleet that's been added in
|
||||
// Get the subfleet that's been added in
|
||||
$subfleet_from_api = $body[0];
|
||||
$this->assertEquals($subfleet->id, $subfleet_from_api['id']);
|
||||
|
||||
# Get all the aircraft from that subfleet
|
||||
// Get all the aircraft from that subfleet
|
||||
$aircraft_from_api = collect($subfleet_from_api['aircraft'])->pluck('id');
|
||||
$this->assertEquals($added_aircraft, $aircraft_from_api);
|
||||
|
||||
/**
|
||||
* Check the user ID call
|
||||
*/
|
||||
$resp = $this->get('/api/users/' . $user->id . '/fleet', [], $user)->assertStatus(200);
|
||||
$resp = $this->get('/api/users/'.$user->id.'/fleet', [], $user)->assertStatus(200);
|
||||
$body = $resp->json()['data'];
|
||||
|
||||
# Get the subfleet that's been added in
|
||||
// Get the subfleet that's been added in
|
||||
$subfleet_from_api = $body[0];
|
||||
$this->assertEquals($subfleet->id, $subfleet_from_api['id']);
|
||||
|
||||
# Get all the aircraft from that subfleet
|
||||
// Get all the aircraft from that subfleet
|
||||
$aircraft_from_api = collect($subfleet_from_api['aircraft'])->pluck('id');
|
||||
$this->assertEquals($added_aircraft, $aircraft_from_api);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flip the setting for getting all of the user's aircraft restricted
|
||||
* by rank. Make sure that they're all returned
|
||||
*/
|
||||
public function testGetAllAircraft()
|
||||
{
|
||||
# Add subfleets and aircraft, but also add another
|
||||
# set of subfleets
|
||||
// Add subfleets and aircraft, but also add another
|
||||
// set of subfleets
|
||||
$subfleetA = $this->createSubfleetWithAircraft();
|
||||
$subfleetB = $this->createSubfleetWithAircraft();
|
||||
|
||||
@@ -104,13 +104,12 @@ class UserTest extends TestCase
|
||||
|
||||
$this->assertEquals($added_aircraft, $all_aircraft);
|
||||
|
||||
|
||||
/**
|
||||
* Check via API
|
||||
*/
|
||||
$resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200);
|
||||
|
||||
# Get all the aircraft from that subfleet
|
||||
// Get all the aircraft from that subfleet
|
||||
$body = $resp->json()['data'];
|
||||
$aircraft_from_api = array_merge(
|
||||
collect($body[0]['aircraft'])->pluck('id')->toArray(),
|
||||
@@ -128,8 +127,8 @@ class UserTest extends TestCase
|
||||
*/
|
||||
public function testGetAircraftAllowedFromFlight()
|
||||
{
|
||||
# Add subfleets and aircraft, but also add another
|
||||
# set of subfleets
|
||||
// Add subfleets and aircraft, but also add another
|
||||
// set of subfleets
|
||||
$airport = factory(App\Models\Airport::class)->create();
|
||||
$subfleetA = $this->createSubfleetWithAircraft(2, $airport->id);
|
||||
$subfleetB = $this->createSubfleetWithAircraft(2);
|
||||
@@ -137,17 +136,17 @@ class UserTest extends TestCase
|
||||
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
|
||||
$user = factory(App\Models\User::class)->create([
|
||||
'curr_airport_id' => $airport->id,
|
||||
'rank_id' => $rank->id,
|
||||
'rank_id' => $rank->id,
|
||||
]);
|
||||
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
'airline_id' => $user->airline_id,
|
||||
'airline_id' => $user->airline_id,
|
||||
'dpt_airport_id' => $airport->id,
|
||||
]);
|
||||
|
||||
$flight->subfleets()->syncWithoutDetaching([
|
||||
$subfleetA['subfleet']->id,
|
||||
$subfleetB['subfleet']->id
|
||||
$subfleetB['subfleet']->id,
|
||||
]);
|
||||
|
||||
/*
|
||||
@@ -158,13 +157,13 @@ class UserTest extends TestCase
|
||||
* Do some sanity checks first
|
||||
*/
|
||||
|
||||
# Make sure no flights are filtered out
|
||||
// Make sure no flights are filtered out
|
||||
$this->settingsRepo->store('pilots.only_flights_from_current', false);
|
||||
|
||||
# And restrict the aircraft
|
||||
// And restrict the aircraft
|
||||
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
|
||||
|
||||
$response = $this->get('/api/flights/' . $flight->id, [], $user);
|
||||
$response = $this->get('/api/flights/'.$flight->id, [], $user);
|
||||
$response->assertStatus(200);
|
||||
$this->assertCount(2, $response->json()['data']['subfleets']);
|
||||
|
||||
@@ -176,7 +175,7 @@ class UserTest extends TestCase
|
||||
/**
|
||||
* Make sure it's filtered out from the single flight call
|
||||
*/
|
||||
$response = $this->get('/api/flights/' . $flight->id, [], $user);
|
||||
$response = $this->get('/api/flights/'.$flight->id, [], $user);
|
||||
$response->assertStatus(200);
|
||||
$this->assertCount(1, $response->json()['data']['subfleets']);
|
||||
|
||||
@@ -191,7 +190,7 @@ class UserTest extends TestCase
|
||||
/**
|
||||
* Filtered from search?
|
||||
*/
|
||||
$response = $this->get('/api/flights/search?flight_id=' . $flight->id, [], $user);
|
||||
$response = $this->get('/api/flights/search?flight_id='.$flight->id, [], $user);
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json()['data'];
|
||||
$this->assertCount(1, $body[0]['subfleets']);
|
||||
|
||||
@@ -4,7 +4,8 @@ use App\Facades\Utils;
|
||||
|
||||
class UtilsTest extends TestCase
|
||||
{
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function testDates()
|
||||
|
||||
Reference in New Issue
Block a user