Check for airline being active; fix tests for L7 #718

This commit is contained in:
Nabeel Shahzad 2020-05-23 11:43:29 -04:00
parent 71c09aaeb1
commit c46fc9171c
36 changed files with 954 additions and 627 deletions

View File

@ -74,9 +74,9 @@ reload-db:
tests: test tests: test
.PHONY: test .PHONY: test
test: phpcs test:
#php artisan database:create --reset @#php artisan database:create --reset
vendor/bin/phpunit --debug --verbose @vendor/bin/phpunit --verbose --debug
.PHONY: phpcs .PHONY: phpcs
phpcs: phpcs:

View File

@ -6,10 +6,10 @@ $factory->define(App\Models\Aircraft::class, function (Faker $faker) {
return [ return [
'id' => null, 'id' => null,
'subfleet_id' => function () { 'subfleet_id' => function () {
return factory(App\Models\Subfleet::class)->create()->id; return factory(\App\Models\Subfleet::class)->create()->id;
}, },
'airport_id' => function () { 'airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id; return factory(\App\Models\Airport::class)->create()->id;
}, },
'iata' => $faker->unique()->text(5), 'iata' => $faker->unique()->text(5),
'icao' => $faker->unique()->text(5), 'icao' => $faker->unique()->text(5),

View File

@ -8,19 +8,19 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) {
return [ return [
'id' => $faker->unique()->numberBetween(10, 10000000), 'id' => $faker->unique()->numberBetween(10, 10000000),
'airline_id' => function () { 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id; return factory(\App\Models\Airline::class)->create()->id;
}, },
'flight_number' => $faker->unique()->numberBetween(10, 1000000), 'flight_number' => $faker->unique()->numberBetween(10, 1000000),
'route_code' => $faker->randomElement(['', $faker->text(5)]), 'route_code' => $faker->randomElement(['', $faker->text(5)]),
'route_leg' => $faker->randomElement(['', $faker->numberBetween(0, 1000)]), 'route_leg' => $faker->randomElement(['', $faker->numberBetween(0, 1000)]),
'dpt_airport_id' => function () { 'dpt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id; return factory(\App\Models\Airport::class)->create()->id;
}, },
'arr_airport_id' => function () { 'arr_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id; return factory(\App\Models\Airport::class)->create()->id;
}, },
'alt_airport_id' => function () { 'alt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id; return factory(\App\Models\Airport::class)->create()->id;
}, },
'distance' => $faker->numberBetween(1, 1000), 'distance' => $faker->numberBetween(1, 1000),
'route' => null, 'route' => null,

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\JournalTransactions::class, function (Faker $faker)
return [ return [
'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(), 'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
'journal_id' => function () { 'journal_id' => function () {
return factory(App\Models\Journal::class)->create()->id; return factory(\App\Models\Journal::class)->create()->id;
}, },
'credit' => $faker->numberBetween(100, 10000), 'credit' => $faker->numberBetween(100, 10000),
'debit' => $faker->numberBetween(100, 10000), 'debit' => $faker->numberBetween(100, 10000),

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\News::class, function (Faker $faker) {
return [ return [
'id' => null, 'id' => null,
'user_id' => function () { 'user_id' => function () {
return factory(App\Models\User::class)->create()->id; return factory(\App\Models\User::class)->create()->id;
}, },
'subject' => $faker->text(), 'subject' => $faker->text(),
'body' => $faker->sentence, 'body' => $faker->sentence,

View File

@ -10,8 +10,8 @@ use Faker\Generator as Faker;
* Create a new PIREP * Create a new PIREP
*/ */
$factory->define(App\Models\Pirep::class, function (Faker $faker) { $factory->define(App\Models\Pirep::class, function (Faker $faker) {
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(\App\Models\Airline::class)->create();
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(\App\Models\Flight::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
]); ]);
@ -21,10 +21,10 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
return $airline->id; return $airline->id;
}, },
'user_id' => function () { 'user_id' => function () {
return factory(App\Models\User::class)->create()->id; return factory(\App\Models\User::class)->create()->id;
}, },
'aircraft_id' => function () { 'aircraft_id' => function () {
return factory(App\Models\Aircraft::class)->create()->id; return factory(\App\Models\Aircraft::class)->create()->id;
}, },
'flight_id' => function () use ($flight) { 'flight_id' => function () use ($flight) {
return $flight->id; return $flight->id;

View File

@ -6,7 +6,7 @@ $factory->define(App\Models\Subfleet::class, function (Faker $faker) {
return [ return [
'id' => null, 'id' => null,
'airline_id' => function () { 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id; return factory(\App\Models\Airline::class)->create()->id;
}, },
'name' => $faker->unique()->text(50), 'name' => $faker->unique()->text(50),
'type' => $faker->unique()->text(7), 'type' => $faker->unique()->text(7),

View File

@ -14,7 +14,7 @@ $factory->define(App\Models\User::class, function (Faker $faker) {
'password' => $password ?: $password = Hash::make('secret'), 'password' => $password ?: $password = Hash::make('secret'),
'api_key' => $faker->sha1, 'api_key' => $faker->sha1,
'airline_id' => function () { 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id; return factory(\App\Models\Airline::class)->create()->id;
}, },
'rank_id' => 1, 'rank_id' => 1,
'flights' => $faker->numberBetween(0, 1000), 'flights' => $faker->numberBetween(0, 1000),

View File

@ -12,3 +12,11 @@ airlines:
active: 1 active: 1
created_at: now created_at: now
updated_at: now updated_at: now
- id: 2
icao: XXX
iata: XX
name: inactive airline
country: us
active: 0
created_at: now
updated_at: now

View File

@ -6,8 +6,6 @@ use App\Exceptions\Converters\GenericExceptionAbstract;
use App\Exceptions\Converters\SymfonyException; use App\Exceptions\Converters\SymfonyException;
use App\Exceptions\Converters\ValidationException; use App\Exceptions\Converters\ValidationException;
use App\Http\Middleware\SetActiveTheme; use App\Http\Middleware\SetActiveTheme;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
@ -16,7 +14,6 @@ use Illuminate\Http\Request;
use Illuminate\Session\TokenMismatchException; use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException as IlluminateValidationException; use Illuminate\Validation\ValidationException as IlluminateValidationException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException; use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable; use Throwable;

View File

@ -78,29 +78,32 @@ class FlightController extends Controller
*/ */
public function search(Request $request) public function search(Request $request)
{ {
/** @var \App\Models\User $user */
$user = Auth::user(); $user = Auth::user();
$where = [ $where = [
'active' => true, 'active' => true,
'visible' => true, 'visible' => true,
]; ];
// Allow the option to bypass some of these restrictions for the searches // Allow the option to bypass some of these restrictions for the searches
if (!$request->filled('ignore_restrictions') if (!$request->filled('ignore_restrictions') || $request->get('ignore_restrictions') === '0') {
|| $request->get('ignore_restrictions') === '0'
) {
if (setting('pilots.restrict_to_company')) { if (setting('pilots.restrict_to_company')) {
$where['airline_id'] = Auth::user()->airline_id; $where['airline_id'] = $user->airline_id;
} }
if (setting('pilots.only_flights_from_current')) { if (setting('pilots.only_flights_from_current')) {
$where['dpt_airport_id'] = Auth::user()->curr_airport_id; $where['dpt_airport_id'] = $user->curr_airport_id;
} }
} }
try { try {
$this->flightRepo->resetCriteria(); $this->flightRepo->resetCriteria();
$this->flightRepo->searchCriteria($request); $this->flightRepo->searchCriteria($request);
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); $this->flightRepo->pushCriteria(new WhereCriteria($request, $where, [
'airline' => ['active' => true],
]));
$this->flightRepo->pushCriteria(new RequestCriteria($request)); $this->flightRepo->pushCriteria(new RequestCriteria($request));
$flights = $this->flightRepo $flights = $this->flightRepo

View File

@ -75,8 +75,9 @@ class FlightController extends Controller
public function search(Request $request) public function search(Request $request)
{ {
$where = [ $where = [
'active' => true, 'active' => true,
'visible' => true, 'visible' => true,
'airlines.active' => true,
]; ];
if (setting('pilots.restrict_to_company')) { if (setting('pilots.restrict_to_company')) {

View File

@ -27,14 +27,19 @@ class AirlineRepository extends Repository implements CacheableInterface
/** /**
* Return the list of airline formatted for a select box * Return the list of airline formatted for a select box
* *
* @param mixed $add_blank * @param bool $add_blank
* @param bool $only_active
* *
* @return array * @return array
*/ */
public function selectBoxList($add_blank = false): array public function selectBoxList($add_blank = false, $only_active = true): array
{ {
$retval = []; $retval = [];
$items = $this->all(); $where = [
'active' => $only_active,
];
$items = $this->findWhere($where);
if ($add_blank) { if ($add_blank) {
$retval[''] = ''; $retval[''] = '';

View File

@ -69,7 +69,7 @@
"friendsofphp/php-cs-fixer": "^2.16", "friendsofphp/php-cs-fixer": "^2.16",
"mockery/mockery": "0.9.*", "mockery/mockery": "0.9.*",
"nunomaduro/collision": "^4.0", "nunomaduro/collision": "^4.0",
"phpunit/phpunit": "~8.3", "phpunit/phpunit": "~9.0",
"squizlabs/php_codesniffer": "3.*", "squizlabs/php_codesniffer": "3.*",
"sempro/phpunit-pretty-print": "^1.2" "sempro/phpunit-pretty-print": "^1.2"
}, },
@ -88,10 +88,7 @@
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Tests\\": "tests/" "Tests\\": "tests/"
}, }
"classmap": [
"tests/TestCase.php"
]
}, },
"extra": { "extra": {
"installer-types": ["phpvms-module"], "installer-types": ["phpvms-module"],

823
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,7 @@
convertNoticesToExceptions="false" convertNoticesToExceptions="false"
convertWarningsToExceptions="false" convertWarningsToExceptions="false"
beStrictAboutOutputDuringTests="false" beStrictAboutOutputDuringTests="false"
beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutTestsThatDoNotTestAnything="false">
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
<testsuites> <testsuites>
<testsuite name="Application Test Suite"> <testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory> <directory suffix="Test.php">./tests</directory>
@ -34,11 +33,14 @@
<server name="APP_KEY" value="base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI="/> <server name="APP_KEY" value="base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI="/>
<server name="APP_DEBUG" value="true"/> <server name="APP_DEBUG" value="true"/>
<server name="APP_LOG_LEVEL" value="error"/> <server name="APP_LOG_LEVEL" value="error"/>
<server name="DB_CONNECTION" value="memory"/> <server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/> <server name="CACHE_DRIVER" value="array"/>
<server name="SESSION_DRIVER" value="array"/> <server name="DB_CONNECTION" value="memory"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="DB_PREFIX" value="vmstest_"/> <server name="DB_PREFIX" value="vmstest_"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/> <server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/> <server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/> <server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>

View File

@ -1,11 +1,24 @@
<?php <?php
namespace Tests;
use App\Exceptions\AircraftNotAtAirport;
use App\Exceptions\UserNotAtAirport;
use App\Models\Acars;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\PirepState; use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus; use App\Models\Enums\PirepStatus;
use App\Models\Fare;
use App\Models\Navdata;
use App\Models\PirepFare; use App\Models\PirepFare;
use App\Models\PirepFieldValue; use App\Models\PirepFieldValue;
use App\Models\User;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Support\Utils; use App\Support\Utils;
use function count;
use function random_int;
/** /**
* Test API calls and authentication, etc * Test API calls and authentication, etc
@ -43,7 +56,7 @@ class AcarsTest extends TestCase
$addtl_fields $addtl_fields
); );
$this->assertCount(\count($route), $points); $this->assertCount(count($route), $points);
foreach ($route as $idx => $point) { foreach ($route as $idx => $point) {
$this->assertHasKeys($points[$idx], $fields); $this->assertHasKeys($points[$idx], $fields);
foreach ($fields as $f) { foreach ($fields as $f) {
@ -69,11 +82,11 @@ class AcarsTest extends TestCase
*/ */
public function testPrefileErrors() public function testPrefileErrors()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create(); $aircraft = factory(Aircraft::class)->create();
/** /**
* INVALID AIRLINE_ID FIELD * INVALID AIRLINE_ID FIELD
@ -96,10 +109,10 @@ class AcarsTest extends TestCase
public function testBlankAirport() public function testBlankAirport()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create(); $aircraft = factory(Aircraft::class)->create();
/** /**
* INVALID AIRLINE_ID FIELD * INVALID AIRLINE_ID FIELD
@ -134,13 +147,13 @@ class AcarsTest extends TestCase
$this->settingsRepo->store('pilots.only_flights_from_current', true); $this->settingsRepo->store('pilots.only_flights_from_current', true);
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'curr_airport_id' => 'KJFK', 'curr_airport_id' => 'KJFK',
]); ]);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create(); $aircraft = factory(Aircraft::class)->create();
/** /**
* INVALID AIRLINE_ID FIELD * INVALID AIRLINE_ID FIELD
@ -161,7 +174,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(400); $response->assertStatus(400);
$body = $response->json(); $body = $response->json();
$this->assertEquals(\App\Exceptions\UserNotAtAirport::MESSAGE, $body['error']['message']); $this->assertEquals(UserNotAtAirport::MESSAGE, $body['error']['message']);
} }
/** /**
@ -173,13 +186,13 @@ class AcarsTest extends TestCase
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'curr_airport_id' => 'KJFK', 'curr_airport_id' => 'KJFK',
]); ]);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = factory(App\Models\Aircraft::class)->create([ $aircraft = factory(Aircraft::class)->create([
'airport_id' => 'KAUS', 'airport_id' => 'KAUS',
]); ]);
@ -202,7 +215,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(400); $response->assertStatus(400);
$body = $response->json(); $body = $response->json();
$this->assertEquals(\App\Exceptions\AircraftNotAtAirport::MESSAGE, $body['error']['message']); $this->assertEquals(AircraftNotAtAirport::MESSAGE, $body['error']['message']);
} }
/** /**
@ -212,16 +225,16 @@ class AcarsTest extends TestCase
{ {
$subfleet = $this->createSubfleetWithAircraft(2); $subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$this->user = factory(App\Models\User::class)->create( $this->user = factory(User::class)->create(
[ [
'rank_id' => $rank->id, 'rank_id' => $rank->id,
] ]
); );
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random(); $aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
@ -312,12 +325,12 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2); $subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random(); $aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
@ -361,14 +374,14 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2); $subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create( $this->user = factory(User::class)->create(
[ [
'rank_id' => $rank->id, 'rank_id' => $rank->id,
] ]
); );
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random(); $aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
@ -438,7 +451,7 @@ class AcarsTest extends TestCase
$response->assertStatus(400); $response->assertStatus(400);
// Post an ACARS update // Post an ACARS update
$acars = factory(App\Models\Acars::class)->make(['pirep_id' => $pirep_id])->toArray(); $acars = factory(Acars::class)->make(['pirep_id' => $pirep_id])->toArray();
$acars = $this->transformData($acars); $acars = $this->transformData($acars);
@ -531,12 +544,12 @@ class AcarsTest extends TestCase
$subfleet = $this->createSubfleetWithAircraft(2); $subfleet = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$aircraft = $subfleet['aircraft']->random(); $aircraft = $subfleet['aircraft']->random();
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
@ -581,8 +594,8 @@ class AcarsTest extends TestCase
{ {
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', true);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(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); $subfleetA = $this->createSubfleetWithAircraft(1);
@ -592,7 +605,7 @@ class AcarsTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]); $rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create( $this->user = factory(User::class)->create(
[ [
'rank_id' => $rank->id, 'rank_id' => $rank->id,
] ]
@ -627,8 +640,8 @@ class AcarsTest extends TestCase
{ {
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(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); $subfleetA = $this->createSubfleetWithAircraft(1);
@ -638,7 +651,7 @@ class AcarsTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]); $rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$this->user = factory(App\Models\User::class)->create( $this->user = factory(User::class)->create(
[ [
'rank_id' => $rank->id, 'rank_id' => $rank->id,
] ]
@ -679,8 +692,8 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/'.$pirep_id.'/acars/position'; $uri = '/api/pireps/'.$pirep_id.'/acars/position';
// Post an ACARS update // Post an ACARS update
$acars_count = \random_int(5, 10); $acars_count = random_int(5, 10);
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id' => '']) $acars = factory(Acars::class, $acars_count)->make(['id' => ''])
->map(function ($point) { ->map(function ($point) {
$point['id'] = Utils::generateNewId(); $point['id'] = Utils::generateNewId();
return $point; return $point;
@ -701,7 +714,7 @@ class AcarsTest extends TestCase
public function testNonExistentPirepGet() public function testNonExistentPirepGet()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$uri = '/api/pireps/DOESNTEXIST/acars'; $uri = '/api/pireps/DOESNTEXIST/acars';
$response = $this->get($uri); $response = $this->get($uri);
@ -710,10 +723,10 @@ class AcarsTest extends TestCase
public function testNonExistentPirepStore() public function testNonExistentPirepStore()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$uri = '/api/pireps/DOESNTEXIST/acars/position'; $uri = '/api/pireps/DOESNTEXIST/acars/position';
$acars = factory(App\Models\Acars::class)->make()->toArray(); $acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, $acars); $response = $this->post($uri, $acars);
$response->assertStatus(404); $response->assertStatus(404);
} }
@ -728,7 +741,7 @@ class AcarsTest extends TestCase
$dt = date('c'); $dt = date('c');
$uri = '/api/pireps/'.$pirep_id.'/acars/position'; $uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make([ $acars = factory(Acars::class)->make([
'sim_time' => $dt, 'sim_time' => $dt,
])->toArray(); ])->toArray();
@ -777,7 +790,7 @@ class AcarsTest extends TestCase
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$pirep_id = $response->json()['data']['id']; $pirep_id = $response->json()['data']['id'];
$acars = factory(App\Models\Acars::class)->make(); $acars = factory(Acars::class)->make();
$post_log = [ $post_log = [
'logs' => [ 'logs' => [
['log' => $acars->log], ['log' => $acars->log],
@ -791,7 +804,7 @@ class AcarsTest extends TestCase
$this->assertEquals(1, $body['count']); $this->assertEquals(1, $body['count']);
$acars = factory(App\Models\Acars::class)->make(); $acars = factory(Acars::class)->make();
$post_log = [ $post_log = [
'events' => [ 'events' => [
['event' => $acars->log], ['event' => $acars->log],
@ -816,9 +829,9 @@ class AcarsTest extends TestCase
$order = 1; $order = 1;
$post_route = []; $post_route = [];
$route_count = \random_int(2, 10); $route_count = random_int(2, 10);
$route = factory(App\Models\Navdata::class, $route_count)->create(); $route = factory(Navdata::class, $route_count)->create();
foreach ($route as $position) { foreach ($route as $position) {
$post_route[] = [ $post_route[] = [
'order' => $order, 'order' => $order,

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Services\AirlineService; use App\Services\AirlineService;
class AirlineTest extends TestCase class AirlineTest extends TestCase
@ -17,7 +19,7 @@ class AirlineTest extends TestCase
public function testAddAirline() public function testAddAirline()
{ {
$attrs = factory(App\Models\Airline::class)->make([ $attrs = factory(\App\Models\Airline::class)->make([
'iata' => '', 'iata' => '',
])->toArray(); ])->toArray();
@ -25,7 +27,7 @@ class AirlineTest extends TestCase
$this->assertNotNull($airline); $this->assertNotNull($airline);
// Add another airline, also blank IATA // Add another airline, also blank IATA
$attrs = factory(App\Models\Airline::class)->make([ $attrs = factory(\App\Models\Airline::class)->make([
'iata' => '', 'iata' => '',
])->toArray(); ])->toArray();
$airline = $this->airlineSvc->createAirline($attrs); $airline = $this->airlineSvc->createAirline($attrs);
@ -37,8 +39,8 @@ class AirlineTest extends TestCase
*/ */
public function testDeleteAirlineWithFlight() public function testDeleteAirlineWithFlight()
{ {
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(\App\Models\Airline::class)->create();
factory(App\Models\Flight::class)->create([ factory(\App\Models\Flight::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
]); ]);
@ -50,8 +52,8 @@ class AirlineTest extends TestCase
*/ */
public function testDeleteAirlineWithPirep() public function testDeleteAirlineWithPirep()
{ {
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(\App\Models\Airline::class)->create();
factory(App\Models\Pirep::class)->create([ factory(\App\Models\Pirep::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
]); ]);

View File

@ -1,8 +1,19 @@
<?php <?php
namespace Tests;
//use Swagger\Serializer; //use Swagger\Serializer;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\UserState;
use App\Models\Fare;
use App\Models\News;
use App\Models\Subfleet;
use App\Models\User; use App\Models\User;
use App\Services\FareService; use App\Services\FareService;
use Exception;
use function random_int;
/** /**
* Test API calls and authentication, etc * Test API calls and authentication, etc
@ -64,11 +75,11 @@ class ApiTest extends TestCase
*/ */
public function testGetNews(): void public function testGetNews(): void
{ {
factory(App\Models\News::class)->create(); factory(News::class)->create();
$response = $this->get('/api/news')->json(); $response = $this->get('/api/news')->json();
$this->assertCount(1, $response['data']); $this->assertCount(1, $response['data']);
$this->assertTrue(array_key_exists('user', $response['data'][0])); $this->assertArrayHasKey('user', $response['data'][0]);
} }
/** /**
@ -76,12 +87,12 @@ class ApiTest extends TestCase
*/ */
public function testGetAirlines() public function testGetAirlines()
{ {
$size = \random_int(5, 10); $size = random_int(5, 10);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'airline_id' => 0, 'airline_id' => 0,
]); ]);
$airlines = factory(App\Models\Airline::class, $size)->create(); $airlines = factory(Airline::class, $size)->create();
$res = $this->get('/api/airlines'); $res = $this->get('/api/airlines');
$this->assertTrue($res->isOk()); $this->assertTrue($res->isOk());
@ -96,12 +107,12 @@ class ApiTest extends TestCase
*/ */
public function testPagination() public function testPagination()
{ {
$size = \random_int(5, 10); $size = random_int(5, 10);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'airline_id' => 0, 'airline_id' => 0,
]); ]);
factory(App\Models\Airline::class, $size)->create(); factory(Airline::class, $size)->create();
/* /*
* Page 0 and page 1 should return the same thing * Page 0 and page 1 should return the same thing
@ -142,8 +153,8 @@ class ApiTest extends TestCase
*/ */
public function testAirportRequest() public function testAirportRequest()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(Airport::class)->create();
$response = $this->get('/api/airports/'.$airport->icao); $response = $this->get('/api/airports/'.$airport->icao);
@ -158,8 +169,8 @@ class ApiTest extends TestCase
*/ */
public function testGetAllAirports() public function testGetAllAirports()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Airport::class, 70)->create(); factory(Airport::class, 70)->create();
$response = $this->get('/api/airports/') $response = $this->get('/api/airports/')
->assertStatus(200); ->assertStatus(200);
@ -170,9 +181,9 @@ class ApiTest extends TestCase
public function testGetAllAirportsHubs() public function testGetAllAirportsHubs()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Airport::class, 10)->create(); factory(Airport::class, 10)->create();
factory(App\Models\Airport::class)->create(['hub' => 1]); factory(Airport::class)->create(['hub' => 1]);
$this->get('/api/airports/hubs') $this->get('/api/airports/hubs')
->assertStatus(200) ->assertStatus(200)
@ -186,23 +197,23 @@ class ApiTest extends TestCase
*/ */
public function testGetSubfleets() public function testGetSubfleets()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$subfleetA = factory(App\Models\Subfleet::class)->create([ $subfleetA = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
$subfleetB = factory(App\Models\Subfleet::class)->create([ $subfleetB = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
$subfleetA_size = \random_int(2, 10); $subfleetA_size = random_int(2, 10);
$subfleetB_size = \random_int(2, 10); $subfleetB_size = random_int(2, 10);
factory(App\Models\Aircraft::class, $subfleetA_size)->create([ factory(Aircraft::class, $subfleetA_size)->create([
'subfleet_id' => $subfleetA->id, 'subfleet_id' => $subfleetA->id,
]); ]);
factory(App\Models\Aircraft::class, $subfleetB_size)->create([ factory(Aircraft::class, $subfleetB_size)->create([
'subfleet_id' => $subfleetB->id, 'subfleet_id' => $subfleetB->id,
]); ]);
@ -226,18 +237,18 @@ class ApiTest extends TestCase
*/ */
public function testGetAircraft() public function testGetAircraft()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$fare_svc = app(FareService::class); $fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create([ $subfleet = factory(Subfleet::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare); $fare_svc->setForSubfleet($subfleet, $fare);
$aircraft = factory(App\Models\Aircraft::class)->create([ $aircraft = factory(Aircraft::class)->create([
'subfleet_id' => $subfleet->id, 'subfleet_id' => $subfleet->id,
]); ]);
@ -259,14 +270,14 @@ class ApiTest extends TestCase
public function testGetAllSettings() public function testGetAllSettings()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$res = $this->get('/api/settings')->assertStatus(200); $res = $this->get('/api/settings')->assertStatus(200);
$settings = $res->json(); $settings = $res->json();
} }
public function testGetUser() public function testGetUser()
{ {
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'avatar' => '/assets/avatar.jpg', 'avatar' => '/assets/avatar.jpg',
]); ]);
@ -277,7 +288,7 @@ class ApiTest extends TestCase
// Should go to gravatar // Should go to gravatar
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$res = $this->get('/api/user')->assertStatus(200); $res = $this->get('/api/user')->assertStatus(200);
$user = $res->json('data'); $user = $res->json('data');

View File

@ -1,8 +1,14 @@
<?php <?php
namespace Tests;
use App\Models\Award;
use App\Models\Pirep;
use App\Models\User;
use App\Models\UserAward; use App\Models\UserAward;
use App\Services\AwardService; use App\Services\AwardService;
use App\Services\PirepService; use App\Services\PirepService;
use Modules\Awards\Awards\PilotFlightAwards;
class AwardsTest extends TestCase class AwardsTest extends TestCase
{ {
@ -35,16 +41,16 @@ class AwardsTest extends TestCase
public function testAwardsGiven() public function testAwardsGiven()
{ {
// Create one award that's given out with one flight // Create one award that's given out with one flight
$award = factory(App\Models\Award::class)->create([ $award = factory(Award::class)->create([
'ref_model' => Modules\Awards\Awards\PilotFlightAwards::class, 'ref_model' => PilotFlightAwards::class,
'ref_model_params' => 1, 'ref_model_params' => 1,
]); ]);
$user = factory(App\Models\User::class)->create([ $user = factory(User::class)->create([
'flights' => 0, 'flights' => 0,
]); ]);
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'airline_id' => $user->airline->id, 'airline_id' => $user->airline->id,
'user_id' => $user->id, 'user_id' => $user->id,
]); ]);

View File

@ -1,8 +1,11 @@
<?php <?php
namespace Tests;
use App\Exceptions\BidExistsForFlight; use App\Exceptions\BidExistsForFlight;
use App\Models\Bid; use App\Models\Bid;
use App\Models\Flight; use App\Models\Flight;
use App\Models\Subfleet;
use App\Models\User; use App\Models\User;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Services\BidService; use App\Services\BidService;
@ -26,12 +29,12 @@ class BidTest extends TestCase
public function addFlight($user) public function addFlight($user)
{ {
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
]); ]);
$flight->subfleets()->syncWithoutDetaching([ $flight->subfleets()->syncWithoutDetaching([
factory(App\Models\Subfleet::class)->create([ factory(Subfleet::class)->create([
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
])->id, ])->id,
]); ]);

View File

@ -27,6 +27,7 @@ class Bootstrap implements BeforeFirstTestHook, AfterLastTestHook
'config:cache', 'config:cache',
'event:cache', 'event:cache',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {
$console->call($command); $console->call($command);
} }

View File

@ -1,9 +1,19 @@
<?php <?php
namespace Tests;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\ExpenseType; use App\Models\Enums\ExpenseType;
use App\Models\Enums\FlightType; use App\Models\Enums\FlightType;
use App\Models\Enums\PirepSource;
use App\Models\Expense; use App\Models\Expense;
use App\Models\Fare;
use App\Models\Flight;
use App\Models\Journal;
use App\Models\Pirep;
use App\Models\Subfleet; use App\Models\Subfleet;
use App\Models\User;
use App\Repositories\ExpenseRepository; use App\Repositories\ExpenseRepository;
use App\Repositories\JournalRepository; use App\Repositories\JournalRepository;
use App\Services\FareService; use App\Services\FareService;
@ -12,6 +22,7 @@ use App\Services\FleetService;
use App\Services\PirepService; use App\Services\PirepService;
use App\Support\Math; use App\Support\Math;
use App\Support\Money; use App\Support\Money;
use Exception;
class FinanceTest extends TestCase class FinanceTest extends TestCase
{ {
@ -60,27 +71,29 @@ class FinanceTest extends TestCase
$this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank); $this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank);
$dpt_apt = factory(App\Models\Airport::class)->create([ $dpt_apt = factory(Airport::class)->create([
'ground_handling_cost' => 10, 'ground_handling_cost' => 10,
'fuel_jeta_cost' => 10, 'fuel_jeta_cost' => 10,
]); ]);
$arr_apt = factory(App\Models\Airport::class)->create([ $arr_apt = factory(Airport::class)->create([
'ground_handling_cost' => 10, 'ground_handling_cost' => 10,
'fuel_jeta_cost' => 10, 'fuel_jeta_cost' => 10,
]); ]);
$user = factory(App\Models\User::class)->create([ /** @var \App\Models\User $user */
$user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$flight = factory(App\Models\Flight::class)->create([ /** @var \App\Models\Flight $flight */
$flight = factory(Flight::class)->create([
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
'dpt_airport_id' => $dpt_apt->icao, 'dpt_airport_id' => $dpt_apt->icao,
'arr_airport_id' => $arr_apt->icao, 'arr_airport_id' => $arr_apt->icao,
]); ]);
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'flight_number' => $flight->flight_number, 'flight_number' => $flight->flight_number,
'flight_type' => FlightType::SCHED_PAX, 'flight_type' => FlightType::SCHED_PAX,
'route_code' => $flight->route_code, 'route_code' => $flight->route_code,
@ -101,7 +114,7 @@ class FinanceTest extends TestCase
* Add fares to the subfleet, and then add the fares * Add fares to the subfleet, and then add the fares
* to the PIREP when it's saved, and set the capacity * to the PIREP when it's saved, and set the capacity
*/ */
$fares = factory(App\Models\Fare::class, 3)->create([ $fares = factory(Fare::class, 3)->create([
'price' => 100, 'price' => 100,
'cost' => 50, 'cost' => 50,
'capacity' => 10, 'capacity' => 10,
@ -112,13 +125,13 @@ class FinanceTest extends TestCase
} }
// Add an expense // Add an expense
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => null, 'airline_id' => null,
'amount' => 100, 'amount' => 100,
]); ]);
// Add a subfleet expense // Add a subfleet expense
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'ref_model' => Subfleet::class, 'ref_model' => Subfleet::class,
'ref_model_id' => $subfleet['subfleet']->id, 'ref_model_id' => $subfleet['subfleet']->id,
'amount' => 200, 'amount' => 200,
@ -131,8 +144,8 @@ class FinanceTest extends TestCase
public function testFlightFaresNoOverride() public function testFlightFaresNoOverride()
{ {
$flight = factory(App\Models\Flight::class)->create(); $flight = factory(Flight::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$this->fareSvc->setForFlight($flight, $fare); $this->fareSvc->setForFlight($flight, $fare);
$subfleet_fares = $this->fareSvc->getForFlight($flight); $subfleet_fares = $this->fareSvc->getForFlight($flight);
@ -165,8 +178,8 @@ class FinanceTest extends TestCase
*/ */
public function testFlightFareOverrideAsPercent() public function testFlightFareOverrideAsPercent()
{ {
$flight = factory(App\Models\Flight::class)->create(); $flight = factory(Flight::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$percent_incr = '20%'; $percent_incr = '20%';
$percent_decr = '-20%'; $percent_decr = '-20%';
@ -192,8 +205,8 @@ class FinanceTest extends TestCase
public function testSubfleetFaresNoOverride() public function testSubfleetFaresNoOverride()
{ {
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$this->fareSvc->setForSubfleet($subfleet, $fare); $this->fareSvc->setForSubfleet($subfleet, $fare);
$subfleet_fares = $this->fareSvc->getForSubfleet($subfleet); $subfleet_fares = $this->fareSvc->getForSubfleet($subfleet);
@ -223,8 +236,8 @@ class FinanceTest extends TestCase
public function testSubfleetFaresOverride() public function testSubfleetFaresOverride()
{ {
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$this->fareSvc->setForSubfleet($subfleet, $fare, [ $this->fareSvc->setForSubfleet($subfleet, $fare, [
'price' => 50, 'capacity' => 400, 'price' => 50, 'capacity' => 400,
@ -260,8 +273,8 @@ class FinanceTest extends TestCase
*/ */
public function testSubfleetFareOverrideAsPercent() public function testSubfleetFareOverrideAsPercent()
{ {
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$percent_incr = '20%'; $percent_incr = '20%';
$percent_decr = '-20%'; $percent_decr = '-20%';
@ -291,9 +304,9 @@ class FinanceTest extends TestCase
*/ */
public function testGetFaresWithOverrides() public function testGetFaresWithOverrides()
{ {
$flight = factory(App\Models\Flight::class)->create(); $flight = factory(Flight::class)->create();
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
[$fare1, $fare2, $fare3, $fare4] = factory(App\Models\Fare::class, 4)->create(); [$fare1, $fare2, $fare3, $fare4] = factory(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, $fare1);
@ -345,8 +358,8 @@ class FinanceTest extends TestCase
public function testGetFaresNoFlightOverrides() public function testGetFaresNoFlightOverrides()
{ {
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
[$fare1, $fare2, $fare3] = factory(App\Models\Fare::class, 3)->create(); [$fare1, $fare2, $fare3] = factory(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, $fare1);
@ -393,11 +406,11 @@ class FinanceTest extends TestCase
$rank = $this->createRank(10, [$subfleet['subfleet']->id]); $rank = $this->createRank(10, [$subfleet['subfleet']->id]);
$this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank); $this->fleetSvc->addSubfleetToRank($subfleet['subfleet'], $rank);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -420,11 +433,11 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate, 'acars_pay' => $acars_pay_rate,
]); ]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$pirep_acars = factory(App\Models\Pirep::class)->create([ $pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -444,7 +457,7 @@ class FinanceTest extends TestCase
'manual_pay' => $manual_pay_rate, 'manual_pay' => $manual_pay_rate,
]); ]);
$pirep_manual = factory(App\Models\Pirep::class)->create([ $pirep_manual = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::MANUAL, 'source' => PirepSource::MANUAL,
@ -471,11 +484,11 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate, 'acars_pay' => $acars_pay_rate,
]); ]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$pirep_acars = factory(App\Models\Pirep::class)->create([ $pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -485,7 +498,7 @@ class FinanceTest extends TestCase
$payment = $this->financeSvc->getPilotPay($pirep_acars); $payment = $this->financeSvc->getPilotPay($pirep_acars);
$this->assertEquals(100, $payment->getValue()); $this->assertEquals(100, $payment->getValue());
$pirep_acars = factory(App\Models\Pirep::class)->create([ $pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -506,16 +519,16 @@ class FinanceTest extends TestCase
'acars_pay' => $acars_pay_rate, 'acars_pay' => $acars_pay_rate,
]); ]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
'pilot_pay' => 1000, 'pilot_pay' => 1000,
]); ]);
$pirep_acars = factory(App\Models\Pirep::class)->create([ $pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -526,7 +539,7 @@ class FinanceTest extends TestCase
$payment = $this->financeSvc->getPilotPay($pirep_acars); $payment = $this->financeSvc->getPilotPay($pirep_acars);
$this->assertEquals(1000, $payment->getValue()); $this->assertEquals(1000, $payment->getValue());
$pirep_acars = factory(App\Models\Pirep::class)->create([ $pirep_acars = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'aircraft_id' => $subfleet['aircraft']->random(), 'aircraft_id' => $subfleet['aircraft']->random(),
'source' => PirepSource::ACARS, 'source' => PirepSource::ACARS,
@ -544,8 +557,8 @@ class FinanceTest extends TestCase
{ {
$journalRepo = app(JournalRepository::class); $journalRepo = app(JournalRepository::class);
$user = factory(App\Models\User::class)->create(); $user = factory(User::class)->create();
$journal = factory(App\Models\Journal::class)->create(); $journal = factory(Journal::class)->create();
$journalRepo->post( $journalRepo->post(
$journal, $journal,
@ -624,18 +637,18 @@ class FinanceTest extends TestCase
*/ */
public function testPirepExpenses() public function testPirepExpenses()
{ {
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$airline2 = factory(App\Models\Airline::class)->create(); $airline2 = factory(Airline::class)->create();
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
]); ]);
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => $airline2->id, 'airline_id' => $airline2->id,
]); ]);
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => null, 'airline_id' => null,
]); ]);
@ -660,8 +673,8 @@ class FinanceTest extends TestCase
* Test the subfleet class * Test the subfleet class
*/ */
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => null, 'airline_id' => null,
'ref_model' => Subfleet::class, 'ref_model' => Subfleet::class,
'ref_model_id' => $subfleet->id, 'ref_model_id' => $subfleet->id,
@ -737,7 +750,7 @@ class FinanceTest extends TestCase
$journalRepo = app(JournalRepository::class); $journalRepo = app(JournalRepository::class);
// Add an expense that's only for a cargo flight // Add an expense that's only for a cargo flight
factory(App\Models\Expense::class)->create([ factory(Expense::class)->create([
'airline_id' => null, 'airline_id' => null,
'amount' => 100, 'amount' => 100,
'flight_type' => FlightType::SCHED_CARGO, 'flight_type' => FlightType::SCHED_CARGO,
@ -784,7 +797,7 @@ class FinanceTest extends TestCase
} }
// Add a new PIREP; // Add a new PIREP;
$pirep2 = factory(App\Models\Pirep::class)->create([ $pirep2 = factory(Pirep::class)->create([
'flight_number' => 100, 'flight_number' => 100,
'flight_type' => FlightType::SCHED_CARGO, 'flight_type' => FlightType::SCHED_CARGO,
'dpt_airport_id' => $pirep->dpt_airport_id, 'dpt_airport_id' => $pirep->dpt_airport_id,

View File

@ -1,14 +1,23 @@
<?php <?php
namespace Tests;
use App\Cron\Nightly\SetActiveFlights; use App\Cron\Nightly\SetActiveFlights;
use App\Events\CronNightly; use App\Events\CronNightly;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Enums\Days; use App\Models\Enums\Days;
use App\Models\Enums\NavaidType; use App\Models\Enums\NavaidType;
use App\Models\Flight; use App\Models\Flight;
use App\Models\Navdata;
use App\Models\Subfleet;
use App\Models\User; use App\Models\User;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Services\AirportService; use App\Services\AirportService;
use App\Services\FleetService;
use App\Services\FlightService; use App\Services\FlightService;
use Carbon\Carbon;
use Exception;
class FlightTest extends TestCase class FlightTest extends TestCase
{ {
@ -38,10 +47,10 @@ class FlightTest extends TestCase
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
], $flight_properties); ], $flight_properties);
$flight = factory(App\Models\Flight::class)->create($opts); $flight = factory(Flight::class)->create($opts);
$flight->subfleets()->syncWithoutDetaching([ $flight->subfleets()->syncWithoutDetaching([
factory(App\Models\Subfleet::class)->create([ factory(Subfleet::class)->create([
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
])->id, ])->id,
]); ]);
@ -59,7 +68,7 @@ class FlightTest extends TestCase
*/ */
public function addFlightsForSubfleet($subfleet, $num_flights) public function addFlightsForSubfleet($subfleet, $num_flights)
{ {
return factory(App\Models\Flight::class, $num_flights)->create([ return factory(Flight::class, $num_flights)->create([
'airline_id' => $subfleet->airline->id, 'airline_id' => $subfleet->airline->id,
])->each(function (Flight $f) use ($subfleet) { ])->each(function (Flight $f) use ($subfleet) {
$f->subfleets()->syncWithoutDetaching([ $f->subfleets()->syncWithoutDetaching([
@ -73,7 +82,7 @@ class FlightTest extends TestCase
*/ */
public function testDuplicateFlight() public function testDuplicateFlight()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user); $flight = $this->addFlight($this->user);
// first flight shouldn't be a duplicate // first flight shouldn't be a duplicate
@ -89,7 +98,7 @@ class FlightTest extends TestCase
$this->assertTrue($this->flightSvc->isFlightDuplicate($flight_dupe)); $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(); $new_airline = factory(Airline::class)->create();
$flight_dupe = new Flight([ $flight_dupe = new Flight([
'airline_id' => $new_airline->airline_id, 'airline_id' => $new_airline->airline_id,
'flight_number' => $flight->flight_number, 'flight_number' => $flight->flight_number,
@ -100,7 +109,7 @@ class FlightTest extends TestCase
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_dupe)); $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([ $flight_leg = factory(Flight::class)->create([
'airline_id' => $flight->airline_id, 'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number, 'flight_number' => $flight->flight_number,
'route_code' => 'A', 'route_code' => 'A',
@ -109,7 +118,7 @@ class FlightTest extends TestCase
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg)); $this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));
// Add both a route and leg // Add both a route and leg
$flight_leg = factory(App\Models\Flight::class)->create([ $flight_leg = factory(Flight::class)->create([
'airline_id' => $flight->airline_id, 'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number, 'flight_number' => $flight->flight_number,
'route_code' => 'A', 'route_code' => 'A',
@ -121,7 +130,7 @@ class FlightTest extends TestCase
public function testGetFlight() public function testGetFlight()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user, [ $flight = $this->addFlight($this->user, [
'load_factor' => '', 'load_factor' => '',
'load_factor_variance' => '', 'load_factor_variance' => '',
@ -148,7 +157,7 @@ class FlightTest extends TestCase
*/ */
public function testSearchFlight() public function testSearchFlight()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user); $flight = $this->addFlight($this->user);
// search specifically for a flight ID // search specifically for a flight ID
@ -157,6 +166,29 @@ class FlightTest extends TestCase
$req->assertStatus(200); $req->assertStatus(200);
} }
public function testSearchFlightInactiveAirline()
{
/** @var \App\Models\Airline $airline_inactive */
$airline_inactive = factory(Airline::class)->create(['active' => 0]);
/** @var \App\Models\Airline $airline_active */
$airline_active = factory(Airline::class)->create(['active' => 1]);
$this->user = factory(User::class)->create([
'airline_id' => $airline_inactive->id,
]);
$this->addFlight($this->user, ['airline_id' => $airline_inactive->id]);
$this->addFlight($this->user, ['airline_id' => $airline_active->id]);
// search specifically for a flight ID
$req = $this->get('/api/flights/search?ignore_restrictions=1');
$req->assertStatus(200);
$body = $req->json('data');
$this->assertEquals(1, count($body));
$this->assertEquals($airline_active->id, $body[0]['airline_id']);
}
/** /**
* Get the flight's route * Get the flight's route
* *
@ -164,11 +196,11 @@ class FlightTest extends TestCase
*/ */
public function testFlightRoute() public function testFlightRoute()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flight = $this->addFlight($this->user); $flight = $this->addFlight($this->user);
$route_count = random_int(4, 6); $route_count = random_int(4, 6);
$route = factory(App\Models\Navdata::class, $route_count)->create(); $route = factory(Navdata::class, $route_count)->create();
$route_text = implode(' ', $route->pluck('id')->toArray()); $route_text = implode(' ', $route->pluck('id')->toArray());
$flight->route = $route_text; $flight->route = $route_text;
@ -198,8 +230,8 @@ class FlightTest extends TestCase
*/ */
public function testFindAllFlights() public function testFindAllFlights()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Flight::class, 20)->create([ factory(Flight::class, 20)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
@ -217,12 +249,12 @@ class FlightTest extends TestCase
*/ */
public function testSearchFlightBySubfleet() public function testSearchFlightBySubfleet()
{ {
$airline = factory(App\Models\Airline::class)->create(); $airline = factory(Airline::class)->create();
$subfleetA = factory(App\Models\Subfleet::class)->create(['airline_id' => $airline->id]); $subfleetA = factory(Subfleet::class)->create(['airline_id' => $airline->id]);
$subfleetB = factory(App\Models\Subfleet::class)->create(['airline_id' => $airline->id]); $subfleetB = factory(Subfleet::class)->create(['airline_id' => $airline->id]);
$rank = $this->createRank(0, [$subfleetB->id]); $rank = $this->createRank(0, [$subfleetB->id]);
$this->user = factory(App\Models\User::class)->create([ $this->user = factory(User::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
@ -250,12 +282,12 @@ class FlightTest extends TestCase
*/ */
public function testFindDaysOfWeek(): void public function testFindDaysOfWeek(): void
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Flight::class, 20)->create([ factory(Flight::class, 20)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
$saved_flight = factory(App\Models\Flight::class)->create([ $saved_flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
'days' => Days::getDaysMask([ 'days' => Days::getDaysMask([
Days::SUNDAY, Days::SUNDAY,
@ -283,7 +315,7 @@ class FlightTest extends TestCase
*/ */
public function testDayOfWeekActive(): void public function testDayOfWeekActive(): void
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
// Set it to Monday or Tuesday, depending on what today is // Set it to Monday or Tuesday, depending on what today is
if (date('N') === '1') { // today is a monday if (date('N') === '1') { // today is a monday
@ -292,8 +324,8 @@ class FlightTest extends TestCase
$days = Days::getDaysMask([Days::MONDAY]); $days = Days::getDaysMask([Days::MONDAY]);
} }
factory(App\Models\Flight::class, 5)->create(); factory(Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'days' => $days, 'days' => $days,
]); ]);
@ -331,17 +363,17 @@ class FlightTest extends TestCase
public function testStartEndDate(): void public function testStartEndDate(): void
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Flight::class, 5)->create(); factory(Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1), 'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1), 'end_date' => Carbon::now('UTC')->addDays(1),
]); ]);
$flight_not_active = factory(App\Models\Flight::class)->create([ $flight_not_active = factory(Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(10), 'start_date' => Carbon::now('UTC')->subDays(10),
'end_date' => Carbon\Carbon::now('UTC')->subDays(2), 'end_date' => Carbon::now('UTC')->subDays(2),
]); ]);
// Run the event that will enable/disable flights // Run the event that will enable/disable flights
@ -360,7 +392,7 @@ class FlightTest extends TestCase
public function testStartEndDateDayOfWeek(): void public function testStartEndDateDayOfWeek(): void
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
// Set it to Monday or Tuesday, depending on what today is // Set it to Monday or Tuesday, depending on what today is
if (date('N') === '1') { // today is a monday if (date('N') === '1') { // today is a monday
@ -369,17 +401,17 @@ class FlightTest extends TestCase
$days = Days::getDaysMask([Days::MONDAY]); $days = Days::getDaysMask([Days::MONDAY]);
} }
factory(App\Models\Flight::class, 5)->create(); factory(Flight::class, 5)->create();
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1), 'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1), 'end_date' => Carbon::now('UTC')->addDays(1),
'days' => Days::$isoDayMap[date('N')], 'days' => Days::$isoDayMap[date('N')],
]); ]);
// Not active because of days of week not today // Not active because of days of week not today
$flight_not_active = factory(App\Models\Flight::class)->create([ $flight_not_active = factory(Flight::class)->create([
'start_date' => Carbon\Carbon::now('UTC')->subDays(1), 'start_date' => Carbon::now('UTC')->subDays(1),
'end_date' => Carbon\Carbon::now('UTC')->addDays(1), 'end_date' => Carbon::now('UTC')->addDays(1),
'days' => $days, 'days' => $days,
]); ]);
@ -399,8 +431,8 @@ class FlightTest extends TestCase
public function testFlightSearchApi() public function testFlightSearchApi()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flights = factory(App\Models\Flight::class, 10)->create([ $flights = factory(Flight::class, 10)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
@ -415,12 +447,12 @@ class FlightTest extends TestCase
public function testFlightSearchApiDepartureAirport() public function testFlightSearchApiDepartureAirport()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
factory(App\Models\Flight::class, 10)->create([ factory(Flight::class, 10)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
'dpt_airport_id' => 'KAUS', 'dpt_airport_id' => 'KAUS',
]); ]);
@ -436,8 +468,8 @@ class FlightTest extends TestCase
public function testFlightSearchApiDistance() public function testFlightSearchApiDistance()
{ {
$total_flights = 10; $total_flights = 10;
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$flights = factory(App\Models\Flight::class, $total_flights)->create([ $flights = factory(Flight::class, $total_flights)->create([
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
]); ]);
@ -474,10 +506,10 @@ class FlightTest extends TestCase
public function testAddSubfleet() public function testAddSubfleet()
{ {
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$flight = factory(App\Models\Flight::class)->create(); $flight = factory(Flight::class)->create();
$fleetSvc = app(App\Services\FleetService::class); $fleetSvc = app(FleetService::class);
$fleetSvc->addSubfleetToFlight($subfleet, $flight); $fleetSvc->addSubfleetToFlight($subfleet, $flight);
$flight->refresh(); $flight->refresh();
@ -508,13 +540,13 @@ class FlightTest extends TestCase
public function testAirportDistance() public function testAirportDistance()
{ {
// KJFK // KJFK
$fromIcao = factory(App\Models\Airport::class)->create([ $fromIcao = factory(Airport::class)->create([
'lat' => 40.6399257, 'lat' => 40.6399257,
'lon' => -73.7786950, 'lon' => -73.7786950,
]); ]);
// KSFO // KSFO
$toIcao = factory(App\Models\Airport::class)->create([ $toIcao = factory(Airport::class)->create([
'lat' => 37.6188056, 'lat' => 37.6188056,
'lon' => -122.3754167, 'lon' => -122.3754167,
]); ]);
@ -531,13 +563,13 @@ class FlightTest extends TestCase
$headers = $this->headers($user); $headers = $this->headers($user);
// KJFK // KJFK
$fromIcao = factory(App\Models\Airport::class)->create([ $fromIcao = factory(Airport::class)->create([
'lat' => 40.6399257, 'lat' => 40.6399257,
'lon' => -73.7786950, 'lon' => -73.7786950,
]); ]);
// KSFO // KSFO
$toIcao = factory(App\Models\Airport::class)->create([ $toIcao = factory(Airport::class)->create([
'lat' => 37.6188056, 'lat' => 37.6188056,
'lon' => -122.3754167, 'lon' => -122.3754167,
]); ]);

View File

@ -1,5 +1,9 @@
<?php <?php
namespace Tests;
use App\Models\Navdata;
use Exception;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
class GeoTest extends TestCase class GeoTest extends TestCase
@ -44,7 +48,7 @@ class GeoTest extends TestCase
$route = []; $route = [];
$nav_count = random_int(5, 20); $nav_count = random_int(5, 20);
$navpoints = factory(App\Models\Navdata::class, $nav_count)->create(); $navpoints = factory(Navdata::class, $nav_count)->create();
foreach ($navpoints as $point) { foreach ($navpoints as $point) {
$route[] = $point->id; $route[] = $point->id;
} }

View File

@ -1,7 +1,10 @@
<?php <?php
namespace Tests;
use App\Contracts\ImportExport; use App\Contracts\ImportExport;
use App\Models\Aircraft; use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport; use App\Models\Airport;
use App\Models\Enums\AircraftStatus; use App\Models\Enums\AircraftStatus;
use App\Models\Enums\Days; use App\Models\Enums\Days;
@ -18,6 +21,7 @@ use App\Services\ImportExport\AircraftExporter;
use App\Services\ImportExport\AirportExporter; use App\Services\ImportExport\AirportExporter;
use App\Services\ImportExport\FlightExporter; use App\Services\ImportExport\FlightExporter;
use App\Services\ImportService; use App\Services\ImportService;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class ImporterTest extends TestCase class ImporterTest extends TestCase
@ -50,18 +54,18 @@ class ImporterTest extends TestCase
'name' => 'phpVMS Airlines', 'name' => 'phpVMS Airlines',
]; ];
$airline = factory(App\Models\Airline::class)->create($al); $airline = factory(Airline::class)->create($al);
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']); $subfleet = factory(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_economy = factory(Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_svc->setForSubfleet($subfleet, $fare_economy); $fare_svc->setForSubfleet($subfleet, $fare_economy);
$fare_business = factory(App\Models\Fare::class)->create(['code' => 'B', 'capacity' => 20]); $fare_business = factory(Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$fare_svc->setForSubfleet($subfleet, $fare_business); $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_first = factory(Fare::class)->create(['code' => 'F', 'capacity' => 10]);
$fare_svc->setForSubfleet($subfleet, $fare_first); $fare_svc->setForSubfleet($subfleet, $fare_first);
return [$airline, $subfleet]; return [$airline, $subfleet];
@ -247,7 +251,7 @@ class ImporterTest extends TestCase
*/ */
public function testAircraftExporter(): void public function testAircraftExporter(): void
{ {
$aircraft = factory(App\Models\Aircraft::class)->create(); $aircraft = factory(Aircraft::class)->create();
$exporter = new AircraftExporter(); $exporter = new AircraftExporter();
$exported = $exporter->export($aircraft); $exported = $exporter->export($aircraft);
@ -273,7 +277,7 @@ class ImporterTest extends TestCase
{ {
$airport_name = 'Adolfo Suárez MadridBarajas Airport'; $airport_name = 'Adolfo Suárez MadridBarajas Airport';
$airport = factory(App\Models\Airport::class)->create([ $airport = factory(Airport::class)->create([
'name' => $airport_name, 'name' => $airport_name,
]); ]);
@ -301,12 +305,12 @@ class ImporterTest extends TestCase
$fareSvc = app(FareService::class); $fareSvc = app(FareService::class);
[$airline, $subfleet] = $this->insertFlightsScaffoldData(); [$airline, $subfleet] = $this->insertFlightsScaffoldData();
$subfleet2 = factory(App\Models\Subfleet::class)->create(['type' => 'B74X']); $subfleet2 = factory(Subfleet::class)->create(['type' => 'B74X']);
$fareY = Fare::where('code', 'Y')->first(); $fareY = Fare::where('code', 'Y')->first();
$fareF = Fare::where('code', 'F')->first(); $fareF = Fare::where('code', 'F')->first();
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'airline_id' => $airline->id, 'airline_id' => $airline->id,
'flight_type' => 'J', 'flight_type' => 'J',
'days' => Days::getDaysMask([ 'days' => Days::getDaysMask([
@ -384,9 +388,9 @@ class ImporterTest extends TestCase
*/ */
public function testExpenseImporter(): void public function testExpenseImporter(): void
{ {
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']); $airline = factory(Airline::class)->create(['icao' => 'VMS']);
$subfleet = factory(App\Models\Subfleet::class)->create(['type' => '744-3X-RB211']); $subfleet = factory(Subfleet::class)->create(['type' => '744-3X-RB211']);
$aircraft = factory(App\Models\Aircraft::class)->create([ $aircraft = factory(Aircraft::class)->create([
'subfleet_id' => $subfleet->id, 'subfleet_id' => $subfleet->id,
'registration' => '001Z', 'registration' => '001Z',
]); ]);
@ -564,8 +568,8 @@ class ImporterTest extends TestCase
*/ */
public function testAircraftImporter(): void public function testAircraftImporter(): void
{ {
factory(App\Models\Airline::class)->create(); factory(Airline::class)->create();
// $subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']); // $subfleet = factory(\App\Models\Subfleet::class)->create(['type' => 'A32X']);
$file_path = base_path('tests/data/aircraft.csv'); $file_path = base_path('tests/data/aircraft.csv');
$status = $this->importSvc->importAircraft($file_path); $status = $this->importSvc->importAircraft($file_path);
@ -646,9 +650,9 @@ class ImporterTest extends TestCase
*/ */
public function testSubfleetImporter(): void public function testSubfleetImporter(): void
{ {
$fare_economy = factory(App\Models\Fare::class)->create(['code' => 'Y', 'capacity' => 150]); $fare_economy = factory(Fare::class)->create(['code' => 'Y', 'capacity' => 150]);
$fare_business = factory(App\Models\Fare::class)->create(['code' => 'B', 'capacity' => 20]); $fare_business = factory(Fare::class)->create(['code' => 'B', 'capacity' => 20]);
$airline = factory(App\Models\Airline::class)->create(['icao' => 'VMS']); $airline = factory(Airline::class)->create(['icao' => 'VMS']);
$file_path = base_path('tests/data/subfleets.csv'); $file_path = base_path('tests/data/subfleets.csv');
$status = $this->importSvc->importSubfleets($file_path); $status = $this->importSvc->importSubfleets($file_path);

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Support\Math; use App\Support\Math;
use App\Support\Units\Distance; use App\Support\Units\Distance;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Services\AirportService; use App\Services\AirportService;
use App\Support\Metar; use App\Support\Metar;
@ -9,6 +11,7 @@ use App\Support\Metar;
*/ */
class MetarTest extends TestCase class MetarTest extends TestCase
{ {
/** @var SettingRepository */
private $settingsRepo; private $settingsRepo;
public function setUp(): void public function setUp(): void

View File

@ -1,11 +1,15 @@
<?php <?php
namespace Tests;
use App\Models\Acars; use App\Models\Acars;
use App\Models\Aircraft; use App\Models\Aircraft;
use App\Models\Bid; use App\Models\Bid;
use App\Models\Enums\AcarsType; use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepState; use App\Models\Enums\PirepState;
use App\Models\Enums\UserState; use App\Models\Enums\UserState;
use App\Models\Flight;
use App\Models\Navdata;
use App\Models\Pirep; use App\Models\Pirep;
use App\Models\User; use App\Models\User;
use App\Notifications\Messages\PirepAccepted; use App\Notifications\Messages\PirepAccepted;
@ -38,7 +42,7 @@ class PIREPTest extends TestCase
protected function createNewRoute() protected function createNewRoute()
{ {
$route = []; $route = [];
$navpoints = factory(App\Models\Navdata::class, 5)->create(); $navpoints = factory(Navdata::class, 5)->create();
foreach ($navpoints as $point) { foreach ($navpoints as $point) {
$route[] = $point->id; $route[] = $point->id;
} }
@ -65,10 +69,10 @@ class PIREPTest extends TestCase
*/ */
public function testAddPirep() public function testAddPirep()
{ {
$user = factory(App\Models\User::class)->create(); $user = factory(User::class)->create();
$route = $this->createNewRoute(); $route = $this->createNewRoute();
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'route' => implode(' ', $route), 'route' => implode(' ', $route),
]); ]);
@ -171,18 +175,18 @@ class PIREPTest extends TestCase
public function testGetUserPireps() public function testGetUserPireps()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$pirep_done = factory(App\Models\Pirep::class)->create([ $pirep_done = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'state' => PirepState::ACCEPTED, 'state' => PirepState::ACCEPTED,
]); ]);
$pirep_in_progress = factory(App\Models\Pirep::class)->create([ $pirep_in_progress = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'state' => PirepState::IN_PROGRESS, 'state' => PirepState::IN_PROGRESS,
]); ]);
$pirep_cancelled = factory(App\Models\Pirep::class)->create([ $pirep_cancelled = factory(Pirep::class)->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'state' => PirepState::CANCELLED, 'state' => PirepState::CANCELLED,
]); ]);
@ -360,7 +364,7 @@ class PIREPTest extends TestCase
*/ */
public function testDuplicatePireps() public function testDuplicatePireps()
{ {
$user = factory(App\Models\User::class)->create(); $user = factory(User::class)->create();
$pirep = factory(Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
]); ]);
@ -392,7 +396,7 @@ class PIREPTest extends TestCase
$pirep_id = $response->json()['data']['id']; $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(); $acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, [ $response = $this->post($uri, [
'positions' => [$acars], 'positions' => [$acars],
]); ]);
@ -406,7 +410,7 @@ class PIREPTest extends TestCase
// Should get a 400 when posting an ACARS update // Should get a 400 when posting an ACARS update
$uri = '/api/pireps/'.$pirep_id.'/acars/position'; $uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make()->toArray(); $acars = factory(Acars::class)->make()->toArray();
$response = $this->post($uri, $acars); $response = $this->post($uri, $acars);
$response->assertStatus(400); $response->assertStatus(400);
@ -421,18 +425,18 @@ class PIREPTest extends TestCase
$flightSvc = app(FlightService::class); $flightSvc = app(FlightService::class);
$this->settingsRepo->store('pireps.remove_bid_on_accept', true); $this->settingsRepo->store('pireps.remove_bid_on_accept', true);
$user = factory(App\Models\User::class)->create([ $user = factory(User::class)->create([
'flight_time' => 0, 'flight_time' => 0,
]); ]);
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'route_code' => null, 'route_code' => null,
'route_leg' => null, 'route_leg' => null,
]); ]);
$bidSvc->addBid($flight, $user); $bidSvc->addBid($flight, $user);
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'airline_id' => $flight->airline_id, 'airline_id' => $flight->airline_id,
'flight_id' => $flight->id, 'flight_id' => $flight->id,

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Events\UserRegistered; use App\Events\UserRegistered;
use App\Models\Enums\UserState; use App\Models\Enums\UserState;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
@ -11,7 +13,7 @@ class RegistrationTest extends TestCase
/** /**
* A basic test example. * A basic test example.
* *
* @throws Exception * @throws \Exception
* *
* @return void * @return void
*/ */
@ -24,7 +26,7 @@ class RegistrationTest extends TestCase
setting('pilots.auto_accept', true); setting('pilots.auto_accept', true);
$attrs = factory(App\Models\User::class)->make()->toArray(); $attrs = factory(\App\Models\User::class)->make()->toArray();
$attrs['password'] = Hash::make('secret'); $attrs['password'] = Hash::make('secret');
$user = $userSvc->createUser($attrs); $user = $userSvc->createUser($attrs);

View File

@ -1,8 +1,13 @@
<?php <?php
namespace Tests;
use App\Models\Acars; use App\Models\Acars;
use App\Models\Enums\AcarsType; use App\Models\Enums\AcarsType;
use App\Models\Flight;
use App\Models\Pirep;
use App\Models\SimBrief; use App\Models\SimBrief;
use App\Models\User;
use App\Services\SimBriefService; use App\Services\SimBriefService;
use App\Support\Utils; use App\Support\Utils;
use Carbon\Carbon; use Carbon\Carbon;
@ -20,7 +25,7 @@ class SimBriefTest extends TestCase
*/ */
protected function loadSimBrief($user): SimBrief protected function loadSimBrief($user): SimBrief
{ {
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(Flight::class)->create([
'id' => self::$simbrief_flight_id, 'id' => self::$simbrief_flight_id,
'dpt_airport_id' => 'OMAA', 'dpt_airport_id' => 'OMAA',
'arr_airport_id' => 'OMDB', 'arr_airport_id' => 'OMDB',
@ -42,7 +47,7 @@ class SimBriefTest extends TestCase
*/ */
public function testReadSimbrief() public function testReadSimbrief()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$briefing = $this->loadSimBrief($this->user); $briefing = $this->loadSimBrief($this->user);
$this->assertNotEmpty($briefing->ofp_xml); $this->assertNotEmpty($briefing->ofp_xml);
@ -81,7 +86,7 @@ class SimBriefTest extends TestCase
*/ */
public function testApiCalls() public function testApiCalls()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$briefing = $this->loadSimBrief($this->user); $briefing = $this->loadSimBrief($this->user);
// Check the flight API response // Check the flight API response
@ -115,7 +120,7 @@ class SimBriefTest extends TestCase
*/ */
public function testUserBidSimbrief() public function testUserBidSimbrief()
{ {
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(User::class)->create();
$this->loadSimBrief($this->user); $this->loadSimBrief($this->user);
// Find the flight // Find the flight
@ -131,8 +136,8 @@ class SimBriefTest extends TestCase
public function testAttachToPirep() public function testAttachToPirep()
{ {
$user = factory(App\Models\User::class)->create(); $user = factory(User::class)->create();
$pirep = factory(App\Models\Pirep::class)->create([ $pirep = factory(Pirep::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'dpt_airport_id' => 'OMAA', 'dpt_airport_id' => 'OMAA',
'arr_airport_id' => 'OMDB', 'arr_airport_id' => 'OMDB',
@ -167,7 +172,7 @@ class SimBriefTest extends TestCase
*/ */
public function testClearExpiredBriefs() public function testClearExpiredBriefs()
{ {
$user = factory(App\Models\User::class)->create(); $user = factory(User::class)->create();
$sb_ignored = factory(SimBrief::class)->create([ $sb_ignored = factory(SimBrief::class)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'flight_id' => 'a_flight_id', 'flight_id' => 'a_flight_id',

View File

@ -1,5 +1,11 @@
<?php <?php
namespace Tests;
use App\Models\Fare;
use App\Models\Subfleet;
use App\Services\FareService;
class SubfleetTest extends TestCase class SubfleetTest extends TestCase
{ {
protected $ac_svc; protected $ac_svc;
@ -13,10 +19,10 @@ class SubfleetTest extends TestCase
public function testSubfleetFaresNoOverride() public function testSubfleetFaresNoOverride()
{ {
$fare_svc = app('App\Services\FareService'); $fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare); $fare_svc->setForSubfleet($subfleet, $fare);
$subfleet_fares = $fare_svc->getForSubfleet($subfleet); $subfleet_fares = $fare_svc->getForSubfleet($subfleet);
@ -46,10 +52,10 @@ class SubfleetTest extends TestCase
public function testSubfleetFaresOverride() public function testSubfleetFaresOverride()
{ {
$fare_svc = app('App\Services\FareService'); $fare_svc = app(FareService::class);
$subfleet = factory(App\Models\Subfleet::class)->create(); $subfleet = factory(Subfleet::class)->create();
$fare = factory(App\Models\Fare::class)->create(); $fare = factory(Fare::class)->create();
$fare_svc->setForSubfleet($subfleet, $fare, [ $fare_svc->setForSubfleet($subfleet, $fare, [
'price' => 50, 'capacity' => 400, 'price' => 50, 'capacity' => 400,

View File

@ -1,29 +1,36 @@
<?php <?php
namespace Tests;
use App\Contracts\Unit;
use App\Exceptions\Handler;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Services\DatabaseService; use App\Services\DatabaseService;
use Carbon\Carbon; use Carbon\Carbon;
use DateTimeImmutable;
use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Illuminate\Testing\TestResponse; use Illuminate\Testing\TestResponse;
use Tests\CreatesApplication; use ReflectionClass;
use Tests\TestData;
class TestCase extends Illuminate\Foundation\Testing\TestCase /**
* Test cases should extend this class
*/
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
{ {
use TestData; use TestData;
use CreatesApplication; use CreatesApplication;
/** /**
* The base URL to use while testing the application. * The base URL to use while testing the application.
*
* @var string
*/ */
public static $prefix = '/api'; public static $prefix = '/api';
@ -31,6 +38,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
protected $baseUrl = 'http://localhost'; protected $baseUrl = 'http://localhost';
protected $connectionsToTransact = ['test']; protected $connectionsToTransact = ['test'];
/** @var \App\Models\User */
protected $user; protected $user;
protected static $auth_headers = [ protected static $auth_headers = [
@ -53,11 +61,31 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
Artisan::call('database:create', ['--reset' => true]); Artisan::call('database:create', ['--reset' => true]);
Artisan::call('migrate:refresh', ['--env' => 'testing']); Artisan::call('migrate:refresh', ['--env' => 'testing']);
// $this->disableExceptionHandling();
} }
public function tearDown(): void /**
* https://stackoverflow.com/a/41945739
* https://gist.github.com/adamwathan/c9752f61102dc056d157
*/
protected function disableExceptionHandling()
{ {
parent::tearDown(); $this->app->instance(ExceptionHandler::class, new class() extends Handler {
public function __construct()
{
}
public function report(\Throwable $e)
{
// no-op
}
public function render($request, \Throwable $e)
{
throw $e;
}
});
} }
/** /**
@ -200,13 +228,13 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
* @param $methodName * @param $methodName
* @param array $parameters * @param array $parameters
* *
* @throws ReflectionException * @throws \ReflectionException
* *
* @return mixed * @return mixed
*/ */
public function invokeMethod(&$object, $methodName, array $parameters = []) public function invokeMethod(&$object, $methodName, array $parameters = [])
{ {
$reflection = new \ReflectionClass(get_class($object)); $reflection = new ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName); $method = $reflection->getMethod($methodName);
$method->setAccessible(true); $method->setAccessible(true);
@ -228,7 +256,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
$this->transformData($value); $this->transformData($value);
} }
if (is_subclass_of($value, App\Contracts\Unit::class)) { if (is_subclass_of($value, Unit::class)) {
$data[$key] = $value->__toString(); $data[$key] = $value->__toString();
} }
@ -249,9 +277,9 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
* @param array $headers * @param array $headers
* @param null $user * @param null $user
* *
* @return Illuminate\Testing\TestResponse * @return \Illuminate\Testing\TestResponse
*/ */
public function get($uri, array $headers = [], $user = null): Illuminate\Testing\TestResponse public function get($uri, array $headers = [], $user = null): TestResponse
{ {
$req = parent::get($uri, $this->headers($user, $headers)); $req = parent::get($uri, $this->headers($user, $headers));
if ($req->isClientError() || $req->isServerError()) { if ($req->isClientError() || $req->isServerError()) {

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Exceptions\PilotIdNotFound; use App\Exceptions\PilotIdNotFound;
use App\Exceptions\UserPilotIdExists; use App\Exceptions\UserPilotIdExists;
use App\Models\User; use App\Models\User;
@ -35,7 +37,7 @@ class UserTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]); $rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
@ -95,7 +97,7 @@ class UserTest extends TestCase
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]); $rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
@ -136,17 +138,17 @@ class UserTest extends TestCase
{ {
// Add subfleets and aircraft, but also add another // Add subfleets and aircraft, but also add another
// set of subfleets // set of subfleets
$airport = factory(App\Models\Airport::class)->create(); $airport = factory(\App\Models\Airport::class)->create();
$subfleetA = $this->createSubfleetWithAircraft(2, $airport->id); $subfleetA = $this->createSubfleetWithAircraft(2, $airport->id);
$subfleetB = $this->createSubfleetWithAircraft(2); $subfleetB = $this->createSubfleetWithAircraft(2);
$rank = $this->createRank(10, [$subfleetA['subfleet']->id]); $rank = $this->createRank(10, [$subfleetA['subfleet']->id]);
$user = factory(App\Models\User::class)->create([ $user = factory(\App\Models\User::class)->create([
'curr_airport_id' => $airport->id, 'curr_airport_id' => $airport->id,
'rank_id' => $rank->id, 'rank_id' => $rank->id,
]); ]);
$flight = factory(App\Models\Flight::class)->create([ $flight = factory(\App\Models\Flight::class)->create([
'airline_id' => $user->airline_id, 'airline_id' => $user->airline_id,
'dpt_airport_id' => $airport->id, 'dpt_airport_id' => $airport->id,
]); ]);
@ -201,8 +203,8 @@ class UserTest extends TestCase
public function testUserPilotIdChangeAlreadyExists() public function testUserPilotIdChangeAlreadyExists()
{ {
$this->expectException(UserPilotIdExists::class); $this->expectException(UserPilotIdExists::class);
$user1 = factory(App\Models\User::class)->create(['id' => 1]); $user1 = factory(\App\Models\User::class)->create(['id' => 1]);
$user2 = factory(App\Models\User::class)->create(['id' => 2]); $user2 = factory(\App\Models\User::class)->create(['id' => 2]);
// Now try to change the original user's pilot_id to 2 (should conflict) // Now try to change the original user's pilot_id to 2 (should conflict)
$this->userSvc->changePilotId($user1, 2); $this->userSvc->changePilotId($user1, 2);
@ -214,7 +216,7 @@ class UserTest extends TestCase
public function testUserPilotIdSplit(): void public function testUserPilotIdSplit(): void
{ {
/** @var \App\Models\User $user */ /** @var \App\Models\User $user */
$user = factory(App\Models\User::class)->create(); $user = factory(\App\Models\User::class)->create();
$found_user = $this->userSvc->findUserByPilotId($user->ident); $found_user = $this->userSvc->findUserByPilotId($user->ident);
$this->assertEquals($user->id, $found_user->id); $this->assertEquals($user->id, $found_user->id);
@ -229,7 +231,7 @@ class UserTest extends TestCase
public function testUserPilotIdSplitInvalidId(): void public function testUserPilotIdSplitInvalidId(): void
{ {
/** @var \App\Models\User $user */ /** @var \App\Models\User $user */
$user = factory(App\Models\User::class)->create(); $user = factory(\App\Models\User::class)->create();
$this->expectException(PilotIdNotFound::class); $this->expectException(PilotIdNotFound::class);
$this->userSvc->findUserByPilotId($user->airline->iata); $this->userSvc->findUserByPilotId($user->airline->iata);
@ -240,13 +242,13 @@ class UserTest extends TestCase
*/ */
public function testUserPilotIdAdded() public function testUserPilotIdAdded()
{ {
$new_user = factory(App\Models\User::class)->make()->toArray(); $new_user = factory(\App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret'); $new_user['password'] = Hash::make('secret');
$user = $this->userSvc->createUser($new_user); $user = $this->userSvc->createUser($new_user);
$this->assertEquals($user->id, $user->pilot_id); $this->assertEquals($user->id, $user->pilot_id);
// Add a second user // Add a second user
$new_user = factory(App\Models\User::class)->make()->toArray(); $new_user = factory(\App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret'); $new_user['password'] = Hash::make('secret');
$user2 = $this->userSvc->createUser($new_user); $user2 = $this->userSvc->createUser($new_user);
$this->assertEquals($user2->id, $user2->pilot_id); $this->assertEquals($user2->id, $user2->pilot_id);
@ -256,7 +258,7 @@ class UserTest extends TestCase
$this->assertEquals(3, $user->pilot_id); $this->assertEquals(3, $user->pilot_id);
// Create a new user and the pilot_id should be 4 // Create a new user and the pilot_id should be 4
$user3 = factory(App\Models\User::class)->create(); $user3 = factory(\App\Models\User::class)->create();
$this->assertEquals(4, $user3->pilot_id); $this->assertEquals(4, $user3->pilot_id);
} }

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Support\ICAO; use App\Support\ICAO;
use App\Support\Units\Time; use App\Support\Units\Time;
use App\Support\Utils; use App\Support\Utils;
@ -14,7 +16,7 @@ class UtilsTest extends TestCase
} }
/** /**
* @throws Exception * @throws \Exception
*/ */
public function testSecondsToTimeParts() public function testSecondsToTimeParts()
{ {

View File

@ -1,5 +1,7 @@
<?php <?php
namespace Tests;
use App\Repositories\KvpRepository; use App\Repositories\KvpRepository;
use App\Services\VersionService; use App\Services\VersionService;