tests check the data object in return #186

This commit is contained in:
Nabeel Shahzad
2018-02-10 18:17:38 -06:00
parent 04d44d9bd7
commit 3aa01aaa18
5 changed files with 36 additions and 33 deletions

View File

@@ -412,7 +412,7 @@ class PirepController extends RestController
* Post the ROUTE for a PIREP, can be done from the ACARS log * Post the ROUTE for a PIREP, can be done from the ACARS log
* @param $id * @param $id
* @param RouteRequest $request * @param RouteRequest $request
* @return AcarsRouteResource * @return \Illuminate\Http\JsonResponse
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/ */
public function route_post($id, RouteRequest $request) public function route_post($id, RouteRequest $request)
@@ -423,6 +423,7 @@ class PirepController extends RestController
Log::info('Posting ROUTE, PIREP: '.$id, $request->post()); Log::info('Posting ROUTE, PIREP: '.$id, $request->post());
$count = 0;
$route = $request->post('route', []); $route = $request->post('route', []);
foreach($route as $position) { foreach($route as $position) {
$position['pirep_id'] = $id; $position['pirep_id'] = $id;
@@ -430,9 +431,11 @@ class PirepController extends RestController
$acars = Acars::create($position); $acars = Acars::create($position);
$acars->save(); $acars->save();
++$count;
} }
return $this->route_get($id, $request); return $this->message($count . ' points added', $count);
} }
/** /**

View File

@@ -385,10 +385,7 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/'.$pirep_id.'/route'; $uri = '/api/pireps/'.$pirep_id.'/route';
$response = $this->post($uri, ['route' => $post_route]); $response = $this->post($uri, ['route' => $post_route]);
$response->assertStatus(200)->assertJsonCount($route_count); $response->assertStatus(200)->assertJson(['count' => $route_count]);
$body = $response->json();
$this->allPointsInRoute($post_route, $body);
/** /**
* Get * Get
@@ -396,8 +393,9 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/' . $pirep_id . '/route'; $uri = '/api/pireps/' . $pirep_id . '/route';
$response = $this->get($uri); $response = $this->get($uri);
$response->assertStatus(200)->assertJsonCount($route_count); $response->assertStatus(200)->assertJsonCount($route_count, 'data');
$body = $response->json();
$body = $response->json()['data'];
$this->allPointsInRoute($post_route, $body); $this->allPointsInRoute($post_route, $body);
/** /**
@@ -409,7 +407,7 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/' . $pirep_id . '/route'; $uri = '/api/pireps/' . $pirep_id . '/route';
$response = $this->get($uri); $response = $this->get($uri);
$response->assertStatus(200)->assertJsonCount(0); $response->assertStatus(200)->assertJsonCount(0, 'data');
} }
/** /**
@@ -420,19 +418,22 @@ class AcarsTest extends TestCase
$this->user = factory(App\Models\User::class)->create(); $this->user = factory(App\Models\User::class)->create();
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
$this->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' => '',
'airline_id' => $this->user->airline_id, 'airline_id' => $this->user->airline_id,
'user_id' => $this->user->id, 'user_id' => $this->user->id,
])->toArray(); ])->toArray();
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(201);
$pirep = $response->json(); $pirep_id = $response->json()['data']['id'];
# try readding
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(200); $response->assertStatus(200);
$body = $response->json(); $dupe_pirep_id = $response->json()['data']['id'];
$this->assertEquals($pirep_id, $dupe_pirep_id);
} }
} }

View File

@@ -132,13 +132,13 @@ class FlightTest extends TestCase
$req = $this->get('/api/user', $headers); $req = $this->get('/api/user', $headers);
$req->assertStatus(200); $req->assertStatus(200);
$body = $req->json(); $body = $req->json()['data'];
$this->assertEquals(1, sizeof($body['bids'])); $this->assertEquals(1, sizeof($body['bids']));
$this->assertEquals($flight->id, $body['bids'][0]['flight_id']); $this->assertEquals($flight->id, $body['bids'][0]['flight_id']);
$req = $this->get('/api/users/'.$user->id.'/bids', $headers); $req = $this->get('/api/users/'.$user->id.'/bids', $headers);
$body = $req->json(); $body = $req->json()['data'];
$req->assertStatus(200); $req->assertStatus(200);
$this->assertEquals($flight->id, $body[0]['id']); $this->assertEquals($flight->id, $body[0]['id']);
@@ -156,15 +156,15 @@ class FlightTest extends TestCase
$req = $this->get('/api/user', $headers); $req = $this->get('/api/user', $headers);
$req->assertStatus(200); $req->assertStatus(200);
$body = $req->json(); $body = $req->json()['data'];
$this->assertEquals($user->id, $body['id']); $this->assertEquals($user->id, $body['id']);
$this->assertEquals(0, sizeof($body['bids'])); $this->assertEquals(0, sizeof($body['bids']));
$req = $this->get('/api/users/'.$user->id.'/bids', $headers); $req = $this->get('/api/users/'.$user->id.'/bids', $headers);
$req->assertStatus(200); $req->assertStatus(200);
$body = $req->json(); $body = $req->json()['data'];
$this->assertEquals(0, sizeof($body)); $this->assertCount(0, $body);
} }
/** /**
@@ -217,15 +217,15 @@ class FlightTest extends TestCase
# And pull the flight details for the user/bids # And pull the flight details for the user/bids
$req = $this->get('/api/user', $headers); $req = $this->get('/api/user', $headers);
$req->assertStatus(200); $req->assertStatus(200);
$body = $req->json();
$body = $req->json()['data'];
$this->assertEquals($user->id, $body['id']); $this->assertEquals($user->id, $body['id']);
$this->assertEquals(0, sizeof($body['bids'])); $this->assertCount(0, $body['bids']);
$req = $this->get('/api/users/'.$user->id.'/bids', $headers); $req = $this->get('/api/users/'.$user->id.'/bids', $headers);
$req->assertStatus(200); $req->assertStatus(200);
$body = $req->json(); $body = $req->json()['data'];
$this->assertEquals(0, sizeof($body)); $this->assertCount(0, $body);
} }
} }

View File

@@ -80,7 +80,7 @@ class PIREPTest extends TestCase
# Also check via API: # Also check via API:
$this->get('/api/fleet/aircraft/' . $pirep->aircraft_id, [], $user) $this->get('/api/fleet/aircraft/' . $pirep->aircraft_id, [], $user)
->assertJson(['airport_id' => $pirep->arr_airport_id]); ->assertJson(['data' => ['airport_id' => $pirep->arr_airport_id]]);
/** /**
* Now go from ACCEPTED to REJECTED * Now go from ACCEPTED to REJECTED
@@ -209,7 +209,7 @@ class PIREPTest extends TestCase
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$pirep_id = $response->json()['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(App\Models\Acars::class)->make()->toArray();

View File

@@ -47,7 +47,7 @@ class UserTest extends TestCase
* Check via API * Check via API
*/ */
$resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200); $resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200);
$body = $resp->json(); $body = $resp->json()['data'];
# Get the subfleet that's been added in # Get the subfleet that's been added in
$subfleet_from_api = $body[0]; $subfleet_from_api = $body[0];
@@ -61,7 +61,7 @@ class UserTest extends TestCase
* Check the user ID call * Check the user ID call
*/ */
$resp = $this->get('/api/users/' . $user->id . '/fleet', [], $user)->assertStatus(200); $resp = $this->get('/api/users/' . $user->id . '/fleet', [], $user)->assertStatus(200);
$body = $resp->json(); $body = $resp->json()['data'];
# Get the subfleet that's been added in # Get the subfleet that's been added in
$subfleet_from_api = $body[0]; $subfleet_from_api = $body[0];
@@ -112,9 +112,9 @@ class UserTest extends TestCase
* Check via API * Check via API
*/ */
$resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200); $resp = $this->get('/api/user/fleet', [], $user)->assertStatus(200);
$body = $resp->json();
# Get all the aircraft from that subfleet # Get all the aircraft from that subfleet
$body = $resp->json()['data'];
$aircraft_from_api = array_merge( $aircraft_from_api = array_merge(
collect($body[0]['aircraft'])->pluck('id')->toArray(), collect($body[0]['aircraft'])->pluck('id')->toArray(),
collect($body[1]['aircraft'])->pluck('id')->toArray() collect($body[1]['aircraft'])->pluck('id')->toArray()
@@ -168,9 +168,8 @@ class UserTest extends TestCase
$this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false); $this->settingsRepo->store('pireps.restrict_aircraft_to_rank', false);
$response = $this->get('/api/flights/' . $flight->id, [], $user); $response = $this->get('/api/flights/' . $flight->id, [], $user);
$body = $response->json();
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(2, $response->json()['subfleets']); $this->assertCount(2, $response->json()['data']['subfleets']);
/* /*
* Now make sure it's filtered out * Now make sure it's filtered out
@@ -182,22 +181,22 @@ class UserTest extends TestCase
*/ */
$response = $this->get('/api/flights/' . $flight->id, [], $user); $response = $this->get('/api/flights/' . $flight->id, [], $user);
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(1, $response->json()['subfleets']); $this->assertCount(1, $response->json()['data']['subfleets']);
/** /**
* Make sure it's filtered out from the flight list * Make sure it's filtered out from the flight list
*/ */
$response = $this->get('/api/flights', [], $user); $response = $this->get('/api/flights', [], $user);
$body = $response->json(); $body = $response->json()['data'];
$response->assertStatus(200); $response->assertStatus(200);
$this->assertCount(1, $body['data'][0]['subfleets']); $this->assertCount(1, $body[0]['subfleets']);
/** /**
* Filtered from search? * Filtered from search?
*/ */
$response = $this->get('/api/flights/search?flight_id=' . $flight->id, [], $user); $response = $this->get('/api/flights/search?flight_id=' . $flight->id, [], $user);
$response->assertStatus(200); $response->assertStatus(200);
$body = $response->json(); $body = $response->json()['data'];
$this->assertCount(1, $body['data'][0]['subfleets']); $this->assertCount(1, $body[0]['subfleets']);
} }
} }