Browse Source

Add owner_id on partners table

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
390242da23
  1. 2
      app/Entities/Partners/Partner.php
  2. 7
      app/Entities/Projects/ProjectsRepository.php
  3. 2
      app/Http/Controllers/Partners/PartnersController.php
  4. 6
      database/factories/PartnerFactory.php
  5. 15
      tests/Feature/ManagePartnersTest.php
  6. 3
      tests/Feature/ManageProjectsTest.php
  7. 2
      tests/TestCase.php

2
app/Entities/Partners/Partner.php

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Partner extends Model
{
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'notes', 'is_active'];
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'notes', 'is_active', 'owner_id'];
public function owner()
{

7
app/Entities/Projects/ProjectsRepository.php

@ -61,9 +61,10 @@ class ProjectsRepository extends BaseRepository
public function createNewCustomer($customerName, $customerEmail)
{
$newCustomer = new Partner;
$newCustomer->name = $customerName;
$newCustomer->email = $customerEmail;
$newCustomer = new Partner;
$newCustomer->name = $customerName;
$newCustomer->email = $customerEmail;
$newCustomer->owner_id = auth()->user()->agency->id;
$newCustomer->save();
return $newCustomer;

2
app/Http/Controllers/Partners/PartnersController.php

@ -44,6 +44,8 @@ class PartnersController extends Controller
'notes' => 'nullable|max:255',
]);
$newPartnerData['owner_id'] = auth()->user()->agency->id;
Partner::create($newPartnerData);
flash(trans('partner.created'), 'success');

6
database/factories/PartnerFactory.php

@ -1,11 +1,15 @@
<?php
use App\Entities\Agencies\Agency;
use App\Entities\Partners\Partner;
use Faker\Generator as Faker;
$factory->define(Partner::class, function (Faker $faker) {
return [
'name' => $faker->company,
'name' => $faker->company,
'owner_id' => function () {
return factory(Agency::class)->create()->id;
},
];
});

15
tests/Feature/ManagePartnersTest.php

@ -25,7 +25,7 @@ class ManagePartnersTest extends TestCase
/** @test */
public function user_can_create_a_partner()
{
$this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$this->visit(route('partners.index'));
$this->click(trans('partner.create'));
@ -43,12 +43,13 @@ class ManagePartnersTest extends TestCase
$this->seePageIs(route('partners.index'));
$this->seeInDatabase('partners', [
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => null,
'name' => 'Partner 1 name',
'email' => 'partner1@mail.com',
'phone' => '081234567890',
'pic' => 'Nama PIC Partner',
'address' => 'Alamat partner 1',
'notes' => null,
'owner_id' => $user->agency->id,
]);
}

3
tests/Feature/ManageProjectsTest.php

@ -36,7 +36,7 @@ class ManageProjectsTest extends TestCase
/** @test */
public function admin_can_input_new_project_with_new_partner()
{
$this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$this->visit(route('projects.index'));
$this->seePageIs(route('projects.index'));
@ -68,6 +68,7 @@ class ManageProjectsTest extends TestCase
'name' => 'Project Baru',
'proposal_value' => '2000000',
'customer_id' => $newPartner->id,
'owner_id' => $user->agency->id,
]);
}

2
tests/TestCase.php

@ -2,6 +2,7 @@
namespace Tests;
use App\Entities\Agencies\Agency;
use App\Entities\Users\User;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
use Tests\Traits\DatabaseMigrateSeeds;
@ -23,6 +24,7 @@ abstract class TestCase extends BaseTestCase
protected function adminUserSigningIn()
{
$user = $this->createUser();
factory(Agency::class)->create(['owner_id' => $user->id]);
$this->actingAs($user);
return $user;

Loading…
Cancel
Save