Browse Source

Change project customer relation from User to Customer class

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
dda56284e2
  1. 3
      app/Entities/Projects/Project.php
  2. 3
      database/factories/ModelFactory.php
  3. 2
      resources/views/projects/partials/project-show.blade.php
  4. 29
      tests/Unit/Models/ProjectTest.php

3
app/Entities/Projects/Project.php

@ -3,6 +3,7 @@
namespace App\Entities\Projects; namespace App\Entities\Projects;
use App\Entities\Invoices\Invoice; use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer;
use App\Entities\Payments\Payment; use App\Entities\Payments\Payment;
use App\Entities\Projects\ProjectPresenter; use App\Entities\Projects\ProjectPresenter;
use App\Entities\Projects\Task; use App\Entities\Projects\Task;
@ -62,7 +63,7 @@ class Project extends Model
public function customer() public function customer()
{ {
return $this->belongsTo(User::class, 'customer_id');
return $this->belongsTo(Customer::class);
} }
public function cashInTotal() public function cashInTotal()

3
database/factories/ModelFactory.php

@ -1,6 +1,7 @@
<?php <?php
use App\Entities\Invoices\Invoice; use App\Entities\Invoices\Invoice;
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;
@ -38,7 +39,7 @@ $factory->define(Project::class, function (Faker\Generator $faker) {
return factory(User::class)->create()->id; return factory(User::class)->create()->id;
}, },
'customer_id' => function () { 'customer_id' => function () {
return factory(User::class)->create()->id;
return factory(Customer::class)->create()->id;
}, },
]; ];
}); });

2
resources/views/projects/partials/project-show.blade.php

@ -16,7 +16,7 @@
<td> <td>
{{ $project->present()->customerNameAndEmail }} {{ $project->present()->customerNameAndEmail }}
@if ($project->customer_id && auth()->id() == $project->owner_id) @if ($project->customer_id && auth()->id() == $project->owner_id)
{!! link_to_route('users.edit', 'Edit', [$project->customer_id], ['title' => 'Edit Data Customer']) !!}
{!! link_to_route('users.edit', trans('app.edit'), [$project->customer_id], ['title' => trans('customer.edit')]) !!}
@endif @endif
</td> </td>
</tr> </tr>

29
tests/Unit/Models/ProjectTest.php

@ -2,6 +2,7 @@
namespace Tests\Unit\Models; namespace Tests\Unit\Models;
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;
@ -14,7 +15,7 @@ use Tests\TestCase;
class ProjectTest extends TestCase class ProjectTest extends TestCase
{ {
/** @test */ /** @test */
public function it_has_many_features()
public function a_project_has_many_features()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$feature = factory(Feature::class)->create(['project_id' => $project->id]); $feature = factory(Feature::class)->create(['project_id' => $project->id]);
@ -23,7 +24,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_many_main_features()
public function a_project_has_many_main_features()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 1]); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 1]);
@ -32,7 +33,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_many_additional_features()
public function a_project_has_many_additional_features()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]);
@ -41,7 +42,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_feature_tasks()
public function a_project_has_feature_tasks()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]);
@ -51,7 +52,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_many_payments()
public function a_project_has_many_payments()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$payment = factory(Payment::class)->create(['project_id' => $project->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id]);
@ -60,7 +61,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_many_subscriptions()
public function a_project_has_many_subscriptions()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$subscription = factory(Subscription::class)->create(['project_id' => $project->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]);
@ -69,14 +70,14 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_belongs_to_a_customer()
public function a_project_belongs_to_a_customer()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$this->assertTrue($project->customer instanceof User);
$this->assertTrue($project->customer instanceof Customer);
} }
/** @test */ /** @test */
public function it_has_cash_in_total_method()
public function a_project_has_cash_in_total_method()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 1, 'amount' => 20000]); $payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 1, 'amount' => 20000]);
@ -84,7 +85,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_cash_out_total_method()
public function a_project_has_cash_out_total_method()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 0, 'amount' => 10000]); $payments = factory(Payment::class, 2)->create(['project_id' => $project->id, 'in_out' => 0, 'amount' => 10000]);
@ -93,7 +94,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_feature_overall_progress_method()
public function a_project_has_feature_overall_progress_method()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
@ -113,7 +114,7 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_returns_0_on_feature_overall_progress_method_if_all_feature_is_free()
public function a_project_returns_0_on_feature_overall_progress_method_if_all_feature_is_free()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
@ -126,14 +127,14 @@ class ProjectTest extends TestCase
} }
/** @test */ /** @test */
public function it_has_many_files()
public function a_project_has_many_files()
{ {
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$this->assertTrue($project->files instanceof Collection); $this->assertTrue($project->files instanceof Collection);
} }
/** @test */ /** @test */
public function it_has_name_link_method()
public function a_project_has_name_link_method()
{ {
$project = factory(Project::class)->make(); $project = factory(Project::class)->make();
$this->assertEquals(link_to_route('projects.show', $project->name, [$project->id]), $project->nameLink()); $this->assertEquals(link_to_route('projects.show', $project->name, [$project->id]), $project->nameLink());

Loading…
Cancel
Save