osb/tests/Feature/ServiceTest.php
2020-12-02 21:55:15 +11:00

101 lines
5.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Product;
use App\Models\Service;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class ServiceTest extends TestCase
{
/**
* Test billing calculations
*
* @return void
*/
public function testBilling()
{
// Test Weekly Billing
$o = factory(Service::class)->states('week')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Weekly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Weekly Equals 1');
$o = factory(Service::class)->states('week-mid')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Weekly Mid Equals 0.57');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(0.57,$o->invoice_next_quantity,'Weekly Mid Equals 0.57');
// Test Monthly Billing
$o = factory(Service::class)->states('month')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Monthly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Monthly Equals 1');
$o = factory(Service::class)->states('month-mid')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Monthly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEqualsWithDelta(round((Carbon::now()->addMonth()->daysInMonth/2)/Carbon::now()->addMonth()->daysInMonth,2),$o->invoice_next_quantity,.03,'Monthly Mid Equals 0.5');
// Test Quarterly Billing
$o = factory(Service::class)->states('quarter')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Quarterly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Quarterly Equals 1');
$o = factory(Service::class)->states('quarter-mid')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Quarterly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEqualsWithDelta(0.5,$o->invoice_next_quantity,.02,'Quarterly Mid Equals 0.5');
// Test Half Year Billing
$o = factory(Service::class)->states('half')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Half Yearly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Half Yearly Equals 1');
$o = factory(Service::class)->states('half-mid')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Half Yearly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEqualsWithDelta(0.5,$o->invoice_next_quantity,.02,'Half Yearly Mid Equals 0.5');
// Test Year Billing
$o = factory(Service::class)->states('year')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Yearly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Yearly Equals 1');
$o = factory(Service::class)->states('year-mid')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Yearly Equals 1');
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(0.5,$o->invoice_next_quantity,'Yearly Mid Equals 0.5');
// Test 2 Year Billing (price_recurr_strict ignored)
$o = factory(Service::class)->states('2year')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Two Yearly Equals 1');
//$o->setRelation('product',factory(Product::class)->states('strict')->make());
//$this->assertEquals(1,$o->invoice_next_quantity,'Two Yearly Equals 1');
// Test 3 Year Billing (price_recurr_strict ignored)
$o = factory(Service::class)->states('3year')->make();
$o->setRelation('product',factory(Product::class)->states('notstrict')->make());
$this->assertEquals(1,$o->invoice_next_quantity,'Three Yearly Equals 1');
//$o->setRelation('product',factory(Product::class)->states('strict')->make());
//$this->assertEquals(1,$o->invoice_next_quantity,'Three Yearly Equals 1');
}
}