addData('base'); } protected function getPirep($pirep_id) { $resp = $this->withHeaders($this->apiHeaders()) ->get('/api/pirep/' . $pirep_id); $resp->assertStatus(200); return $resp->json(); } /** * Post a PIREP into a PREFILE state and post ACARS */ public function testAcarsUpdates() { $airport = factory(App\Models\Airport::class)->create(); $airline = factory(App\Models\Airline::class)->create(); $aircraft = factory(App\Models\Aircraft::class)->create(); $uri = '/api/pirep/prefile'; $pirep = [ 'airline_id' => $airline->id, 'aircraft_id' => $aircraft->id, 'dpt_airport_id' => $airport->icao, 'arr_airport_id' => $airport->icao, 'altitude' => 38000, 'planned_flight_time' => 120, 'route' => 'POINTA POINTB', ]; $response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep); $response->assertStatus(201); # Get the PIREP ID $pirep_id = $response->json()['id']; $this->assertNotNull($pirep_id); # Check the PIREP state and status $pirep = $this->getPirep($pirep_id); $this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']); $this->assertEquals(PirepStatus::PREFILE, $pirep['status']); # Post an ACARS update $uri = '/api/pirep/' . $pirep_id . '/acars'; $acars = factory(App\Models\Acars::class)->make()->toArray(); $response = $this->withHeaders($this->apiHeaders())->post($uri, $acars); $response->assertStatus(201); $body = $response->json(); $this->assertNotNull($body['id']); $this->assertEquals($pirep_id, $body['pirep_id']); # Make sure PIREP state moved into ENROUTE $pirep = $this->getPirep($pirep_id); $this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']); $this->assertEquals(PirepStatus::ENROUTE, $pirep['status']); $uri = '/api/pirep/' . $pirep_id . '/acars'; $response = $this->withHeaders($this->apiHeaders())->get($uri); $response->assertStatus(200); $body = $response->json(); $this->assertEquals(1, $this->count($body)); $this->assertEquals($pirep_id, $body[0]['pirep_id']); } public function testNonExistentPirepGet() { $uri = '/api/pirep/DOESNTEXIST/acars'; $response = $this->withHeaders($this->apiHeaders())->get($uri); $response->assertStatus(404); } public function testNonExistentPirepStore() { $uri = '/api/pirep/DOESNTEXIST/acars'; $acars = factory(App\Models\Acars::class)->make()->toArray(); $response = $this->withHeaders($this->apiHeaders())->post($uri, $acars); $response->assertStatus(404); } public function testAcarsIsoDate() { $pirep = factory(App\Models\Pirep::class)->make()->toArray(); $uri = '/api/pirep/prefile'; $response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep); $pirep_id = $response->json()['id']; $dt = date('c'); $uri = '/api/pirep/' . $pirep_id . '/acars'; $acars = factory(App\Models\Acars::class)->make()->toArray(); $acars['sim_time'] = $dt; $response = $this->withHeaders($this->apiHeaders())->post($uri, $acars); $response->assertStatus(201); $uri = '/api/pirep/' . $pirep_id . '/acars'; $response = $this->withHeaders($this->apiHeaders())->get($uri); $response->assertStatus(200); $body = $response->json(); $this->assertEquals($dt, $body[0]['sim_time']); } }