make sure resources return the data object #186
This commit is contained in:
@@ -49,7 +49,7 @@ class AcarsTest extends TestCase
|
||||
{
|
||||
$resp = $this ->get('/api/pireps/' . $pirep_id);
|
||||
$resp->assertStatus(200);
|
||||
return $resp->json();
|
||||
return $resp->json()['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,11 +116,11 @@ class AcarsTest extends TestCase
|
||||
|
||||
# Get the PIREP ID
|
||||
$body = $response->json();
|
||||
$pirep_id = $body['id'];
|
||||
$pirep_id = $body['data']['id'];
|
||||
|
||||
$this->assertHasKeys($body, ['airline', 'arr_airport', 'dpt_airport', 'position']);
|
||||
$this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport', 'position']);
|
||||
$this->assertNotNull($pirep_id);
|
||||
$this->assertEquals($body['user_id'], $this->user->id);
|
||||
$this->assertEquals($body['data']['user_id'], $this->user->id);
|
||||
|
||||
# Check the PIREP state and status
|
||||
$pirep = $this->getPirep($pirep_id);
|
||||
@@ -167,7 +167,7 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(200)->assertJson(['count' => 1]);
|
||||
|
||||
# Read that if the ACARS record posted
|
||||
$acars_data = $this->get($uri)->json()[0];
|
||||
$acars_data = $this->get($uri)->json()['data'][0];
|
||||
$this->assertEquals(round($acars['lat'], 2), round($acars_data['lat'], 2));
|
||||
$this->assertEquals(round($acars['lon'], 2), round($acars_data['lon'], 2));
|
||||
$this->assertEquals($acars['log'], $acars_data['log']);
|
||||
@@ -179,7 +179,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json();
|
||||
$body = $response->json()['data'];
|
||||
|
||||
$this->assertNotNull($body);
|
||||
$this->assertCount(1, $body);
|
||||
@@ -201,6 +201,7 @@ class AcarsTest extends TestCase
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json();
|
||||
|
||||
# Add a comment
|
||||
$uri = '/api/pireps/'.$pirep_id.'/comments';
|
||||
@@ -226,7 +227,7 @@ class AcarsTest extends TestCase
|
||||
$response = $this->post($uri, $pirep);
|
||||
$response->assertStatus(201);
|
||||
|
||||
$pirep_id = $response->json()['id'];
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$uri = '/api/pireps/' . $pirep_id . '/acars/position';
|
||||
|
||||
@@ -239,7 +240,7 @@ class AcarsTest extends TestCase
|
||||
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
|
||||
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200)->assertJsonCount($acars_count);
|
||||
$response->assertStatus(200)->assertJsonCount($acars_count, 'data');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +278,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$response = $this->post($uri, $pirep);
|
||||
$pirep_id = $response->json()['id'];
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$dt = date('c');
|
||||
$uri = '/api/pireps/' . $pirep_id . '/acars/position';
|
||||
@@ -300,7 +301,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$response = $this->post($uri, $pirep);
|
||||
$pirep_id = $response->json()['id'];
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$post_route = ['order' => 1, 'name' => 'NAVPOINT'];
|
||||
$uri = '/api/pireps/' . $pirep_id . '/route';
|
||||
@@ -323,7 +324,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$response = $this->post($uri, $pirep);
|
||||
$pirep_id = $response->json()['id'];
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$acars = factory(App\Models\Acars::class)->make();
|
||||
$post_log = [
|
||||
@@ -364,7 +365,7 @@ class AcarsTest extends TestCase
|
||||
|
||||
$uri = '/api/pireps/prefile';
|
||||
$response = $this->post($uri, $pirep);
|
||||
$pirep_id = $response->json()['id'];
|
||||
$pirep_id = $response->json()['data']['id'];
|
||||
|
||||
$order = 1;
|
||||
$post_route = [];
|
||||
|
||||
@@ -36,16 +36,17 @@ class ApiTest extends TestCase
|
||||
|
||||
// Test upper/lower case of Authorization header, etc
|
||||
$response = $this->get($uri, $this->headers($user));
|
||||
$response->assertStatus(200)->assertJson(['id' => $user->id], true);
|
||||
$body = $response->json();
|
||||
$response->assertStatus(200)->assertJson(['data' => ['id' => $user->id]]);
|
||||
|
||||
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
||||
->assertJson(['id' => $user->id], true);
|
||||
->assertJson(['data' => ['id' => $user->id]]);
|
||||
|
||||
$this->withHeaders(['x-API-key' => $user->api_key])->get($uri)
|
||||
->assertJson(['id' => $user->id], true);
|
||||
->assertJson(['data' => ['id' => $user->id]]);
|
||||
|
||||
$this->withHeaders(['X-API-KEY' => $user->api_key])->get($uri)
|
||||
->assertJson(['id' => $user->id], true);
|
||||
->assertJson(['data' => ['id' => $user->id]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +80,8 @@ class ApiTest extends TestCase
|
||||
$this->assertCount($size, $body['data']);
|
||||
|
||||
$airline = $airlines->random();
|
||||
$this->get('/api/airlines/'.$airline->id)->assertJson(['name' => $airline->name]);
|
||||
$this->get('/api/airlines/'.$airline->id)
|
||||
->assertJson(['data' => ['name' => $airline->name]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +95,7 @@ class ApiTest extends TestCase
|
||||
$response = $this->get('/api/airports/' . $airport->icao);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['icao' => $airport->icao], true);
|
||||
$response->assertJson(['data' => ['icao' => $airport->icao]]);
|
||||
|
||||
$this->get('/api/airports/UNK')->assertStatus(404);
|
||||
}
|
||||
@@ -158,9 +160,9 @@ class ApiTest extends TestCase
|
||||
|
||||
$response = $this->get('/api/fleet');
|
||||
$response->assertStatus(200);
|
||||
$body = $response->json();
|
||||
$body = $response->json()['data'];
|
||||
|
||||
foreach($body['data'] as $subfleet) {
|
||||
foreach($body as $subfleet) {
|
||||
if($subfleet['id'] === $subfleetA->id) {
|
||||
$size = $subfleetA_size;
|
||||
} else {
|
||||
@@ -195,19 +197,19 @@ class ApiTest extends TestCase
|
||||
* Just try retrieving by ID
|
||||
*/
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id);
|
||||
$body = $resp->json();
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?registration=' . $aircraft->registration);
|
||||
$body = $resp->json();
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?tail_number=' . $aircraft->registration);
|
||||
$body = $resp->json();
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
|
||||
$resp = $this->get('/api/fleet/aircraft/' . $aircraft->id . '?icao=' . $aircraft->icao);
|
||||
$body = $resp->json();
|
||||
$body = $resp->json()['data'];
|
||||
$this->assertEquals($body['id'], $aircraft->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class FlightTest extends TestCase
|
||||
$req = $this->get('/api/flights/' . $flight->id);
|
||||
$req->assertStatus(200);
|
||||
|
||||
$body = $req->json();
|
||||
$body = $req->json()['data'];
|
||||
$this->assertEquals($flight->id, $body['id']);
|
||||
$this->assertEquals($flight->dpt_airport_id, $body['dpt_airport_id']);
|
||||
$this->assertEquals($flight->arr_airport_id, $body['arr_airport_id']);
|
||||
|
||||
Reference in New Issue
Block a user