Browse Source

Set vendor relation in Subscription model to Vendor model

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
cc071899a1
  1. 2
      app/Entities/Subscriptions/Subscription.php
  2. 4
      database/factories/ModelFactory.php
  3. 5
      tests/Feature/ManageSubscriptionsTest.php
  4. 7
      tests/Unit/Models/SubscriptionTest.php

2
app/Entities/Subscriptions/Subscription.php

@ -19,7 +19,7 @@ class Subscription extends Model
public function vendor()
{
return $this->belongsTo('App\Entities\Partners\Customer');
return $this->belongsTo('App\Entities\Partners\Vendor');
}
public function status()

4
database/factories/ModelFactory.php

@ -1,7 +1,7 @@
<?php
use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Feature;
use App\Entities\Projects\Project;
use App\Entities\Projects\Task;
@ -37,7 +37,7 @@ $factory->define(Subscription::class, function (Faker\Generator $faker) {
'due_date' => $startDate->addYears(1)->format('Y-m-d'),
'remark' => $faker->paragraph,
'vendor_id' => function () {
return factory(Customer::class)->create()->id;
return factory(Vendor::class)->create()->id;
},
];
});

5
tests/Feature/ManageSubscriptionsTest.php

@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Project;
use App\Entities\Subscriptions\Subscription;
use Tests\TestCase;
@ -13,7 +14,7 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_entry_subscription()
{
$user = $this->adminUserSigningIn();
$vendor = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]);
$customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]);
@ -52,7 +53,7 @@ class ManageSubscriptionsTest extends TestCase
{
$eppCode = str_random(10);
$user = $this->adminUserSigningIn();
$vendor = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]);
$customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]);
$project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]);

7
tests/Unit/Models/SubscriptionTest.php

@ -2,7 +2,7 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Project;
use App\Entities\Subscriptions\Subscription;
use Tests\TestCase as TestCase;
@ -27,6 +27,9 @@ class SubscriptionTest extends TestCase
public function it_has_vendor_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue($subscription->vendor instanceof Customer);
$this->assertTrue(
$subscription->vendor instanceof Vendor,
'A subscription must belongs to a App\Entities\Partners\Vendor model as it\'s vendor.'
);
}
}
Loading…
Cancel
Save