Tests for taxes

This commit is contained in:
David Bomba 2023-03-24 16:43:09 +11:00
parent bba25f1033
commit 49b3182639
2 changed files with 91 additions and 35 deletions

View File

@ -58,40 +58,49 @@ class Response
*
*/
public string $geoPostalCode = "92582";
public string $geoCity = "SAN JACINTO";
public string $geoCounty = "RIVERSIDE";
public string $geoState = "CA";
public float $taxSales = 0.0875;
public float $taxUse = 0.0875;
public string $txbService = "N";
public string $txbFreight = "N";
public float $stateSalesTax = 0.06;
public float $stateUseTax = 0.06;
public float $citySalesTax = 0.01;
public float $cityUseTax = 0.01;
public string $cityTaxCode = "874";
public float $countySalesTax = 0.0025;
public float $countyUseTax = 0.0025;
public string $geoPostalCode = "";
public string $geoCity = "";
public string $geoCounty = "";
public string $geoState = "";
public float $taxSales = 0;
public float $taxUse = 0;
public string $txbService = "";
public string $txbFreight = "";
public float $stateSalesTax = 0;
public float $stateUseTax = 0;
public float $citySalesTax = 0;
public float $cityUseTax = 0;
public string $cityTaxCode = "";
public float $countySalesTax = 0;
public float $countyUseTax = 0;
public string $countyTaxCode = "";
public float $districtSalesTax = 0.015;
public float $districtUseTax = 0.015;
public string $district1Code = "26";
public float $districtSalesTax = 0;
public float $districtUseTax = 0;
public string $district1Code = "";
public float $district1SalesTax = 0;
public float $district1UseTax = 0;
public string $district2Code = "26";
public float $district2SalesTax = 0.005;
public float $district2UseTax = 0.005;
public string $district2Code = "";
public float $district2SalesTax = 0;
public float $district2UseTax = 0;
public string $district3Code = "";
public float $district3SalesTax = 0;
public float $district3UseTax = 0;
public string $district4Code = "33";
public float $district4SalesTax = 0.01;
public float $district4UseTax = 0.01;
public string $district4Code = "";
public float $district4SalesTax = 0;
public float $district4UseTax = 0;
public string $district5Code = "";
public float $district5SalesTax = 0;
public float $district5UseTax = 0;
public string $originDestination = "D";
public string $originDestination = "";
public function __construct(?array $data)
{
foreach($data as $key => $value){
$this->{$key} = $value;
}
}
}

View File

@ -13,7 +13,12 @@ namespace Tests\Unit\Tax;
use Tests\TestCase;
use App\Models\Client;
use App\Models\Invoice;
use Tests\MockAccountData;
use App\DataMapper\Tax\ClientTaxData;
use App\DataMapper\Tax\CompanyTaxData;
use App\DataMapper\Tax\InvoiceTaxData;
use App\DataMapper\Tax\ZipTax\Response;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -25,7 +30,9 @@ class SumTaxTest extends TestCase
use MockAccountData;
use DatabaseTransactions;
public array $response = [
public Response $response;
public array $resp = [
"geoPostalCode" => "92582",
"geoCity" => "SAN JACINTO",
"geoCounty" => "RIVERSIDE",
@ -74,39 +81,79 @@ class SumTaxTest extends TestCase
$this->withoutExceptionHandling();
$this->makeTestData();
$this->response = new Response($this->resp);
}
public function testTaxOnInvoice()
public function testTaxOnCompany()
{
$tax_class = new CompanyTaxData($this->response);
$this->company->tax_data = $tax_class;
$this->company->save();
$this->assertEquals("92582", $this->company->tax_data->origin->geoPostalCode);
$this->assertEquals(0.0875, $this->company->tax_data->origin->taxSales);
}
public function testTaxOnClient()
{
$c = Client::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
]);
$tax_class = new ClientTaxData($this->response, $this->response);
$c->tax_data = $this->response;
$c->tax_data = $tax_class;
$c->save();
$this->assertEquals("92582", $c->tax_data->geoPostalCode);
$this->assertEquals(0.0875, $c->tax_data->taxSales);
$this->assertEquals("92582", $c->tax_data->origin->geoPostalCode);
$this->assertEquals(0.0875, $c->tax_data->origin->taxSales);
}
public function testTaxOnInvoice()
{
$i = Invoice::factory()->create([
'company_id' => $this->company->id,
'client_id' => $this->client->id,
'user_id' => $this->user->id,
]);
$tax_class = new InvoiceTaxData($this->response);
$i->tax_data = $tax_class;
$i->save();
$this->assertEquals("92582", $i->tax_data->origin->geoPostalCode);
$this->assertEquals(0.0875, $i->tax_data->origin->taxSales);
}
public function testSumOfInvoice()
{
$this->assertEquals("CA", $this->response['geoState']);
$this->assertEquals("CA", $this->response->geoState);
}
public function testSumOfTaxes()
{
$sum =
$this->response['stateSalesTax'] +
$this->response->stateSalesTax +
// $this->response['stateUseTax'] +
$this->response['citySalesTax'] +
$this->response->citySalesTax +
// $this->response['cityUseTax'] +
$this->response['countySalesTax'] +
$this->response->countySalesTax +
// $this->response['countyUseTax'] +
$this->response['districtSalesTax'];
$this->response->districtSalesTax;
// // $this->response['districtUseTax'] +
// $this->response['district1SalesTax'] +
// // $this->response['district1UseTax'] +