diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 2fcf1c6d..a0a1336e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -10,6 +10,9 @@ assignees: '' **Describe the bug** A clear and concise description of what the bug is. +**Version** +Please enter the version + **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' @@ -23,10 +26,5 @@ A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - **Additional context** -Add any other context about the problem here. +Add any other context and attach logs (from `storage/logs/laravel-.log`) diff --git a/app/Database/seeds/settings.yml b/app/Database/seeds/settings.yml index 17332d43..32635a17 100644 --- a/app/Database/seeds/settings.yml +++ b/app/Database/seeds/settings.yml @@ -60,7 +60,7 @@ value: gallons options: 'gallons,l=liters' type: select - description: 'The units for fuel for display' + description: 'The units of volume for display' - key: units.temperature name: 'Temperature Units' group: units diff --git a/app/Services/AirportService.php b/app/Services/AirportService.php index f8f092c2..05d60460 100644 --- a/app/Services/AirportService.php +++ b/app/Services/AirportService.php @@ -26,16 +26,16 @@ class AirportService extends Service * * @return Metar|null */ - public function getMetar($icao): Metar + public function getMetar($icao) { - $metar = null; - $wind = null; - $raw_metar = $this->metarProvider->get_metar($icao); + $icao = trim($icao); + if ($icao === '') { + return; + } + $raw_metar = $this->metarProvider->get_metar($icao); if ($raw_metar && $raw_metar !== '') { return new Metar($raw_metar); } - - return null; } } diff --git a/app/Services/Metar/AviationWeather.php b/app/Services/Metar/AviationWeather.php index 19332750..8c894272 100644 --- a/app/Services/Metar/AviationWeather.php +++ b/app/Services/Metar/AviationWeather.php @@ -35,6 +35,10 @@ class AviationWeather extends Metar */ protected function metar($icao): string { + if ($icao === '') { + return ''; + } + $url = static::METAR_URL.$icao; try { diff --git a/tests/MetarTest.php b/tests/MetarTest.php index 03ddf009..035e73d7 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -1,7 +1,12 @@ settingsRepo = app(SettingRepository::class); } + /** + * @param string $filename + */ + private function mockXmlResponse($filename) + { + $mock = new MockHandler([ + new Response(200, + [ + 'Content-Type' => 'text/xml', + ], + $this->readDataFile($filename) + ), + ]); + + $handler = HandlerStack::create($mock); + $guzzleClient = new Client(['handler' => $handler]); + app()->instance(Client::class, $guzzleClient); + } + /** * Make sure a blank metar doesn't give problems */ @@ -145,4 +169,20 @@ class MetarTest extends TestCase $this->assertEquals('A few at 457 meters; a few at 7620 meters', $metar['clouds_report']); $this->assertEquals('A few at 1500 feet; a few at 25000 feet', $metar['clouds_report_ft']); } + + public function testHttpCallSuccess() + { + $this->mockXmlResponse('aviationweather/kjfk.xml'); + $airportSvc = app(AirportService::class); + + $this->assertInstanceOf(Metar::class, $airportSvc->getMetar('kjfk')); + } + + public function testHttpCallEmpty() + { + $this->mockXmlResponse('aviationweather/empty.xml'); + $airportSvc = app(AirportService::class); + + $this->assertNull($airportSvc->getMetar('idk')); + } } diff --git a/tests/data/aviationweather/empty.xml b/tests/data/aviationweather/empty.xml new file mode 100644 index 00000000..d345c684 --- /dev/null +++ b/tests/data/aviationweather/empty.xml @@ -0,0 +1,13 @@ + + + 26064774 + + + + Invalid station string: station string cannot be empty + + + 0 + diff --git a/tests/data/aviationweather/kjfk.xml b/tests/data/aviationweather/kjfk.xml new file mode 100644 index 00000000..58262799 --- /dev/null +++ b/tests/data/aviationweather/kjfk.xml @@ -0,0 +1,18 @@ + + + 24902199 + + + + + 250 + + + KJFK 042151Z 28026G39KT 10SM FEW055 SCT095 BKN110 BKN230 12/M04 A2958 RMK AO2 + PK WND 27045/2128 PRESRR SLP018 T01221044 + + + +