diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index 24ea533..efcd132 100644 --- a/app/Entities/Partners/Customer.php +++ b/app/Entities/Partners/Customer.php @@ -2,19 +2,11 @@ namespace App\Entities\Partners; -use App\Traits\OwnedByAgency; use Illuminate\Database\Eloquent\Model; class Customer extends Model { - use OwnedByAgency; - - protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'website', 'notes', 'is_active', 'owner_id']; - - public function owner() - { - return $this->belongsTo('App\Entities\Agencies\Agency'); - } + protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'website', 'notes', 'is_active']; public function projects() { diff --git a/app/Entities/Partners/Vendor.php b/app/Entities/Partners/Vendor.php index 79471f0..8fcd169 100644 --- a/app/Entities/Partners/Vendor.php +++ b/app/Entities/Partners/Vendor.php @@ -6,10 +6,5 @@ use Illuminate\Database\Eloquent\Model; class Vendor extends Model { - protected $fillable = ['name', 'notes', 'website', 'owner_id', 'is_active']; - - public function owner() - { - return $this->belongsTo('App\Entities\Agencies\Agency', 'owner_id'); - } + protected $fillable = ['name', 'notes', 'website', 'is_active']; } diff --git a/app/Entities/Payments/Payment.php b/app/Entities/Payments/Payment.php index 831a29f..ac97243 100755 --- a/app/Entities/Payments/Payment.php +++ b/app/Entities/Payments/Payment.php @@ -19,12 +19,12 @@ class Payment extends Model { parent::boot(); - static::addGlobalScope('by_owner_project', function (Builder $builder) { - if (auth()->user() && auth()->user()->agency) { - $projectIds = auth()->user()->agency->projects->pluck('id')->all(); - $builder->whereIn('project_id', $projectIds); - } - }); + // static::addGlobalScope('by_owner_project', function (Builder $builder) { + // if (auth()->user() && auth()->user()->agency) { + // $projectIds = auth()->user()->agency->projects->pluck('id')->all(); + // $builder->whereIn('project_id', $projectIds); + // } + // }); } public function project() diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index 72ebc9e..cf99cb1 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -9,13 +9,12 @@ use App\Entities\Payments\Payment; use App\Entities\Projects\ProjectPresenter; use App\Entities\Projects\Task; use App\Entities\Subscriptions\Subscription; -use App\Traits\OwnedByAgency; use Illuminate\Database\Eloquent\Model; use Laracasts\Presenter\PresentableTrait; class Project extends Model { - use PresentableTrait, OwnedByAgency; + use PresentableTrait; protected $presenter = ProjectPresenter::class; protected $guarded = ['id', 'created_at', 'updated_at']; diff --git a/app/Entities/Projects/ProjectsRepository.php b/app/Entities/Projects/ProjectsRepository.php index 2131ced..cf7419c 100755 --- a/app/Entities/Projects/ProjectsRepository.php +++ b/app/Entities/Projects/ProjectsRepository.php @@ -38,7 +38,6 @@ class ProjectsRepository extends BaseRepository public function create($projectData) { $projectData['project_value'] = $projectData['proposal_value'] ?: 0; - $projectData['owner_id'] = auth()->id(); DB::beginTransaction(); if (isset($projectData['customer_id']) == false || $projectData['customer_id'] == '') { @@ -63,7 +62,6 @@ class ProjectsRepository extends BaseRepository $newCustomer = new Customer; $newCustomer->name = $customerName; $newCustomer->email = $customerEmail; - $newCustomer->owner_id = auth()->user()->agency->id; $newCustomer->save(); return $newCustomer; diff --git a/app/Policies/Partners/VendorPolicy.php b/app/Policies/Partners/VendorPolicy.php index efa2d4a..3ebef38 100644 --- a/app/Policies/Partners/VendorPolicy.php +++ b/app/Policies/Partners/VendorPolicy.php @@ -19,7 +19,7 @@ class VendorPolicy */ public function view(User $user, Vendor $vendor) { - return $user->agency->id == $vendor->owner_id; + return true; } /** @@ -31,7 +31,7 @@ class VendorPolicy */ public function create(User $user, Vendor $vendor) { - return ! ! $user->agency; + return true; } /** diff --git a/app/Policies/Projects/ProjectPolicy.php b/app/Policies/Projects/ProjectPolicy.php index 393fed2..f063e06 100644 --- a/app/Policies/Projects/ProjectPolicy.php +++ b/app/Policies/Projects/ProjectPolicy.php @@ -20,7 +20,7 @@ class ProjectPolicy public function view(User $user, Project $project) { // User can only view the project if he is the project's agency owner. - return $user->agency->id == $project->owner_id; + return true; } /** @@ -33,7 +33,7 @@ class ProjectPolicy public function create(User $user, Project $project) { // User can create a project if they owns an agency. - return ! is_null($user->agency); + return true; } /** diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index ccb04d0..b444f14 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -34,7 +34,7 @@ class AuthServiceProvider extends ServiceProvider // Dynamically register permissions with Laravel's Gate. foreach ($this->getPermissions() as $permission) { Gate::define($permission, function ($user) { - return ! is_null($user->agency); + return true; }); } @@ -43,11 +43,11 @@ class AuthServiceProvider extends ServiceProvider }); Gate::define('manage_project', function ($user, $project) { - return $user->id == $project->owner_id; + return true; }); Gate::define('manage_features', function ($user, $project) { - return $user->id == $project->owner_id; + return true; }); Gate::define('manage_feature', function ($user, $feature) { diff --git a/database/factories/CustomerFactory.php b/database/factories/CustomerFactory.php index dd2bcb1..20b20e5 100644 --- a/database/factories/CustomerFactory.php +++ b/database/factories/CustomerFactory.php @@ -8,8 +8,5 @@ $factory->define(Customer::class, function (Faker $faker) { return [ 'name' => $faker->company, - 'owner_id' => function () { - return factory(Agency::class)->create()->id; - }, ]; }); diff --git a/database/factories/ProjectFactory.php b/database/factories/ProjectFactory.php index 746cb09..b16849b 100644 --- a/database/factories/ProjectFactory.php +++ b/database/factories/ProjectFactory.php @@ -20,9 +20,6 @@ $factory->define(Project::class, function (Faker $faker) { 'project_value' => $projectValue = rand(1, 10) * 500000, 'proposal_value' => $projectValue, 'status_id' => rand(1, 6), - 'owner_id' => function () { - return factory(Agency::class)->create()->id; - }, 'customer_id' => function () { return factory(Customer::class)->create()->id; }, diff --git a/database/factories/VendorFactory.php b/database/factories/VendorFactory.php index fac2ebc..c22d568 100644 --- a/database/factories/VendorFactory.php +++ b/database/factories/VendorFactory.php @@ -1,15 +1,11 @@ define(Vendor::class, function (Faker $faker) { return [ - 'name' => $faker->word, - 'owner_id' => function () { - return factory(Agency::class)->create()->id; - }, + 'name' => $faker->company, ]; }); diff --git a/database/migrations/2016_07_06_110052_create_projects_table.php b/database/migrations/2016_07_06_110052_create_projects_table.php index 01900b5..7b99f19 100644 --- a/database/migrations/2016_07_06_110052_create_projects_table.php +++ b/database/migrations/2016_07_06_110052_create_projects_table.php @@ -24,7 +24,6 @@ class CreateProjectsTable extends Migration { $table->integer('proposal_value')->unsigned()->nullable(); $table->boolean('status_id')->default(1)->comment('1: planned, 2: on progress, 3: done, 4: closed, 5: canceled, 6: on hold '); $table->integer('customer_id')->unsigned(); - $table->integer('owner_id')->unsigned(); $table->timestamps(); }); } diff --git a/database/migrations/2017_10_26_134455_create_customers_table.php b/database/migrations/2017_10_26_134455_create_customers_table.php index b788c71..7a9a8c8 100644 --- a/database/migrations/2017_10_26_134455_create_customers_table.php +++ b/database/migrations/2017_10_26_134455_create_customers_table.php @@ -23,7 +23,6 @@ class CreateCustomersTable extends Migration $table->string('website')->nullable(); $table->string('notes')->nullable(); $table->boolean('is_active')->default(1); - $table->unsignedInteger('owner_id'); $table->timestamps(); }); } diff --git a/database/migrations/2017_11_01_185745_create_vendors_table.php b/database/migrations/2017_11_01_185745_create_vendors_table.php index dc5cc91..31e80f2 100644 --- a/database/migrations/2017_11_01_185745_create_vendors_table.php +++ b/database/migrations/2017_11_01_185745_create_vendors_table.php @@ -17,7 +17,6 @@ class CreateVendorsTable extends Migration $table->increments('id'); $table->string('name', 60); $table->string('website')->nullable(); - $table->unsignedInteger('owner_id'); $table->boolean('is_active')->default(1); $table->string('notes')->nullable(); $table->timestamps(); diff --git a/tests/Feature/Api/ApiManageProjectsTest.php b/tests/Feature/Api/ApiManageProjectsTest.php index a581935..cfb4f27 100644 --- a/tests/Feature/Api/ApiManageProjectsTest.php +++ b/tests/Feature/Api/ApiManageProjectsTest.php @@ -11,7 +11,7 @@ class ApiManageProjectsTest extends TestCase public function user_can_get_project_lists() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class, 1)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class, 1)->create(); $this->getJson(route('api.projects.index'), [ 'Authorization' => 'Bearer '.$user->api_token, diff --git a/tests/Feature/InvoiceEntryTest.php b/tests/Feature/InvoiceEntryTest.php index e9e0f7f..7b02805 100644 --- a/tests/Feature/InvoiceEntryTest.php +++ b/tests/Feature/InvoiceEntryTest.php @@ -101,7 +101,7 @@ class InvoiceEntryTest extends TestCase public function user_can_update_draft_invoice_detail_and_get_confirm_page() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(); $cart = new InvoiceDraftCollection(); $draft = $cart->add(new InvoiceDraft()); @@ -139,8 +139,8 @@ class InvoiceEntryTest extends TestCase $item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]); $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['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 61936e5..f1575c6 100644 --- a/tests/Feature/ManageFeaturesTest.php +++ b/tests/Feature/ManageFeaturesTest.php @@ -17,8 +17,8 @@ class ManageFeaturesTest extends TestCase { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $worker = $this->createUser(); @@ -49,11 +49,11 @@ class ManageFeaturesTest extends TestCase public function admin_can_edit_feature_data() { $user = factory(User::class, 3)->create(); - $agency = factory(Agency::class)->create(['owner_id' => $user[0]->id]); + $agency = factory(Agency::class)->create(); $this->actingAs($user[0]); - $customer = factory(Customer::class)->create(['owner_id' => $agency->id]); - $project = factory(Project::class)->create(['owner_id' => $agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['worker_id' => $user[1]->id, 'project_id' => $project->id]); @@ -83,8 +83,8 @@ class ManageFeaturesTest extends TestCase public function admin_can_delete_a_feature() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $feature = factory(Feature::class)->create(['project_id' => $project->id]); $tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]); @@ -120,7 +120,7 @@ class ManageFeaturesTest extends TestCase { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->id]); + $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 1]); $this->visit(route('projects.features', $project->id)); @@ -136,8 +136,8 @@ class ManageFeaturesTest extends TestCase public function admin_may_clone_many_features_from_other_projects() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $projects = factory(Project::class, 2)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $projects = factory(Project::class, 2)->create(['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/ManageProjectsTest.php b/tests/Feature/ManageProjectsTest.php index 1984513..feecc9a 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_customer() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); $this->visit(route('projects.index')); $this->seePageIs(route('projects.index')); @@ -68,7 +68,6 @@ class ManageProjectsTest extends TestCase 'name' => 'Project Baru', 'proposal_value' => '2000000', 'customer_id' => $newCustomer->id, - 'owner_id' => $user->agency->id, ]); } @@ -76,9 +75,9 @@ class ManageProjectsTest extends TestCase public function admin_can_delete_a_project() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $project = factory(Project::class)->create(['customer_id' => $customer->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]); @@ -87,13 +86,12 @@ class ManageProjectsTest extends TestCase $this->click(trans('app.edit')); $this->click(trans('app.delete')); $this->press(trans('app.delete_confirm_button')); - $this->seePageIs('projects'); + $this->seePageIs(route('projects.index')); $this->see(trans('project.deleted')); $this->notSeeInDatabase('projects', [ 'name' => $project->name, 'proposal_value' => $project->proposal_value, - 'owner_id' => $user->id, ]); $this->notSeeInDatabase('payments', [ @@ -113,8 +111,8 @@ class ManageProjectsTest extends TestCase public function admin_can_edit_a_project() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $this->visit('projects/'.$project->id.'/edit'); $this->seePageIs('projects/'.$project->id.'/edit'); @@ -145,7 +143,7 @@ class ManageProjectsTest extends TestCase public function form_is_validated_on_invalid_project_entry() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); $this->visit(route('projects.index')); $this->seePageIs(route('projects.index')); @@ -166,9 +164,8 @@ class ManageProjectsTest extends TestCase public function admin_can_update_project_status_on_project_detail_page() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); $project = factory(Project::class)->create([ - 'owner_id' => $user->agency->id, 'customer_id' => $customer->id, 'status_id' => 1, ]); diff --git a/tests/Feature/ManageSubscriptionsTest.php b/tests/Feature/ManageSubscriptionsTest.php index cc95566..48d4421 100644 --- a/tests/Feature/ManageSubscriptionsTest.php +++ b/tests/Feature/ManageSubscriptionsTest.php @@ -13,10 +13,9 @@ class ManageSubscriptionsTest extends TestCase /** @test */ public function admin_can_entry_subscription() { - $user = $this->adminUserSigningIn(); - $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]); + $user = $this->adminUserSigningIn(); + $vendor = factory(Vendor::class)->create(); + $project = factory(Project::class)->create(); $this->visit(route('subscriptions.index')); $this->click(trans('subscription.create')); @@ -53,9 +52,9 @@ class ManageSubscriptionsTest extends TestCase { $eppCode = str_random(10); $user = $this->adminUserSigningIn(); - $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]); + $vendor = factory(Vendor::class)->create(); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); @@ -90,8 +89,8 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_delete_a_subscription() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); @@ -108,9 +107,9 @@ class ManageSubscriptionsTest extends TestCase public function admin_can_see_a_subscription() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::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' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); $this->visit(route('subscriptions.show', $subscription->id)); diff --git a/tests/Feature/ManageTasksTest.php b/tests/Feature/ManageTasksTest.php index 34ca093..c189551 100644 --- a/tests/Feature/ManageTasksTest.php +++ b/tests/Feature/ManageTasksTest.php @@ -13,7 +13,7 @@ class ManageTasksTest extends TestCase public function admin_can_entry_task() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['worker_id' => $user->id, 'project_id' => $project->id]); $this->visit('features/'.$feature->id); @@ -42,7 +42,7 @@ class ManageTasksTest extends TestCase public function admin_can_edit_task_data() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['worker_id' => $user->id, 'project_id' => $project->id]); @@ -72,7 +72,7 @@ class ManageTasksTest extends TestCase public function admin_can_delete_a_task() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['worker_id' => $user->id, 'project_id' => $project->id]); diff --git a/tests/Feature/Partners/ManageCustomersTest.php b/tests/Feature/Partners/ManageCustomersTest.php index a73002a..c66b097 100644 --- a/tests/Feature/Partners/ManageCustomersTest.php +++ b/tests/Feature/Partners/ManageCustomersTest.php @@ -14,8 +14,8 @@ class ManageCustomersTest extends TestCase public function user_can_see_customer_list_in_customer_index_page() { $user = $this->adminUserSigningIn(); - $customer1 = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $customer2 = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer1 = factory(Customer::class)->create(); + $customer2 = factory(Customer::class)->create(); $this->visit(route('customers.index')); $this->see($customer1->name); @@ -44,14 +44,13 @@ class ManageCustomersTest extends TestCase $this->see(trans('customer.created')); $this->seeInDatabase('customers', [ - 'name' => 'Customer 1 name', - 'email' => 'customer1@mail.com', - 'phone' => '081234567890', - 'pic' => 'Nama PIC Customer', - 'address' => 'Alamat customer 1', - 'website' => 'https://example.com', - 'notes' => null, - 'owner_id' => $user->agency->id, + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'website' => 'https://example.com', + 'notes' => null, ]); } @@ -59,7 +58,7 @@ class ManageCustomersTest extends TestCase public function user_can_edit_a_customer() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id, 'name' => 'Testing 123']); + $customer = factory(Customer::class)->create(['name' => 'Testing 123']); $this->visit(route('customers.show', [$customer->id])); $this->click('edit-customer-'.$customer->id); @@ -94,7 +93,7 @@ class ManageCustomersTest extends TestCase public function user_can_delete_a_customer() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); $this->visit(route('customers.edit', [$customer->id])); $this->click('del-customer-'.$customer->id); diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 72a19d7..c7fc3b1 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -14,8 +14,8 @@ class ManagePaymentsTest extends TestCase public function admin_can_entry_project_an_income_payment() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(); $this->visit(route('payments.index')); $this->seePageIs(route('payments.index')); @@ -46,8 +46,8 @@ class ManagePaymentsTest extends TestCase public function admin_can_entry_project_an_expanse_payment() { $user = $this->adminUserSigningIn(); - $vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Vendor::class)->create(); + $project = factory(Project::class)->create(); $this->visit(route('payments.index')); $this->seePageIs(route('payments.index')); @@ -79,8 +79,8 @@ class ManagePaymentsTest extends TestCase public function admin_can_edit_payment_data() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(); $payment = factory(Payment::class)->create([ 'partner_id' => $customer->id, @@ -110,8 +110,8 @@ class ManagePaymentsTest extends TestCase public function admin_can_delete_a_payment() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); @@ -126,8 +126,8 @@ class ManagePaymentsTest extends TestCase public function admin_can_see_a_payment() { $user = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $user->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id, 'customer_id' => $customer->id]); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id]); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); diff --git a/tests/Feature/Payments/PaymentSearchTest.php b/tests/Feature/Payments/PaymentSearchTest.php index 58f5c7c..f9887ef 100644 --- a/tests/Feature/Payments/PaymentSearchTest.php +++ b/tests/Feature/Payments/PaymentSearchTest.php @@ -13,10 +13,10 @@ class PaymentSearchTest extends TestCase public function user_can_find_payment_by_project_name() { $admin = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['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]); + $project2 = factory(Project::class)->create(['customer_id' => $customer->id]); $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id, 'partner_id' => $customer->id]); $this->visit(route('payments.index')); @@ -34,17 +34,17 @@ class PaymentSearchTest extends TestCase public function partner_find_payment_by_customer_id() { $admin = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'name' => 'Project']); + $project = factory(Project::class)->create(['name' => 'Project']); $payment = factory(Payment::class)->create(['project_id' => $project->id]); - $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id]); + $project2 = factory(Project::class)->create(); $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id]); $admin = $this->adminUserSigningIn(); - $customer = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); - $project = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer->id, 'name' => 'Project']); + $customer = factory(Customer::class)->create(); + $project = factory(Project::class)->create(['customer_id' => $customer->id, 'name' => 'Project']); $payment = factory(Payment::class)->create(['project_id' => $project->id, 'partner_id' => $customer->id]); - $customer2 = factory(Customer::class)->create(['owner_id' => $admin->agency->id]); - $project2 = factory(Project::class)->create(['owner_id' => $admin->agency->id, 'customer_id' => $customer2->id]); + $customer2 = factory(Customer::class)->create(); + $project2 = factory(Project::class)->create(['customer_id' => $customer2->id]); $unShownPayment = factory(Payment::class)->create(['project_id' => $project2->id, 'partner_id' => $customer2->id]); $this->visit(route('payments.index')); diff --git a/tests/Feature/Projects/UploadFilesTest.php b/tests/Feature/Projects/UploadFilesTest.php index 63176e0..96dde02 100644 --- a/tests/Feature/Projects/UploadFilesTest.php +++ b/tests/Feature/Projects/UploadFilesTest.php @@ -2,9 +2,7 @@ namespace Tests\Feature\Projects; -use App\Entities\Projects\File; use App\Entities\Projects\Project; -use Illuminate\Http\Testing\FileFactory; use Illuminate\Http\UploadedFile; use Storage; use Tests\TestCase; @@ -15,8 +13,8 @@ class UploadFilesTest extends TestCase public function user_can_upload_document_to_a_project() { Storage::fake('avatar'); - $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->id]); + $user = $this->adminUserSigningIn(); + $project = factory(Project::class)->create(); $this->visit(route('projects.files', $project->id)); $this->seeElement('form', ['id' => 'upload-file']); $this->seeElement('input', ['id' => 'file']); @@ -30,10 +28,10 @@ class UploadFilesTest extends TestCase $this->assertCount(1, $project->files); $this->seeInDatabase('files', [ - 'fileable_id' => $project->id, + 'fileable_id' => $project->id, 'fileable_type' => 'App\Entities\Projects\Project', - 'title' => 'Judul file', - 'description' => 'Deskripsi file yang diuplod.', + 'title' => 'Judul file', + 'description' => 'Deskripsi file yang diuplod.', ]); $file = $project->files->first(); @@ -44,8 +42,8 @@ class UploadFilesTest extends TestCase public function user_can_edit_document_file_on_a_project() { Storage::fake('avatar'); - $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->id]); + $user = $this->adminUserSigningIn(); + $project = factory(Project::class)->create(); // $file = factory(File::class, 'project')->create(['fileable_id' => $project->id]); // dd(get_class_methods((new FileFactory)->create('123.txt'))); // $result = Storage::disk('avatar')->put('public/files', (new FileFactory)->create('123.txt')); @@ -72,10 +70,10 @@ class UploadFilesTest extends TestCase $this->seePageIs(route('projects.files', [$project->id])); $this->seeInDatabase('files', [ - 'fileable_id' => $project->id, + 'fileable_id' => $project->id, 'fileable_type' => 'App\Entities\Projects\Project', - 'title' => 'Edit Judul file', - 'description' => 'Edit Deskripsi file yang diuplod.', + 'title' => 'Edit Judul file', + 'description' => 'Edit Deskripsi file yang diuplod.', ]); Storage::disk('avatar')->assertExists('public/files/'.$file->filename); diff --git a/tests/Unit/Models/AgencyTest.php b/tests/Unit/Models/AgencyTest.php deleted file mode 100644 index 0e1c1a1..0000000 --- a/tests/Unit/Models/AgencyTest.php +++ /dev/null @@ -1,61 +0,0 @@ -create(); - $this->assertInstanceOf(User::class, $agency->owner); - } - - /** @test */ - public function agency_has_many_projects() - { - $agency = factory(Agency::class)->create(); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); - - $this->assertInstanceOf(Collection::class, $agency->projects); - $this->assertInstanceOf(Project::class, $agency->projects->first()); - } - - /** @test */ - public function agency_can_has_many_workers() - { - $agency = factory(Agency::class)->create(); - $workers = factory(User::class, 2)->create(); - - $agency->addWorker($workers[0]); - $agency->addWorker($workers[1]); - - $this->assertCount(2, $agency->workers); - $this->assertInstanceOf(Collection::class, $agency->workers); - $this->assertInstanceOf(User::class, $agency->workers->first()); - } - - /** @test */ - public function agency_can_remove_some_workers() - { - $agency = factory(Agency::class)->create(); - $workers = factory(User::class, 2)->create(); - - $agency->addWorker($workers[0]); - $agency->addWorker($workers[1]); - - $this->assertCount(2, $agency->workers); - - $agency->removeWorker($workers[0]); - - $agency = $agency->fresh(); - $this->assertCount(1, $agency->workers); - $this->assertEquals($workers[1]->id, $agency->workers->first()->id); - } -} diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index 46d3c1f..1fa42c5 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/tests/Unit/Models/CustomerTest.php @@ -2,7 +2,6 @@ namespace Tests\Unit\Models; -use App\Entities\Agencies\Agency; use App\Entities\Partners\Customer; use App\Entities\Projects\Project; use Illuminate\Support\Collection; @@ -11,23 +10,13 @@ use Tests\TestCase as TestCase; class CustomerTest extends TestCase { /** @test */ - public function a_customer_has_an_owner() - { - $agency = factory(Agency::class)->create(); - $customer = factory(Customer::class)->create(['owner_id' => $agency->id]); - - $this->assertTrue($customer->owner instanceof Agency); - $this->assertEquals($customer->owner->id, $agency->id); - } - - /** @test */ public function a_customer_has_many_projects() { $customer = factory(Customer::class)->create(); $project = factory(Project::class)->create(['customer_id' => $customer->id]); - $this->assertTrue($customer->projects instanceof Collection); - $this->assertTrue($customer->projects->first() instanceof Project); + $this->assertInstanceOf(Collection::class, $customer->projects); + $this->assertInstanceOf(Project::class, $customer->projects->first()); } /** @test */ diff --git a/tests/Unit/Models/InvoiceTest.php b/tests/Unit/Models/InvoiceTest.php index ae121f8..7dada94 100644 --- a/tests/Unit/Models/InvoiceTest.php +++ b/tests/Unit/Models/InvoiceTest.php @@ -13,19 +13,20 @@ class InvoiceTest extends TestCase public function it_has_project_relation() { $user = $this->adminUserSigningIn(); - $project = factory(Project::class)->create(['owner_id' => $user->agency->id]); + $project = factory(Project::class)->create(); $invoice = factory(Invoice::class)->create(['project_id' => $project->id]); - $this->assertTrue($invoice->project instanceof Project); + $this->assertInstanceOf(Project::class, $invoice->project); $this->assertEquals($invoice->project->id, $project->id); } + /** @test */ public function it_has_creator_relation() { $user = $this->adminUserSigningIn(); $invoice = factory(Invoice::class)->create(['creator_id' => $user->id]); - $this->assertTrue($invoice->creator instanceof User); + $this->assertInstanceOf(User::class, $invoice->creator); $this->assertEquals($invoice->creator->id, $user->id); } diff --git a/tests/Unit/Models/ProjectTest.php b/tests/Unit/Models/ProjectTest.php index 69ee3e7..f04a854 100644 --- a/tests/Unit/Models/ProjectTest.php +++ b/tests/Unit/Models/ProjectTest.php @@ -2,7 +2,6 @@ namespace Tests\Unit\Models; -use App\Entities\Agencies\Agency; use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Projects\Feature; @@ -19,8 +18,8 @@ class ProjectTest extends TestCase { $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['project_id' => $project->id]); - $this->assertTrue($project->features instanceof Collection); - $this->assertTrue($project->features->first() instanceof Feature); + $this->assertInstanceOf(Collection::class, $project->features); + $this->assertInstanceOf(Feature::class, $project->features->first()); } /** @test */ @@ -28,8 +27,8 @@ class ProjectTest extends TestCase { $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 1]); - $this->assertTrue($project->mainFeatures instanceof Collection); - $this->assertTrue($project->mainFeatures->first() instanceof Feature); + $this->assertInstanceOf(Collection::class, $project->mainFeatures); + $this->assertInstanceOf(Feature::class, $project->mainFeatures->first()); } /** @test */ @@ -37,8 +36,8 @@ class ProjectTest extends TestCase { $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]); - $this->assertTrue($project->additionalFeatures instanceof Collection); - $this->assertTrue($project->additionalFeatures->first() instanceof Feature); + $this->assertInstanceOf(Collection::class, $project->additionalFeatures); + $this->assertInstanceOf(Feature::class, $project->additionalFeatures->first()); } /** @test */ @@ -47,8 +46,8 @@ class ProjectTest extends TestCase $project = factory(Project::class)->create(); $feature = factory(Feature::class)->create(['project_id' => $project->id, 'type_id' => 2]); $tasks = factory(Task::class, 2)->create(['feature_id' => $feature->id]); - $this->assertTrue($project->tasks instanceof Collection); - $this->assertTrue($project->tasks->first() instanceof Task); + $this->assertInstanceOf(Collection::class, $project->tasks); + $this->assertInstanceOf(Task::class, $project->tasks->first()); } /** @test */ @@ -56,8 +55,8 @@ class ProjectTest extends TestCase { $project = factory(Project::class)->create(); $payment = factory(Payment::class)->create(['project_id' => $project->id]); - $this->assertTrue($project->payments instanceof Collection); - $this->assertTrue($project->payments->first() instanceof Payment); + $this->assertInstanceOf(Collection::class, $project->payments); + $this->assertInstanceOf(Payment::class, $project->payments->first()); } /** @test */ @@ -65,8 +64,8 @@ class ProjectTest extends TestCase { $project = factory(Project::class)->create(); $subscription = factory(Subscription::class)->create(['project_id' => $project->id]); - $this->assertTrue($project->subscriptions instanceof Collection); - $this->assertTrue($project->subscriptions->first() instanceof Subscription); + $this->assertInstanceOf(Collection::class, $project->subscriptions); + $this->assertInstanceOf(Subscription::class, $project->subscriptions->first()); } /** @test */ @@ -75,21 +74,11 @@ class ProjectTest extends TestCase $customer = factory(Customer::class)->create(); $project = factory(Project::class)->create(['customer_id' => $customer->id]); - $this->assertTrue($project->customer instanceof Customer); + $this->assertInstanceOf(Customer::class, $project->customer); $this->assertEquals($project->customer_id, $customer->id); } /** @test */ - public function a_project_belongs_to_an_agency() - { - $agency = factory(Agency::class)->create(); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); - - $this->assertTrue($project->owner instanceof Agency); - $this->assertEquals($project->owner_id, $agency->id); - } - - /** @test */ public function a_project_has_cash_in_total_method() { $project = factory(Project::class)->create(); @@ -143,7 +132,7 @@ class ProjectTest extends TestCase public function a_project_has_many_files() { $project = factory(Project::class)->create(); - $this->assertTrue($project->files instanceof Collection); + $this->assertInstanceOf(Collection::class, $project->files); } /** @test */ diff --git a/tests/Unit/Models/VendorTest.php b/tests/Unit/Models/VendorTest.php index 2d21236..794f275 100644 --- a/tests/Unit/Models/VendorTest.php +++ b/tests/Unit/Models/VendorTest.php @@ -2,7 +2,6 @@ namespace Tests\Unit\Models; -use App\Entities\Agencies\Agency; use App\Entities\Partners\Vendor; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase as TestCase; @@ -12,12 +11,9 @@ class VendorTest extends TestCase use DatabaseMigrations; /** @test */ - public function a_vendor_belongs_to_an_agency_as_its_owner() + public function a_vendor_has_name() { - $vendor = factory(Vendor::class)->create(); - $this->assertTrue( - $vendor->owner instanceof Agency, - 'A vendor must belongs to an App\Entities\Agencies\Agency model as its owner.' - ); + $vendor = factory(Vendor::class)->make(['name' => 'Vendor 1 name']); + $this->assertEquals('Vendor 1 name', $vendor->name); } } diff --git a/tests/Unit/Policies/AgencyPolicyTest.php b/tests/Unit/Policies/AgencyPolicyTest.php deleted file mode 100644 index 22c839b..0000000 --- a/tests/Unit/Policies/AgencyPolicyTest.php +++ /dev/null @@ -1,18 +0,0 @@ -createUser(); - factory(Agency::class)->create(['owner_id' => $user->id]); - - $this->assertTrue($user->can('manage', $user->agency)); - } -} diff --git a/tests/Unit/Policies/ProjectPolicyTest.php b/tests/Unit/Policies/ProjectPolicyTest.php index d466108..69df65d 100644 --- a/tests/Unit/Policies/ProjectPolicyTest.php +++ b/tests/Unit/Policies/ProjectPolicyTest.php @@ -22,7 +22,7 @@ class ProjectPolicyTest extends TestCase { $user = $this->userSigningIn(); $agency = factory(Agency::class)->create(['owner_id' => $user->id]); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); + $project = factory(Project::class)->create(); $this->assertTrue($user->can('view', $project)); } @@ -32,7 +32,7 @@ class ProjectPolicyTest extends TestCase { $user = $this->userSigningIn(); $agency = factory(Agency::class)->create(['owner_id' => $user->id]); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); + $project = factory(Project::class)->create(); $this->assertTrue($user->can('update', $project)); } @@ -42,7 +42,7 @@ class ProjectPolicyTest extends TestCase { $user = $this->userSigningIn(); $agency = factory(Agency::class)->create(['owner_id' => $user->id]); - $project = factory(Project::class)->create(['owner_id' => $agency->id]); + $project = factory(Project::class)->create(); $this->assertTrue($user->can('delete', $project)); } diff --git a/tests/Unit/Policies/VendorPolicyTest.php b/tests/Unit/Policies/VendorPolicyTest.php index 994feaa..2b3ff84 100644 --- a/tests/Unit/Policies/VendorPolicyTest.php +++ b/tests/Unit/Policies/VendorPolicyTest.php @@ -21,7 +21,7 @@ class VendorPolicyTest extends TestCase public function user_can_view_vendor() { $user = $this->adminUserSigningIn(); - $vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Vendor::class)->create(); $this->assertTrue($user->can('view', $vendor)); } @@ -29,7 +29,7 @@ class VendorPolicyTest extends TestCase public function user_can_update_vendor() { $user = $this->adminUserSigningIn(); - $vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Vendor::class)->create(); $this->assertTrue($user->can('update', $vendor)); } @@ -37,7 +37,7 @@ class VendorPolicyTest extends TestCase public function user_can_delete_vendor() { $user = $this->adminUserSigningIn(); - $vendor = factory(Vendor::class)->create(['owner_id' => $user->agency->id]); + $vendor = factory(Vendor::class)->create(); $this->assertTrue($user->can('delete', $vendor)); } }