diff --git a/app/Policies/PlanPolicy.php b/app/Policies/PlanPolicy.php index 8fb8047..536b452 100755 --- a/app/Policies/PlanPolicy.php +++ b/app/Policies/PlanPolicy.php @@ -14,6 +14,6 @@ class PlanPolicy private function isAuthorPlan(User $user, Plan $plan): bool { - return $user->id === $plan->author->first()->id; + return $user->id === $plan->author()->first()->id; } } diff --git a/database/seeders/RolesAndPermissionsSeeder.php b/database/seeders/RolesAndPermissionsSeeder.php index 61e8112..2a43d56 100644 --- a/database/seeders/RolesAndPermissionsSeeder.php +++ b/database/seeders/RolesAndPermissionsSeeder.php @@ -12,7 +12,7 @@ class RolesAndPermissionsSeeder extends Seeder { app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions(); - Permission::create(['name' => 'edit_plan']); + // Permission::create(['name' => 'edit_plan']); $role = Role::create(['name' => 'admin']); $role->givePermissionTo(Permission::all()); diff --git a/tests/Feature/Plan/EditTest.php b/tests/Feature/Plan/EditTest.php index d878c36..dadf7fe 100644 --- a/tests/Feature/Plan/EditTest.php +++ b/tests/Feature/Plan/EditTest.php @@ -34,23 +34,44 @@ class EditTest extends TestCase public function test_show_form_edit_plan_success_for_author(): void { - $plan = $this->plan; - $plan->author()->attach($this->user->id); + $this->plan->author()->attach($this->user->id); + $response = $this ->actingAs($this->user) - ->get(route('plan.edit', $plan)); + ->get(route('plan.edit', $this->plan)); $response->assertSuccessful(); } - public function test_show_form_edit_plan_fail_for_not_author(): void + + public function test_show_form_edit_plan_success_for_admin(): void + { + $this->plan->author()->attach($this->user->id); + + $response = $this + ->actingAs($this->user->assignRole('admin')) + ->get(route('plan.edit', $this->plan)); + $response->assertSuccessful(); + } + + + public function test_show_form_edit_plan_success_for_moderator(): void + { + $this->plan->author()->attach($this->user->id); + + $response = $this + ->actingAs($this->user->assignRole('moderator')) + ->get(route('plan.edit', $this->plan)); + $response->assertSuccessful(); + } + + public function test_show_form_edit_plan_forbidden_for_not_author(): void { - $plan = $this->plan; $user = User::factory()->create(); - $plan->author()->attach($user->id); + $this->plan->author()->attach($user->id); $response = $this ->actingAs($this->user) - ->get(route('plan.edit', $plan)); + ->get(route('plan.edit', $this->plan)); $response->assertForbidden(); } diff --git a/tests/Feature/Recipe/EditTest.php b/tests/Feature/Recipe/EditTest.php index fd0f746..c434170 100644 --- a/tests/Feature/Recipe/EditTest.php +++ b/tests/Feature/Recipe/EditTest.php @@ -39,16 +39,33 @@ final class EditTest extends TestCase public function test_show_form_edit_recipe_success_for_author(): void { - $user = $this->user; $recipe = Recipe::factory()->create(); - $user->author_of_recipe()->attach($recipe->id); + $this->user->author_of_recipe()->attach($recipe->id); $response = $this - ->actingAs($user) + ->actingAs($this->user) ->get(route('recipe.edit', $recipe)); $response->assertSuccessful(); } + + public function test_show_form_edit_recipe_success_for_admin(): void + { + $response = $this + ->actingAs($this->user->assignRole('admin')) + ->get(route('recipe.edit', $this->recipe)); + $response->assertSuccessful(); + } + + + public function test_show_form_edit_recipe_success_for_moderator(): void + { + $response = $this + ->actingAs($this->user->assignRole('moderator')) + ->get(route('recipe.edit', $this->recipe)); + $response->assertSuccessful(); + } + public function test_show_form_edit_recipe_forbidden_for_not_author(): void { $response = $this