Cleanup tests to automatically inject proper headers when needed
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Prettus\Repository\Criteria\RequestCriteria;
|
||||||
|
|
||||||
use App\Repositories\FlightRepository;
|
use App\Repositories\FlightRepository;
|
||||||
use App\Http\Resources\Flight as FlightResource;
|
use App\Http\Resources\Flight as FlightResource;
|
||||||
@@ -31,7 +32,9 @@ class FlightController extends RestController
|
|||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
$this->flightRepo->searchCriteria($request);
|
||||||
|
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
||||||
|
$flights = $this->flightRepo->paginate();
|
||||||
} catch (RepositoryException $e) {
|
} catch (RepositoryException $e) {
|
||||||
return response($e, 503);
|
return response($e, 503);
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-37
@@ -48,8 +48,8 @@ class AcarsTest extends TestCase
|
|||||||
|
|
||||||
protected function getPirep($pirep_id)
|
protected function getPirep($pirep_id)
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$resp = $this->withHeaders($this->headers($user))
|
$resp = $this
|
||||||
->get('/api/pireps/' . $pirep_id);
|
->get('/api/pireps/' . $pirep_id);
|
||||||
$resp->assertStatus(200);
|
$resp->assertStatus(200);
|
||||||
return $resp->json();
|
return $resp->json();
|
||||||
@@ -60,7 +60,7 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAcarsUpdates()
|
public function testAcarsUpdates()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
|
||||||
$airport = factory(App\Models\Airport::class)->create();
|
$airport = factory(App\Models\Airport::class)->create();
|
||||||
$airline = factory(App\Models\Airline::class)->create();
|
$airline = factory(App\Models\Airline::class)->create();
|
||||||
@@ -78,7 +78,7 @@ class AcarsTest extends TestCase
|
|||||||
'route' => 'POINTA POINTB',
|
'route' => 'POINTA POINTB',
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$response->assertStatus(201);
|
$response->assertStatus(201);
|
||||||
|
|
||||||
# Get the PIREP ID
|
# Get the PIREP ID
|
||||||
@@ -98,7 +98,7 @@ class AcarsTest extends TestCase
|
|||||||
# Test missing positions field
|
# Test missing positions field
|
||||||
# Post an ACARS update
|
# Post an ACARS update
|
||||||
$update = [];
|
$update = [];
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $update);
|
$response = $this->post($uri, $update);
|
||||||
$response->assertStatus(400);
|
$response->assertStatus(400);
|
||||||
|
|
||||||
# Post an ACARS update
|
# Post an ACARS update
|
||||||
@@ -106,7 +106,7 @@ class AcarsTest extends TestCase
|
|||||||
unset($acars['id']);
|
unset($acars['id']);
|
||||||
|
|
||||||
$update = ['positions' => [$acars]];
|
$update = ['positions' => [$acars]];
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $update);
|
$response = $this->post($uri, $update);
|
||||||
$response->assertStatus(200)->assertJson(['count' => 1]);
|
$response->assertStatus(200)->assertJson(['count' => 1]);
|
||||||
|
|
||||||
# Make sure PIREP state moved into ENROUTE
|
# Make sure PIREP state moved into ENROUTE
|
||||||
@@ -114,7 +114,7 @@ class AcarsTest extends TestCase
|
|||||||
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
$this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']);
|
||||||
$this->assertEquals(PirepStatus::ENROUTE, $pirep['status']);
|
$this->assertEquals(PirepStatus::ENROUTE, $pirep['status']);
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))->get($uri);
|
$response = $this->get($uri);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
|
|
||||||
@@ -129,11 +129,11 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMultipleAcarsPositionUpdates()
|
public function testMultipleAcarsPositionUpdates()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$response->assertStatus(201);
|
$response->assertStatus(201);
|
||||||
|
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['id'];
|
||||||
@@ -145,10 +145,10 @@ class AcarsTest extends TestCase
|
|||||||
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id'=>''])->toArray();
|
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id'=>''])->toArray();
|
||||||
|
|
||||||
$update = ['positions' => $acars];
|
$update = ['positions' => $acars];
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $update);
|
$response = $this->post($uri, $update);
|
||||||
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
|
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))->get($uri);
|
$response = $this->get($uri);
|
||||||
$response->assertStatus(200)->assertJsonCount($acars_count);
|
$response->assertStatus(200)->assertJsonCount($acars_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +157,10 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNonExistentPirepGet()
|
public function testNonExistentPirepGet()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
|
||||||
$uri = '/api/pireps/DOESNTEXIST/acars';
|
$uri = '/api/pireps/DOESNTEXIST/acars';
|
||||||
$response = $this->withHeaders($this->headers($user))->get($uri);
|
$response = $this->get($uri);
|
||||||
$response->assertStatus(404);
|
$response->assertStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +169,11 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNonExistentPirepStore()
|
public function testNonExistentPirepStore()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\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(App\Models\Acars::class)->make()->toArray();
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $acars);
|
$response = $this->post($uri, $acars);
|
||||||
$response->assertStatus(404);
|
$response->assertStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,11 +182,11 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAcarsIsoDate()
|
public function testAcarsIsoDate()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['id'];
|
||||||
|
|
||||||
$dt = date('c');
|
$dt = date('c');
|
||||||
@@ -196,7 +196,7 @@ class AcarsTest extends TestCase
|
|||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
$update = ['positions' => [$acars]];
|
$update = ['positions' => [$acars]];
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $update);
|
$response = $this->post($uri, $update);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,16 +205,16 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAcarsInvalidRoutePost()
|
public function testAcarsInvalidRoutePost()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['id'];
|
||||||
|
|
||||||
$post_route = ['order' => 1, 'name' => 'NAVPOINT'];
|
$post_route = ['order' => 1, 'name' => 'NAVPOINT'];
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $post_route);
|
$response = $this->post($uri, $post_route);
|
||||||
$response->assertStatus(400);
|
$response->assertStatus(400);
|
||||||
|
|
||||||
$post_route = [
|
$post_route = [
|
||||||
@@ -222,17 +222,17 @@ class AcarsTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $post_route);
|
$response = $this->post($uri, $post_route);
|
||||||
$response->assertStatus(400);
|
$response->assertStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAcarsLogPost()
|
public function testAcarsLogPost()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['id'];
|
||||||
|
|
||||||
$acars = factory(App\Models\Acars::class)->make();
|
$acars = factory(App\Models\Acars::class)->make();
|
||||||
@@ -243,7 +243,7 @@ class AcarsTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/acars/log';
|
$uri = '/api/pireps/' . $pirep_id . '/acars/log';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $post_log);
|
$response = $this->post($uri, $post_log);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
|
|
||||||
@@ -255,11 +255,11 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAcarsRoutePost()
|
public function testAcarsRoutePost()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['id'];
|
||||||
|
|
||||||
$order = 1;
|
$order = 1;
|
||||||
@@ -279,7 +279,7 @@ class AcarsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
$uri = '/api/pireps/'.$pirep_id.'/route';
|
$uri = '/api/pireps/'.$pirep_id.'/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, ['route' => $post_route]);
|
$response = $this->post($uri, ['route' => $post_route]);
|
||||||
$response->assertStatus(200)->assertJsonCount($route_count);
|
$response->assertStatus(200)->assertJsonCount($route_count);
|
||||||
|
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
@@ -290,7 +290,7 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->get($uri);
|
$response = $this->get($uri);
|
||||||
$response->assertStatus(200)->assertJsonCount($route_count);
|
$response->assertStatus(200)->assertJsonCount($route_count);
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
$this->allPointsInRoute($post_route, $body);
|
$this->allPointsInRoute($post_route, $body);
|
||||||
@@ -299,11 +299,11 @@ class AcarsTest extends TestCase
|
|||||||
* Delete and then recheck
|
* Delete and then recheck
|
||||||
*/
|
*/
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->delete($uri);
|
$response = $this->delete($uri);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||||
$response = $this->withHeaders($this->headers($user))->get($uri);
|
$response = $this->get($uri);
|
||||||
$response->assertStatus(200)->assertJsonCount(0);
|
$response->assertStatus(200)->assertJsonCount(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,21 +312,21 @@ class AcarsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDuplicatePirep()
|
public function testDuplicatePirep()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make([
|
$pirep = factory(App\Models\Pirep::class)->make([
|
||||||
'id' => '',
|
'id' => '',
|
||||||
'airline_id' => $user->airline_id,
|
'airline_id' => $this->user->airline_id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $this->user->id,
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$response->assertStatus(201);
|
$response->assertStatus(201);
|
||||||
$pirep = $response->json();
|
$pirep = $response->json();
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-25
@@ -56,13 +56,12 @@ class ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testApiDeniedOnInactiveUser()
|
public function testApiDeniedOnInactiveUser()
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create([
|
$this->user = factory(User::class)->create([
|
||||||
'state' => UserState::PENDING
|
'state' => UserState::PENDING
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$uri = '/api/user';
|
$uri = '/api/user';
|
||||||
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
$this->get($uri)->assertStatus(401);
|
||||||
->assertStatus(401);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,18 +69,15 @@ class ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAirportRequest()
|
public function testAirportRequest()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$airport = factory(App\Models\Airport::class)->create();
|
$airport = factory(App\Models\Airport::class)->create();
|
||||||
|
|
||||||
$response = $this->withHeaders($this->headers($user))
|
$response = $this->get('/api/airports/' . $airport->icao);
|
||||||
->get('/api/airports/' . $airport->icao);
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertJson(['icao' => $airport->icao], true);
|
$response->assertJson(['icao' => $airport->icao], true);
|
||||||
|
|
||||||
$this->withHeaders($this->headers($user))
|
$this->get('/api/airports/UNK')->assertStatus(404);
|
||||||
->get('/api/airports/UNK')
|
|
||||||
->assertStatus(404);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,10 +85,9 @@ class ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetAllAirports()
|
public function testGetAllAirports()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
|
||||||
factory(App\Models\Airport::class, 70)->create();
|
factory(App\Models\Airport::class, 70)->create();
|
||||||
|
|
||||||
$response = $this->user_get($user, '/api/airports/')
|
$response = $this->get('/api/airports/')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonCount(50, 'data');
|
->assertJsonCount(50, 'data');
|
||||||
|
|
||||||
@@ -101,19 +96,17 @@ class ApiTest extends TestCase
|
|||||||
$this->assertHasKeys($body, ['data', 'links', 'meta']);
|
$this->assertHasKeys($body, ['data', 'links', 'meta']);
|
||||||
|
|
||||||
$last_page = $body['meta']['last_page'];
|
$last_page = $body['meta']['last_page'];
|
||||||
$this->user_get($user, '/api/airports?page='.$last_page)
|
$this->get('/api/airports?page=' . $last_page)
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonCount(20, 'data');
|
->assertJsonCount(20, 'data');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAllAirportsHubs()
|
public function testGetAllAirportsHubs()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
|
||||||
|
|
||||||
factory(App\Models\Airport::class, 10)->create();
|
factory(App\Models\Airport::class, 10)->create();
|
||||||
factory(App\Models\Airport::class)->create(['hub' => 1]);
|
factory(App\Models\Airport::class)->create(['hub' => 1]);
|
||||||
|
|
||||||
$this->user_get($user, '/api/airports/hubs')
|
$this->get('/api/airports/hubs')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonCount(1, 'data');
|
->assertJsonCount(1, 'data');
|
||||||
}
|
}
|
||||||
@@ -123,7 +116,6 @@ class ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetSubfleets()
|
public function testGetSubfleets()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
|
||||||
$subfleetA = factory(App\Models\Subfleet::class)->create();
|
$subfleetA = factory(App\Models\Subfleet::class)->create();
|
||||||
$subfleetB = factory(App\Models\Subfleet::class)->create();
|
$subfleetB = factory(App\Models\Subfleet::class)->create();
|
||||||
|
|
||||||
@@ -137,7 +129,7 @@ class ApiTest extends TestCase
|
|||||||
'subfleet_id' => $subfleetB->id
|
'subfleet_id' => $subfleetB->id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->user_get($user, '/api/fleet');
|
$response = $this->get('/api/fleet');
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
|
|
||||||
@@ -157,7 +149,6 @@ class ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetAircraft()
|
public function testGetAircraft()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
|
||||||
$subfleet = factory(App\Models\Subfleet::class)->create();
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||||
$aircraft = factory(App\Models\Aircraft::class)->create([
|
$aircraft = factory(App\Models\Aircraft::class)->create([
|
||||||
'subfleet_id' => $subfleet->id
|
'subfleet_id' => $subfleet->id
|
||||||
@@ -166,22 +157,19 @@ class ApiTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Just try retrieving by ID
|
* Just try retrieving by ID
|
||||||
*/
|
*/
|
||||||
$resp = $this->user_get($user, '/api/fleet/aircraft/'. $aircraft->id);
|
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id);
|
||||||
$body = $resp->json();
|
$body = $resp->json();
|
||||||
$this->assertEquals($body['id'], $aircraft->id);
|
$this->assertEquals($body['id'], $aircraft->id);
|
||||||
|
|
||||||
$resp = $this->user_get($user,
|
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?registration=' . $aircraft->registration);
|
||||||
'/api/fleet/aircraft/'.$aircraft->id.'?registration='.$aircraft->registration);
|
|
||||||
$body = $resp->json();
|
$body = $resp->json();
|
||||||
$this->assertEquals($body['id'], $aircraft->id);
|
$this->assertEquals($body['id'], $aircraft->id);
|
||||||
|
|
||||||
$resp = $this->user_get($user,
|
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?tail_number=' . $aircraft->registration);
|
||||||
'/api/fleet/aircraft/' . $aircraft->id . '?tail_number=' . $aircraft->registration);
|
|
||||||
$body = $resp->json();
|
$body = $resp->json();
|
||||||
$this->assertEquals($body['id'], $aircraft->id);
|
$this->assertEquals($body['id'], $aircraft->id);
|
||||||
|
|
||||||
$resp = $this->user_get($user,
|
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?icao=' . $aircraft->icao);
|
||||||
'/api/fleet/aircraft/' . $aircraft->id . '?icao=' . $aircraft->icao);
|
|
||||||
$body = $resp->json();
|
$body = $resp->json();
|
||||||
$this->assertEquals($body['id'], $aircraft->id);
|
$this->assertEquals($body['id'], $aircraft->id);
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-2
@@ -29,7 +29,7 @@ class FlightTest extends TestCase
|
|||||||
{
|
{
|
||||||
$flight = $this->addFlight();
|
$flight = $this->addFlight();
|
||||||
|
|
||||||
$req = $this->get('/api/flights/'.$flight->id, self::$auth_headers);
|
$req = $this->get('/api/flights/' . $flight->id);
|
||||||
$req->assertStatus(200);
|
$req->assertStatus(200);
|
||||||
|
|
||||||
$body = $req->json();
|
$body = $req->json();
|
||||||
@@ -50,10 +50,22 @@ class FlightTest extends TestCase
|
|||||||
|
|
||||||
# search specifically for a flight ID
|
# search specifically for a flight ID
|
||||||
$query = 'flight_id=' . $flight->id;
|
$query = 'flight_id=' . $flight->id;
|
||||||
$req = $this->get('/api/flights/search?' . $query, self::$auth_headers);
|
$req = $this->get('/api/flights/search?' . $query);
|
||||||
$req->assertStatus(200);
|
$req->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFlightSearchApi()
|
||||||
|
{
|
||||||
|
$flights = factory(App\Models\Flight::class, 100)->create();
|
||||||
|
$flight = $flights->random();
|
||||||
|
|
||||||
|
$query = 'flight_id=' . $flight->id;
|
||||||
|
$req = $this->get('/api/flights/search?' . $query);
|
||||||
|
$body = $req->json();
|
||||||
|
|
||||||
|
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add/remove a bid, test the API, etc
|
* Add/remove a bid, test the API, etc
|
||||||
* @throws \App\Services\Exception
|
* @throws \App\Services\Exception
|
||||||
|
|||||||
+8
-6
@@ -167,7 +167,9 @@ class PIREPTest extends TestCase
|
|||||||
public function testDuplicatePireps()
|
public function testDuplicatePireps()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(Pirep::class)->create();
|
$pirep = factory(Pirep::class)->create([
|
||||||
|
'user_id' => $user->id
|
||||||
|
]);
|
||||||
|
|
||||||
# This should find itself...
|
# This should find itself...
|
||||||
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
|
||||||
@@ -190,16 +192,16 @@ class PIREPTest extends TestCase
|
|||||||
|
|
||||||
public function testCancelViaAPI()
|
public function testCancelViaAPI()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->make(['id'=>''])->toArray();
|
$pirep = factory(App\Models\Pirep::class)->make(['id'=>''])->toArray();
|
||||||
|
|
||||||
$uri = '/api/pireps/prefile';
|
$uri = '/api/pireps/prefile';
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $pirep);
|
$response = $this->post($uri, $pirep);
|
||||||
$pirep_id = $response->json()['id'];
|
$pirep_id = $response->json()['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(App\Models\Acars::class)->make()->toArray();
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, [
|
$response = $this->post($uri, [
|
||||||
'positions' => [$acars]
|
'positions' => [$acars]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -207,13 +209,13 @@ class PIREPTest extends TestCase
|
|||||||
|
|
||||||
# Cancel it
|
# Cancel it
|
||||||
$uri = '/api/pireps/' . $pirep_id . '/cancel';
|
$uri = '/api/pireps/' . $pirep_id . '/cancel';
|
||||||
$response = $this->withHeaders($this->headers($user))->delete($uri, $acars);
|
$response = $this->delete($uri, $acars);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
# 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(App\Models\Acars::class)->make()->toArray();
|
||||||
$response = $this->withHeaders($this->headers($user))->post($uri, $acars);
|
$response = $this->post($uri, $acars);
|
||||||
$response->assertStatus(400);
|
$response->assertStatus(400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-7
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
protected $baseUrl = 'http://localhost';
|
protected $baseUrl = 'http://localhost';
|
||||||
protected $connectionsToTransact = ['testing'];
|
protected $connectionsToTransact = ['testing'];
|
||||||
|
|
||||||
|
protected $user;
|
||||||
|
|
||||||
protected static $auth_headers = [
|
protected static $auth_headers = [
|
||||||
'x-api-key' => 'testadminapikey'
|
'x-api-key' => 'testadminapikey'
|
||||||
];
|
];
|
||||||
@@ -30,8 +33,6 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
public function headers($user)
|
public function headers($user)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
#'accept' => 'application/json',
|
|
||||||
#'content-type' => 'application/json',
|
|
||||||
'x-api-key' => $user->api_key,
|
'x-api-key' => $user->api_key,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -59,7 +60,6 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
{
|
{
|
||||||
$app = require __DIR__.'/../bootstrap/app.php';
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||||
//$app['config']->set('database.default','testing');
|
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,13 +97,55 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut for a get call with a user
|
* Override the GET call to inject the user API key
|
||||||
* @param \App\Models\User $user
|
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
|
* @param array $headers
|
||||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||||
*/
|
*/
|
||||||
public function user_get($user, $uri)
|
public function get($uri, array $headers=[]): \Illuminate\Foundation\Testing\TestResponse
|
||||||
{
|
{
|
||||||
return $this->withHeaders($this->headers($user))->get($uri);
|
if(empty($headers)) {
|
||||||
|
if($this->user !== null) {
|
||||||
|
$headers = $this->headers($this->user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::get($uri, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the POST calls to inject the user API key
|
||||||
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
|
* @param array $headers
|
||||||
|
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||||
|
*/
|
||||||
|
public function post($uri, array $data = [], array $headers = [])
|
||||||
|
{
|
||||||
|
if (empty($headers)) {
|
||||||
|
if ($this->user !== null) {
|
||||||
|
$headers = $this->headers($this->user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::post($uri, $data, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the DELETE calls to inject the user API key
|
||||||
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
|
* @param array $headers
|
||||||
|
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||||
|
*/
|
||||||
|
public function delete($uri, array $data = [], array $headers = [])
|
||||||
|
{
|
||||||
|
if (empty($headers)) {
|
||||||
|
if ($this->user !== null) {
|
||||||
|
$headers = $this->headers($this->user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::delete($uri, $data, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user