Don't allow cancels from certain states (#396)
* Don't allow cancels from certain states * Unused imports * Don't reset the state doubly * Move SetUserActive into listener; code cleanup * Unused imports * Add missing files into htaccess * Move Command contract to correct folder
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Enums\PirepStatus;
|
||||
use App\Models\PirepFare;
|
||||
use App\Repositories\SettingRepository;
|
||||
|
||||
/**
|
||||
@@ -217,7 +218,7 @@ class AcarsTest extends TestCase
|
||||
$pirep = $response->json('data');
|
||||
|
||||
// See that the fields and fares were set
|
||||
$fares = \App\Models\PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$fares = PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$this->assertCount(1, $fares);
|
||||
$saved_fare = $fares->first();
|
||||
|
||||
@@ -246,16 +247,30 @@ class AcarsTest extends TestCase
|
||||
];
|
||||
|
||||
$response = $this->post($uri, $update);
|
||||
$response->assertStatus(200);
|
||||
$updated_pirep = $response->json('data');
|
||||
$response->assertOk();
|
||||
|
||||
// Make sure there are no duplicates
|
||||
$fares = \App\Models\PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$fares = PirepFare::where('pirep_id', $pirep['id'])->get();
|
||||
$this->assertCount(1, $fares);
|
||||
$saved_fare = $fares->first();
|
||||
|
||||
$this->assertEquals($fare->id, $saved_fare['fare_id']);
|
||||
$this->assertEquals($fare->capacity, $saved_fare['count']);
|
||||
|
||||
/*
|
||||
* Try cancelling the PIREP now
|
||||
*/
|
||||
$uri = '/api/pireps/'.$pirep['id'].'/cancel';
|
||||
$response = $this->put($uri, []);
|
||||
$response->assertOk();
|
||||
|
||||
// Read it
|
||||
$uri = '/api/pireps/'.$pirep['id'];
|
||||
$response = $this->get($uri);
|
||||
$response->assertOk();
|
||||
$body = $response->json('data');
|
||||
|
||||
$this->assertEquals($body['state'], PirepState::CANCELLED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,11 +475,6 @@ class AcarsTest extends TestCase
|
||||
$body = $this->get('/api/pireps/'.$pirep_id)->json('data');
|
||||
$this->assertNotNull($body['block_off_time']);
|
||||
$this->assertNotNull($body['block_on_time']);
|
||||
|
||||
// make sure the time matches up
|
||||
/*$block_on = new Carbon($body['block_on_time'], 'UTC');
|
||||
$block_off = new Carbon($body['block_off_time'], 'UTC');
|
||||
$this->assertEquals($block_on->subMinutes($body['flight_time']), $block_off);*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ use App\Services\ImportExport\AircraftExporter;
|
||||
use App\Services\ImportExport\AirportExporter;
|
||||
use App\Services\ImportExport\FlightExporter;
|
||||
use App\Services\ImportService;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Class ImporterTest
|
||||
@@ -358,11 +359,10 @@ class ImporterTest extends TestCase
|
||||
|
||||
/**
|
||||
* Try importing the aicraft in the airports. Should fail
|
||||
*
|
||||
* @expectedException \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testInvalidFileImport(): void
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
$file_path = base_path('tests/data/aircraft.csv');
|
||||
$this->importSvc->importAirports($file_path);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,11 @@ class PIREPTest extends TestCase
|
||||
$this->get('/api/fleet/aircraft/'.$pirep->aircraft_id, [], $user)
|
||||
->assertJson(['data' => ['airport_id' => $pirep->arr_airport_id]]);
|
||||
|
||||
// Try cancelling it
|
||||
$uri = '/api/pireps/'.$pirep->id.'/cancel';
|
||||
$response = $this->put($uri, [], [], $user);
|
||||
$response->assertStatus(400);
|
||||
|
||||
/**
|
||||
* Now go from ACCEPTED to REJECTED
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Exceptions\UserPilotIdExists;
|
||||
use App\Models\User;
|
||||
use App\Repositories\SettingRepository;
|
||||
use App\Services\UserService;
|
||||
@@ -191,11 +192,10 @@ class UserTest extends TestCase
|
||||
|
||||
/**
|
||||
* Test the pilot ID being added when a new user is created
|
||||
*
|
||||
* @expectedException \App\Exceptions\UserPilotIdExists
|
||||
*/
|
||||
public function testUserPilotIdChangeAlreadyExists()
|
||||
{
|
||||
$this->expectException(UserPilotIdExists::class);
|
||||
$user1 = factory(App\Models\User::class)->create(['id' => 1]);
|
||||
$user2 = factory(App\Models\User::class)->create(['id' => 2]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user