Browse Source

Pass all test after project customer relation changed to Customer model

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
2c6041e502
  1. 9
      app/Entities/BaseRepository.php
  2. 6
      app/Entities/Projects/ProjectPresenter.php
  3. 16
      app/Entities/Projects/ProjectsRepository.php
  4. 18
      app/Entities/Subscriptions/Subscription.php
  5. 5
      database/factories/ModelFactory.php
  6. 2
      resources/lang/id/app.php
  7. 48
      tests/Feature/ManageProjectsTest.php
  8. 10
      tests/Feature/ManageSubscriptionsTest.php
  9. 32
      tests/Unit/Models/SubscriptionTest.php

9
app/Entities/BaseRepository.php

@ -2,6 +2,8 @@
namespace App\Entities; namespace App\Entities;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Feature; use App\Entities\Projects\Feature;
use App\Entities\Projects\Project; use App\Entities\Projects\Project;
use App\Entities\Users\User; use App\Entities\Users\User;
@ -9,11 +11,12 @@ use App\Entities\Users\User;
/** /**
* Base Repository Class * Base Repository Class
*/ */
abstract class BaseRepository extends EloquentRepository {
abstract class BaseRepository extends EloquentRepository
{
public function getCustomersList() public function getCustomersList()
{ {
return User::orderBy('name')->hasRoles(['customer'])->pluck('name','id');
return Customer::orderBy('name')->pluck('name', 'id');
} }
public function getCustomersAndVendorsList() public function getCustomersAndVendorsList()
@ -28,7 +31,7 @@ abstract class BaseRepository extends EloquentRepository {
public function getVendorsList() public function getVendorsList()
{ {
return User::orderBy('name')->hasRoles(['vendor'])->pluck('name','id');
return Vendor::orderBy('name')->pluck('name', 'id');
} }
public function getProjectsList() public function getProjectsList()

6
app/Entities/Projects/ProjectPresenter.php

@ -23,12 +23,14 @@ class ProjectPresenter extends Presenter
public function workDuration() public function workDuration()
{ {
if (is_null($this->entity->end_date))
if (is_null($this->entity->end_date)) {
return '-'; return '-';
}
$workDuration = dateDifference($this->entity->start_date, $this->entity->end_date); $workDuration = dateDifference($this->entity->start_date, $this->entity->end_date);
if ((int) $workDuration > 30)
if ((int) $workDuration > 30) {
return dateDifference($this->entity->start_date, $this->entity->end_date, '%m Bulan %d Hari'); return dateDifference($this->entity->start_date, $this->entity->end_date, '%m Bulan %d Hari');
}
return $workDuration.' Hari'; return $workDuration.' Hari';
} }

16
app/Entities/Projects/ProjectsRepository.php

@ -3,9 +3,8 @@
namespace App\Entities\Projects; namespace App\Entities\Projects;
use App\Entities\BaseRepository; use App\Entities\BaseRepository;
use App\Entities\Users\User;
use App\Entities\Partners\Customer;
use DB; use DB;
use Option;
/** /**
* Projects Repository Class * Projects Repository Class
@ -26,8 +25,10 @@ class ProjectsRepository extends BaseRepository
return $this->model->latest() return $this->model->latest()
->where(function ($query) use ($q, $statusId, $statusIds) { ->where(function ($query) use ($q, $statusId, $statusIds) {
$query->where('name', 'like', '%'.$q.'%'); $query->where('name', 'like', '%'.$q.'%');
if ($statusId && in_array($statusId, $statusIds))
if ($statusId && in_array($statusId, $statusIds)) {
$query->where('status_id', $statusId); $query->where('status_id', $statusId);
}
}) })
->withCount('payments') ->withCount('payments')
->with('customer') ->with('customer')
@ -60,13 +61,11 @@ class ProjectsRepository extends BaseRepository
public function createNewCustomer($customerName, $customerEmail) public function createNewCustomer($customerName, $customerEmail)
{ {
$newCustomer = new User;
$newCustomer = new Customer;
$newCustomer->name = $customerName; $newCustomer->name = $customerName;
$newCustomer->email = $customerEmail; $newCustomer->email = $customerEmail;
$newCustomer->password = Option::get('default_password', 'member');
$newCustomer->remember_token = str_random(10);
$newCustomer->save(); $newCustomer->save();
$newCustomer->assignRole('customer');
return $newCustomer; return $newCustomer;
} }
@ -97,8 +96,9 @@ class ProjectsRepository extends BaseRepository
{ {
return Feature::where(function ($query) use ($projectId, $type) { return Feature::where(function ($query) use ($projectId, $type) {
$query->whereProjectId($projectId); $query->whereProjectId($projectId);
if ($type)
if ($type) {
$query->whereTypeId($type); $query->whereTypeId($type);
}
})->orderBy('position')->with('worker', 'tasks')->get(); })->orderBy('position')->with('worker', 'tasks')->get();
} }

18
app/Entities/Subscriptions/Subscription.php

@ -2,37 +2,33 @@
namespace App\Entities\Subscriptions; namespace App\Entities\Subscriptions;
use App\Entities\Projects\Project;
use App\Entities\Subscriptions\SubscriptionPresenter;
use App\Entities\Users\User;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait; use Laracasts\Presenter\PresentableTrait;
class Subscription extends Model {
class Subscription extends Model
{
use PresentableTrait; use PresentableTrait;
protected $presenter = SubscriptionPresenter::class;
protected $presenter = 'App\Entities\Subscriptions\SubscriptionPresenter';
protected $guarded = ['id', 'created_at', 'updated_at']; protected $guarded = ['id', 'created_at', 'updated_at'];
public function project() public function project()
{ {
return $this->belongsTo(Project::class);
return $this->belongsTo('App\Entities\Projects\Project');
} }
public function customer() public function customer()
{ {
return $this->belongsTo(User::class,'customer_id');
return $this->belongsTo('App\Entities\Partners\Customer');
} }
public function vendor() public function vendor()
{ {
return $this->belongsTo(User::class,'vendor_id');
return $this->belongsTo('App\Entities\Partners\Vendor', 'vendor_id');
} }
public function status() public function status()
{ {
return $this->status_id ? 'Aktif' : 'Non Aktif';
return $this->status_id ? trans('app.active') : trans('app.in_active');
} }
} }

5
database/factories/ModelFactory.php

@ -2,6 +2,7 @@
use App\Entities\Invoices\Invoice; use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer; use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Payments\Payment; use App\Entities\Payments\Payment;
use App\Entities\Projects\Feature; use App\Entities\Projects\Feature;
use App\Entities\Projects\Project; use App\Entities\Projects\Project;
@ -82,10 +83,10 @@ $factory->define(Subscription::class, function (Faker\Generator $faker) {
'due_date' => $startDate->addYears(1)->format('Y-m-d'), 'due_date' => $startDate->addYears(1)->format('Y-m-d'),
'remark' => $faker->paragraph, 'remark' => $faker->paragraph,
'customer_id' => function () { 'customer_id' => function () {
return factory(User::class)->create()->id;
return factory(Customer::class)->create()->id;
}, },
'vendor_id' => function () { 'vendor_id' => function () {
return factory(User::class)->create()->id;
return factory(Vendor::class)->create()->id;
}, },
]; ];
}); });

2
resources/lang/id/app.php

@ -39,4 +39,6 @@ return [
'change_photo' => 'Ganti Foto', 'change_photo' => 'Ganti Foto',
'welcome' => 'Selamat Datang', 'welcome' => 'Selamat Datang',
'to' => 'Kepada', 'to' => 'Kepada',
'active' => 'Aktif',
'in_active' => 'Non Aktif',
]; ];

48
tests/Feature/ManageProjectsTest.php

@ -2,11 +2,11 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Payments\Payment; use App\Entities\Payments\Payment;
use App\Entities\Projects\Feature; use App\Entities\Projects\Feature;
use App\Entities\Projects\Project; use App\Entities\Projects\Project;
use App\Entities\Projects\Task; use App\Entities\Projects\Task;
use App\Entities\Users\User;
use Tests\TestCase; use Tests\TestCase;
class ManageProjectsTest extends TestCase class ManageProjectsTest extends TestCase
@ -14,18 +14,15 @@ class ManageProjectsTest extends TestCase
/** @test */ /** @test */
public function admin_can_input_new_project_with_existing_customer() public function admin_can_input_new_project_with_existing_customer()
{ {
$users = factory(User::class, 2)->create();
$users[0]->assignRole('admin');
$this->actingAs($users[0]);
$users[1]->assignRole('customer');
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$this->visit(route('projects.index')); $this->visit(route('projects.index'));
$this->seePageIs(route('projects.index')); $this->seePageIs(route('projects.index'));
$this->click(trans('project.create')); $this->click(trans('project.create'));
$this->seePageIs(route('projects.create')); $this->seePageIs(route('projects.create'));
$this->type('Project Baru', 'name'); $this->type('Project Baru', 'name');
$this->select($users[1]->id, 'customer_id');
$this->select($customer->id, 'customer_id');
$this->type('2016-04-15', 'proposal_date'); $this->type('2016-04-15', 'proposal_date');
$this->type('2000000', 'proposal_value'); $this->type('2000000', 'proposal_value');
$this->type('Deskripsi project baru', 'description'); $this->type('Deskripsi project baru', 'description');
@ -59,11 +56,19 @@ class ManageProjectsTest extends TestCase
$this->type('Customer Baru', 'customer_name'); $this->type('Customer Baru', 'customer_name');
$this->type('email@customer.baru', 'customer_email'); $this->type('email@customer.baru', 'customer_email');
$this->press(trans('project.create')); $this->press(trans('project.create'));
$this->see(trans('project.created')); $this->see(trans('project.created'));
$this->see('Project Baru'); $this->see('Project Baru');
$this->seeInDatabase('users', ['name' => 'Customer Baru', 'email' => 'email@customer.baru']);
$newCustomer = User::whereName('Customer Baru')->whereEmail('email@customer.baru')->first();
$this->seeInDatabase('projects', ['name' => 'Project Baru', 'proposal_value' => '2000000', 'customer_id' => $newCustomer->id]);
$this->seeInDatabase('customers', [
'name' => 'Customer Baru',
'email' => 'email@customer.baru',
]);
$newCustomer = Customer::whereName('Customer Baru')->whereEmail('email@customer.baru')->first();
$this->seeInDatabase('projects', [
'name' => 'Project Baru',
'proposal_value' => '2000000',
'customer_id' => $newCustomer->id,
]);
} }
/** @test */ /** @test */
@ -105,12 +110,9 @@ class ManageProjectsTest extends TestCase
/** @test */ /** @test */
public function admin_can_edit_a_project() public function admin_can_edit_a_project()
{ {
$users = factory(User::class, 2)->create();
$users[0]->assignRole('admin');
$this->actingAs($users[0]);
$project = factory(Project::class)->create(['owner_id' => $users[0]->id]);
$users[1]->assignRole('customer');
$user = $this->adminUserSigningIn();
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create(['owner_id' => $user->id]);
$this->visit('projects/'.$project->id.'/edit'); $this->visit('projects/'.$project->id.'/edit');
$this->seePageIs('projects/'.$project->id.'/edit'); $this->seePageIs('projects/'.$project->id.'/edit');
@ -122,7 +124,7 @@ class ManageProjectsTest extends TestCase
$this->type(2000000, 'proposal_value'); $this->type(2000000, 'proposal_value');
$this->type(2000000, 'project_value'); $this->type(2000000, 'project_value');
$this->select(4, 'status_id'); $this->select(4, 'status_id');
$this->select($users[1]->id, 'customer_id');
$this->select($customer->id, 'customer_id');
$this->type('Edit deskripsi project', 'description'); $this->type('Edit deskripsi project', 'description');
$this->press(trans('project.update')); $this->press(trans('project.update'));
@ -132,7 +134,7 @@ class ManageProjectsTest extends TestCase
'proposal_date' => '2016-04-15', 'proposal_date' => '2016-04-15',
'start_date' => '2016-04-25', 'start_date' => '2016-04-25',
'end_date' => '2016-05-05', 'end_date' => '2016-05-05',
'customer_id' => $users[1]->id,
'customer_id' => $customer->id,
'description' => 'Edit deskripsi project', 'description' => 'Edit deskripsi project',
]); ]);
} }
@ -140,18 +142,16 @@ class ManageProjectsTest extends TestCase
/** @test */ /** @test */
public function form_is_validated_on_invalid_project_entry() public function form_is_validated_on_invalid_project_entry()
{ {
$users = factory(User::class, 2)->create();
$users[0]->assignRole('admin');
$this->actingAs($users[0]);
$user = $this->adminUserSigningIn();
$users[1]->assignRole('customer');
$customer = factory(Customer::class)->create();
$this->visit(route('projects.index')); $this->visit(route('projects.index'));
$this->seePageIs(route('projects.index')); $this->seePageIs(route('projects.index'));
$this->click(trans('project.create')); $this->click(trans('project.create'));
$this->seePageIs(route('projects.create')); $this->seePageIs(route('projects.create'));
$this->type('', 'name'); $this->type('', 'name');
$this->select($users[1]->id, 'customer_id');
$this->select($customer->id, 'customer_id');
$this->type('2016-04-15aa', 'proposal_date'); $this->type('2016-04-15aa', 'proposal_date');
$this->type('', 'proposal_value'); $this->type('', 'proposal_value');
$this->type('Deskripsi project baru', 'description'); $this->type('Deskripsi project baru', 'description');
@ -164,8 +164,8 @@ class ManageProjectsTest extends TestCase
public function admin_can_update_project_status_on_project_detail_page() public function admin_can_update_project_status_on_project_detail_page()
{ {
$user = $this->adminUserSigningIn(); $user = $this->adminUserSigningIn();
$project = factory(Project::class)->create(['owner_id' => $user->id, 'status_id' => 1]); $project = factory(Project::class)->create(['owner_id' => $user->id, 'status_id' => 1]);
$this->visit(route('projects.show', $project->id)); $this->visit(route('projects.show', $project->id));
$this->seePageIs(route('projects.show', $project->id)); $this->seePageIs(route('projects.show', $project->id));
$this->select(2, 'status_id'); $this->select(2, 'status_id');

10
tests/Feature/ManageSubscriptionsTest.php

@ -2,6 +2,8 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Projects\Project; use App\Entities\Projects\Project;
use App\Entities\Subscriptions\Subscription; use App\Entities\Subscriptions\Subscription;
use Tests\TestCase; use Tests\TestCase;
@ -12,9 +14,9 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_entry_subscription() public function admin_can_entry_subscription()
{ {
$user = $this->adminUserSigningIn(); $user = $this->adminUserSigningIn();
$vendor = $this->createUser('vendor');
$vendor = factory(Vendor::class)->create();
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$customer = $this->createUser('customer');
$customer = factory(Customer::class)->create();
$this->visit(route('subscriptions.index')); $this->visit(route('subscriptions.index'));
$this->click(trans('subscription.create')); $this->click(trans('subscription.create'));
@ -52,10 +54,10 @@ class ManageSubscriptionsTest extends TestCase
public function admin_can_edit_subscription_data() public function admin_can_edit_subscription_data()
{ {
$user = $this->adminUserSigningIn(); $user = $this->adminUserSigningIn();
$vendor = $this->createUser('vendor');
$vendor = factory(Vendor::class)->create();
$eppCode = str_random(10); $eppCode = str_random(10);
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$customer = $this->createUser('customer');
$customer = factory(Customer::class)->create();
$subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]); $subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]);

32
tests/Unit/Models/SubscriptionTest.php

@ -0,0 +1,32 @@
<?php
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Partners\Vendor;
use App\Entities\Subscriptions\Subscription;
use Tests\TestCase as TestCase;
class SubscriptionTest extends TestCase
{
/** @test */
public function it_has_domain_name_attribute()
{
$subscription = factory(Subscription::class)->create(['domain_name' => 'Subscription 1 Domain Name']);
$this->assertEquals('Subscription 1 Domain Name', $subscription->domain_name);
}
/** @test */
public function it_has_customer_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue($subscription->customer instanceof Customer);
}
/** @test */
public function it_has_vendor_relation()
{
$subscription = factory(Subscription::class)->create();
$this->assertTrue($subscription->vendor instanceof Vendor);
}
}
Loading…
Cancel
Save