Skip to content

Commit

Permalink
Handle SVFR Squawks (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF authored and CalumTowers committed Jan 20, 2019
1 parent f177e08 commit a98f855
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/SquawkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function assignLocalSquawk(Request $request, string $callsign) : JsonResp
$request,
[
'unit' => 'required|alpha',
'rules' => 'required|in:V,I',
'rules' => 'required|in:V,I,S',
]
);

Expand Down
6 changes: 5 additions & 1 deletion app/Services/SquawkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class SquawkService
{
/**
* Constant deemed to mean Any Flight Rules
* Constant deemed to mean Any Flight Rules.
*
* @var String
*/
Expand Down Expand Up @@ -103,6 +103,10 @@ public function assignLocalSquawk(string $callsign, string $unit, string $rules)
throw new InvalidArgumentException('Unit not found');
}

if ($rules === 'S') {
$rules = 'V';
}

$allRanges = $unit->ranges;
$ruleSpecificRanges = $allRanges->where('rules', $rules)->shuffle();
$rangesToUse = ($ruleSpecificRanges->isNotEmpty())
Expand Down
5 changes: 5 additions & 0 deletions tests/app/Services/SquawkServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ public function testItAssignsFlightRuleSpecificLocalSquawks()
$this->assertSame('3762', $this->squawkService->assignLocalSquawk('BAW9AZ', 'EGKA', 'I')->squawk());
}

public function testLocalSquawksTreatsSvfrAsVfr()
{
$this->assertSame('3763', $this->squawkService->assignLocalSquawk('BAW9AZ', 'EGKA', 'S')->squawk());
}

public function testItAuditsWhoAssignsLocalSquawks()
{
$this->squawkService->assignLocalSquawk('BAW9AZ', 'EGKA', 'I');
Expand Down

0 comments on commit a98f855

Please sign in to comment.