From f5d8ed5b66bbf24b10996e42aae6e57314b61ea4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 29 Oct 2017 11:54:06 +0800 Subject: [PATCH] Add OwnedByAgency trait for Partner model --- app/Entities/Partners/Partner.php | 3 +++ app/Http/Controllers/InvoiceDraftController.php | 5 ++--- resources/views/invoices/show.blade.php | 2 +- tests/Feature/InvoiceEntryTest.php | 6 ++++-- tests/Feature/ManageFeaturesTest.php | 25 ++++++++++++++----------- tests/Feature/ManagePartnersTest.php | 14 +++++++------- tests/Feature/ManageProjectsTest.php | 24 +++++++++++++++--------- tests/Feature/ManageSubscriptionsTest.php | 21 ++++++++++++--------- tests/Feature/Payments/ManagePaymentsTest.php | 17 ++++++++--------- tests/Feature/Payments/PaymentSearchTest.php | 18 ++++++++++++++---- 10 files changed, 80 insertions(+), 55 deletions(-) diff --git a/app/Entities/Partners/Partner.php b/app/Entities/Partners/Partner.php index 711ad7c..e12b01c 100644 --- a/app/Entities/Partners/Partner.php +++ b/app/Entities/Partners/Partner.php @@ -2,10 +2,13 @@ namespace App\Entities\Partners; +use App\Traits\OwnedByAgency; use Illuminate\Database\Eloquent\Model; class Partner extends Model { + use OwnedByAgency; + protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'notes', 'is_active', 'owner_id']; public function owner() diff --git a/app/Http/Controllers/InvoiceDraftController.php b/app/Http/Controllers/InvoiceDraftController.php index 92562bf..fde1ea8 100644 --- a/app/Http/Controllers/InvoiceDraftController.php +++ b/app/Http/Controllers/InvoiceDraftController.php @@ -19,7 +19,7 @@ class InvoiceDraftController extends Controller public function index(Request $request) { - $draft = $this->draftCollection->content()->first(); + $draft = $this->draftCollection->content()->first(); $projects = Project::pluck('name', 'id'); return view('invoices.create', compact('draft', 'projects')); @@ -69,8 +69,7 @@ class InvoiceDraftController extends Controller return back(); } - public function empty($draftKey) - { + function empty($draftKey) { $this->draftCollection->emptyDraft($draftKey); return redirect()->route('invoices.create', $draftKey); diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php index 5fc625a..99c7e36 100644 --- a/resources/views/invoices/show.blade.php +++ b/resources/views/invoices/show.blade.php @@ -57,4 +57,4 @@ -@endsection \ No newline at end of file +@endsection diff --git a/tests/Feature/InvoiceEntryTest.php b/tests/Feature/InvoiceEntryTest.php index 493e307..14d8a5d 100644 --- a/tests/Feature/InvoiceEntryTest.php +++ b/tests/Feature/InvoiceEntryTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Entities\Partners\Partner; use App\Entities\Projects\Project; use App\Services\InvoiceDrafts\InvoiceDraft; use App\Services\InvoiceDrafts\InvoiceDraftCollection; @@ -137,8 +138,9 @@ class InvoiceEntryTest extends TestCase $item1 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 1000]); $item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]); - $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); // Add items to draft $cart->addItemToDraft($draft->draftKey, $item1); diff --git a/tests/Feature/ManageFeaturesTest.php b/tests/Feature/ManageFeaturesTest.php index fe9ed7e..5e0ca0e 100644 --- a/tests/Feature/ManageFeaturesTest.php +++ b/tests/Feature/ManageFeaturesTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use App\Entities\Agencies\Agency; +use App\Entities\Partners\Partner; use App\Entities\Projects\Feature; use App\Entities\Projects\Project; use App\Entities\Projects\Task; @@ -16,9 +17,10 @@ class ManageFeaturesTest extends TestCase { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->id]); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); - $worker = $this->createUser('worker'); + $worker = $this->createUser(); $this->visit(route('projects.features', $project->id)); $this->click(trans('feature.create')); @@ -50,7 +52,8 @@ class ManageFeaturesTest extends TestCase $agency = factory(Agency::class)->create(['owner_id' => $user[0]->id]); $this->actingAs($user[0]); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); + $customer = factory(Partner::class)->create(['owner_id' => $agency->id]); + $project = factory(Project::class)->create(['owner_id' => $agency->id, 'customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['worker_id' => $user[1]->id, 'project_id' => $project->id]); @@ -79,11 +82,11 @@ class ManageFeaturesTest extends TestCase /** @test */ public function admin_can_delete_a_feature() { - $user = $this->adminUserSigningIn(); - - $project = factory(Project::class)->create(['owner_id' => $user->id]); - $feature = factory(Feature::class)->create(['project_id' => $project->id]); - $tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $feature = factory(Feature::class)->create(['project_id' => $project->id]); + $tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]); $this->seeInDatabase('features', [ 'name' => $feature->name, @@ -132,9 +135,9 @@ class ManageFeaturesTest extends TestCase /** @test */ public function admin_may_clone_many_features_from_other_projects() { - $user = $this->adminUserSigningIn(); - - $projects = factory(Project::class, 2)->create(['owner_id' => $user->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $projects = factory(Project::class, 2)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); $features = factory(Feature::class, 3)->create(['project_id' => $projects[0]->id]); $tasks1 = factory(Task::class, 3)->create(['feature_id' => $features[0]->id]); $tasks2 = factory(Task::class, 3)->create(['feature_id' => $features[1]->id]); diff --git a/tests/Feature/ManagePartnersTest.php b/tests/Feature/ManagePartnersTest.php index bd0bc18..6a2bada 100644 --- a/tests/Feature/ManagePartnersTest.php +++ b/tests/Feature/ManagePartnersTest.php @@ -13,10 +13,10 @@ class ManagePartnersTest extends TestCase /** @test */ public function user_can_see_partner_list_in_partner_index_page() { - $partner1 = factory(Partner::class)->create(); - $partner2 = factory(Partner::class)->create(); + $user = $this->adminUserSigningIn(); + $partner1 = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $partner2 = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $this->adminUserSigningIn(); $this->visit(route('partners.index')); $this->see($partner1->name); $this->see($partner2->name); @@ -56,8 +56,8 @@ class ManagePartnersTest extends TestCase /** @test */ public function user_can_edit_a_partner_within_search_query() { - $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(['name' => 'Testing 123']); + $user = $this->adminUserSigningIn(); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id, 'name' => 'Testing 123']); $this->visit(route('partners.index', ['q' => '123'])); $this->click('edit-partner-'.$partner->id); @@ -89,8 +89,8 @@ class ManagePartnersTest extends TestCase /** @test */ public function user_can_delete_a_partner() { - $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(); + $user = $this->adminUserSigningIn(); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $this->visit(route('partners.index', [$partner->id])); $this->click('del-partner-'.$partner->id); diff --git a/tests/Feature/ManageProjectsTest.php b/tests/Feature/ManageProjectsTest.php index 4f051e0..0234f66 100644 --- a/tests/Feature/ManageProjectsTest.php +++ b/tests/Feature/ManageProjectsTest.php @@ -15,7 +15,7 @@ class ManageProjectsTest extends TestCase public function admin_can_input_new_project_with_existing_partner() { $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $this->visit(route('projects.index')); $this->seePageIs(route('projects.index')); @@ -75,9 +75,10 @@ class ManageProjectsTest extends TestCase /** @test */ public function admin_can_delete_a_project() { - $user = $this->adminUserSigningIn(); + $user = $this->adminUserSigningIn(); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $partner->id]); $feature = factory(Feature::class)->create(['project_id' => $project->id]); $task = factory(Task::class)->create(['feature_id' => $feature->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id]); @@ -112,8 +113,8 @@ class ManageProjectsTest extends TestCase public function admin_can_edit_a_project() { $user = $this->adminUserSigningIn(); - $partner = factory(Partner::class)->create(); - $project = factory(Project::class)->create(['owner_id' => $user->id]); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $partner->id]); $this->visit('projects/'.$project->id.'/edit'); $this->seePageIs('projects/'.$project->id.'/edit'); @@ -143,9 +144,8 @@ class ManageProjectsTest extends TestCase /** @test */ public function form_is_validated_on_invalid_project_entry() { - $user = $this->adminUserSigningIn(); - - $partner = factory(Partner::class)->create(); + $user = $this->adminUserSigningIn(); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $this->visit(route('projects.index')); $this->seePageIs(route('projects.index')); @@ -157,6 +157,7 @@ class ManageProjectsTest extends TestCase $this->type('', 'proposal_value'); $this->type('Deskripsi project baru', 'description'); $this->press(trans('project.create')); + $this->seePageIs(route('projects.create')); $this->see('Mohon periksa kembali form isian Anda.'); } @@ -165,7 +166,12 @@ class ManageProjectsTest extends TestCase public function admin_can_update_project_status_on_project_detail_page() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->id, 'status_id' => 1]); + $partner = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create([ + 'owner_id' => $user->agency->id, + 'customer_id' => $partner->id, + 'status_id' => 1, + ]); $this->visit(route('projects.show', $project->id)); $this->seePageIs(route('projects.show', $project->id)); diff --git a/tests/Feature/ManageSubscriptionsTest.php b/tests/Feature/ManageSubscriptionsTest.php index 88a288c..033f5e3 100644 --- a/tests/Feature/ManageSubscriptionsTest.php +++ b/tests/Feature/ManageSubscriptionsTest.php @@ -13,9 +13,9 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_entry_subscription() { $user = $this->adminUserSigningIn(); - $vendor = factory(Partner::class)->create(); + $vendor = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $customer = factory(Partner::class)->create(); $this->visit(route('subscriptions.index')); $this->click(trans('subscription.create')); @@ -52,11 +52,11 @@ class ManageSubscriptionsTest extends TestCase /** @test */ public function admin_can_edit_subscription_data() { - $user = $this->adminUserSigningIn(); - $vendor = factory(Partner::class)->create(); $eppCode = str_random(10); + $user = $this->adminUserSigningIn(); + $vendor = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $customer = factory(Partner::class)->create(); $subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]); @@ -94,9 +94,11 @@ class ManageSubscriptionsTest extends TestCase /** @test */ public function admin_can_delete_a_subscription() { - $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + + $subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]); $this->visit(route('subscriptions.edit', $subscription->id)); $this->click(trans('subscription.delete')); @@ -111,8 +113,9 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_see_a_subscription() { $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); + $subscription = factory(Subscription::class)->create(['customer_id' => $customer->id, 'project_id' => $project->id]); $this->visit(route('subscriptions.show', $subscription->id)); diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 0731f64..1db9b2c 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -106,11 +106,10 @@ class ManagePaymentsTest extends TestCase /** @test */ public function admin_can_delete_a_payment() { - $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $payment = factory(Payment::class)->create([ - 'project_id' => $project->id, - ]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); $this->click(trans('app.edit')); @@ -123,10 +122,10 @@ class ManagePaymentsTest extends TestCase /** @test */ public function admin_can_see_a_payment() { - $user = $this->adminUserSigningIn(); - - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); - $payment = factory(Payment::class)->create(['project_id' => $project->id]); + $user = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); $this->click(trans('app.show')); diff --git a/tests/Feature/Payments/PaymentSearchTest.php b/tests/Feature/Payments/PaymentSearchTest.php index 26e49e6..6f488a6 100644 --- a/tests/Feature/Payments/PaymentSearchTest.php +++ b/tests/Feature/Payments/PaymentSearchTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Payments; +use App\Entities\Partners\Partner; use App\Entities\Payments\Payment; use App\Entities\Projects\Project; use Tests\TestCase; @@ -12,10 +13,11 @@ class PaymentSearchTest extends TestCase public function user_can_find_payment_by_project_name() { $admin = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'name' => 'Project']); - $payment = factory(Payment::class)->create(['project_id' => $project->id]); - $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id]); - $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id]); + $customer = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); + $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); + $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id]); + $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); $this->submitForm(trans('app.search'), [ @@ -37,6 +39,14 @@ class PaymentSearchTest extends TestCase $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id]); $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id]); + $admin = $this->adminUserSigningIn(); + $customer = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); + $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); + $customer2 = factory(Partner::class)->create(['owner_id' => $admin->agency->id]); + $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer2->id]); + $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id, 'partner_id' => $customer2->id]); + $this->visit(route('payments.index')); $this->submitForm(trans('app.search'), [ 'q' => '',