2017-12-12 12:05:22 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test API calls and authentication, etc
|
|
|
|
*/
|
|
|
|
class ApiTest extends TestCase
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->addData('base');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure authentication against the API works
|
|
|
|
*/
|
|
|
|
public function testApiAuthentication()
|
|
|
|
{
|
2017-12-13 11:50:55 +08:00
|
|
|
$airport = factory(App\Models\Airport::class)->create();
|
|
|
|
|
|
|
|
$uri = '/api/airports/' . $airport->icao;
|
2017-12-12 12:05:22 +08:00
|
|
|
|
|
|
|
// Missing auth header
|
|
|
|
$this->get($uri)->assertStatus(401);
|
|
|
|
|
|
|
|
// Test invalid API key
|
|
|
|
$this->withHeaders(['Authorization' => 'invalidKey'])->get($uri)
|
|
|
|
->assertStatus(401);
|
|
|
|
|
|
|
|
// Test upper/lower case of Authorization header, etc
|
2017-12-13 10:14:01 +08:00
|
|
|
$this->withHeaders($this->apiHeaders())->get($uri)
|
2017-12-12 12:05:22 +08:00
|
|
|
->assertStatus(200)
|
2017-12-13 11:50:55 +08:00
|
|
|
->assertJson(['icao' => $airport->icao], true);
|
2017-12-12 12:05:22 +08:00
|
|
|
|
2017-12-13 10:14:01 +08:00
|
|
|
$this->withHeaders(['AUTHORIZATION' => 'testadminapikey'])->get($uri)
|
2017-12-12 12:05:22 +08:00
|
|
|
->assertStatus(200)
|
2017-12-13 11:50:55 +08:00
|
|
|
->assertJson(['icao' => $airport->icao], true);
|
2017-12-12 12:05:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure the airport data is returned
|
|
|
|
*/
|
|
|
|
public function testAirportRequest()
|
|
|
|
{
|
2017-12-13 11:50:55 +08:00
|
|
|
$airport = factory(App\Models\Airport::class)->create();
|
|
|
|
|
|
|
|
$this->withHeaders($this->apiHeaders())->get('/api/airports/' . $airport->icao)
|
2017-12-12 12:05:22 +08:00
|
|
|
->assertStatus(200)
|
2017-12-13 11:50:55 +08:00
|
|
|
->assertJson(['icao' => $airport->icao], true);
|
2017-12-12 12:05:22 +08:00
|
|
|
|
2017-12-13 10:14:01 +08:00
|
|
|
$this->withHeaders($this->apiHeaders())->get('/api/airports/UNK')
|
2017-12-12 12:05:22 +08:00
|
|
|
->assertStatus(404);
|
|
|
|
}
|
|
|
|
}
|