You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.5 KiB
99 lines
3.5 KiB
<?php
|
|
|
|
namespace Tests\Unit\Models;
|
|
|
|
use App\Entities\Invoices\Invoice;
|
|
use App\Entities\Partners\Customer;
|
|
use App\Entities\Payments\Payment;
|
|
use App\Entities\Projects\Project;
|
|
use App\Entities\Subscriptions\Subscription;
|
|
use Illuminate\Support\Collection;
|
|
use Tests\TestCase as TestCase;
|
|
|
|
class CustomerTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function a_customer_has_many_projects()
|
|
{
|
|
$customer = factory(Customer::class)->create();
|
|
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
|
|
|
|
$this->assertInstanceOf(Collection::class, $customer->projects);
|
|
$this->assertInstanceOf(Project::class, $customer->projects->first());
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_many_payments_relation()
|
|
{
|
|
$customer = factory(Customer::class)->create();
|
|
$payment = factory(Payment::class)->create(['partner_id' => $customer->id]);
|
|
|
|
$this->assertInstanceOf(Collection::class, $customer->payments);
|
|
$this->assertInstanceOf(Payment::class, $customer->payments->first());
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_many_subscriptions_relation()
|
|
{
|
|
$customer = factory(Customer::class)->create();
|
|
$subscription = factory(Subscription::class)->create(['customer_id' => $customer->id]);
|
|
|
|
$this->assertInstanceOf(Collection::class, $customer->subscriptions);
|
|
$this->assertInstanceOf(Subscription::class, $customer->subscriptions->first());
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_many_invoices_through_projects_relation()
|
|
{
|
|
$customer = factory(Customer::class)->create();
|
|
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
|
|
$invoice = factory(Invoice::class)->create(['project_id' => $project->id]);
|
|
|
|
$this->assertInstanceOf(Collection::class, $customer->invoices);
|
|
$this->assertInstanceOf(Invoice::class, $customer->invoices->first());
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_name_link_method()
|
|
{
|
|
$customer = factory(Customer::class)->make();
|
|
$this->assertEquals(
|
|
link_to_route('customers.show', $customer->name, [$customer->id], [
|
|
'title' => trans(
|
|
'app.show_detail_title',
|
|
['name' => $customer->name, 'type' => trans('customer.customer')]
|
|
),
|
|
]), $customer->nameLink()
|
|
);
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_status_attribute()
|
|
{
|
|
$customer = factory(Customer::class)->make(['is_active' => 1]);
|
|
|
|
$this->assertEquals(1, $customer->is_active);
|
|
$this->assertEquals(trans('app.active'), $customer->status);
|
|
|
|
$customer = factory(Customer::class)->make(['is_active' => 0]);
|
|
|
|
$this->assertEquals(0, $customer->is_active);
|
|
$this->assertEquals(trans('app.in_active'), $customer->status);
|
|
}
|
|
|
|
/** @test */
|
|
public function a_customer_has_status_label_attribute()
|
|
{
|
|
$customer = factory(Customer::class)->make(['is_active' => 1]);
|
|
|
|
$this->assertEquals(1, $customer->is_active);
|
|
$activeLabel = '<span class="badge" style="background-color: #337ab7">'.trans('app.active').'</span>';
|
|
$this->assertEquals($activeLabel, $customer->status_label);
|
|
|
|
$customer = factory(Customer::class)->make(['is_active' => 0]);
|
|
|
|
$this->assertEquals(0, $customer->is_active);
|
|
$inActiveLabel = '<span class="badge">'.trans('app.in_active').'</span>';
|
|
$this->assertEquals($inActiveLabel, $customer->status_label);
|
|
}
|
|
}
|