-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/more-scout-indexers
- Loading branch information
Showing
12 changed files
with
348 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Lunar\Actions\Taxes; | ||
|
||
use Lunar\Models\TaxZoneCountry; | ||
|
||
class GetTaxZoneCountry | ||
{ | ||
public function execute($countryId) | ||
{ | ||
$taxZone = $this->getZone($countryId); | ||
|
||
if ($taxZone instanceof TaxZoneCountry) { | ||
return $taxZone; | ||
} | ||
|
||
if (!$taxZone) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Return the zone or zones which match this country. | ||
* | ||
* @param int $countryId | ||
* @return TaxZoneCountry|null | ||
*/ | ||
protected function getZone(int $countryId) | ||
{ | ||
return TaxZoneCountry::whereCountryId($countryId)->first(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/core/tests/Unit/Actions/Taxes/GetTaxZoneCountryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Lunar\Tests\Unit\Actions\Taxes; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Lunar\Actions\Taxes\GetTaxZoneCountry; | ||
use Lunar\Models\Country; | ||
use Lunar\Models\TaxZoneCountry; | ||
use Lunar\Tests\TestCase; | ||
|
||
/** | ||
* @group lunar.actions | ||
*/ | ||
class GetTaxZoneCountryTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function can_match_country_id() | ||
{ | ||
$belgium = Country::factory()->create([ | ||
'name' => 'Belgium', | ||
]); | ||
|
||
$uk = Country::factory()->create([ | ||
'name' => 'United Kingdom', | ||
]); | ||
|
||
$taxZoneBelgium = TaxZoneCountry::factory()->create([ | ||
'country_id' => $belgium->id, | ||
]); | ||
|
||
$taxZoneUk = TaxZoneCountry::factory()->create([ | ||
'country_id' => $uk->id, | ||
]); | ||
|
||
$zone = app(GetTaxZoneCountry::class)->execute($uk->id); | ||
|
||
$this->assertEquals($taxZoneUk->id, $zone->id); | ||
} | ||
|
||
/** @test */ | ||
public function can_mismatch_country_id() | ||
{ | ||
$belgium = Country::factory()->create([ | ||
'name' => 'Belgium', | ||
]); | ||
|
||
$uk = Country::factory()->create([ | ||
'name' => 'United Kingdom', | ||
]); | ||
|
||
$taxZoneBelgium = TaxZoneCountry::factory()->create([ | ||
'country_id' => $belgium->id, | ||
]); | ||
|
||
$zone = app(GetTaxZoneCountry::class)->execute($uk->id); | ||
|
||
$this->assertNull($zone); | ||
} | ||
} |
Oops, something went wrong.