osb/tests/Feature/InvoiceTest.php
2020-02-12 21:32:57 +11:00

33 lines
1.1 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 InvoiceTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function testInvoiceAmount()
{
// Create two services for the same account
// First service was billed a month ago, so this invoice will have 1 service charge
$o = factory(Service::class)->states('next-invoice')->make();
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEquals(110,$o->next_invoice_items(FALSE)->sum('total'),'Invoice Equals 110');
// Second service wasnt billed, connected 1.5 months ago, so invoice will have 2 service charges - 1 x 0.5 month and 1 x full month. and a connection charge
$o = factory(Service::class)->states('new-connect')->make();
$o->setRelation('product',factory(Product::class)->states('strict')->make());
$this->assertEqualsWithDelta(110+110+55+55,$o->next_invoice_items(FALSE)->sum('total'),2.5,'Invoice Equals 220');
}
}