Invoice rendering for service, and unit testing for Invoice Item quantity

This commit is contained in:
Deon George
2020-02-06 18:31:43 +09:00
parent 5f5d114f42
commit ebd4367975
14 changed files with 541 additions and 236 deletions

View File

@@ -1,21 +0,0 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/login');
$response->assertStatus(200);
}
}

View File

@@ -0,0 +1,100 @@
<?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
{
/**
* A basic feature test example.
*
* @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->assertEquals(round(round(Carbon::now()->addMonth()->daysInMonth/2,0)/Carbon::now()->addMonth()->daysInMonth,2),$o->invoice_next_quantity,'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->assertEquals(0.5,$o->invoice_next_quantity,'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');
}
}