Add feature test coverage for the core domain

Only Breeze's default auth/profile tests existed - nothing covered
Workouts, Sessions, Exercises, Yoga, Favorites, Blog, or the Admin
panel, which is the actual product. Adds factories for the domain
models and 45 new feature tests covering the main flows plus
authorization boundaries (owner-only access on workouts/sessions,
admin-only access on /admin, drafts hidden from the public blog).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 11:47:51 +03:00
co-authored by Claude Sonnet 5
parent 221493e56f
commit 0a36afbfdc
17 changed files with 861 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Tests\Feature\Admin;
use App\Models\Exercise;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExerciseCrudTest extends TestCase
{
use RefreshDatabase;
protected function admin(): User
{
$admin = User::factory()->create();
$admin->is_admin = true;
$admin->save();
return $admin;
}
public function test_regular_user_cannot_access_exercise_admin(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get(route('admin.exercises.index'));
$response->assertForbidden();
}
public function test_admin_can_create_an_exercise(): void
{
$response = $this->actingAs($this->admin())->post(route('admin.exercises.store'), [
'name' => 'Barbell Deadlift',
'gif_url' => 'https://example.com/deadlift.gif',
'instructions' => 'Lift the bar.',
]);
$response->assertRedirect(route('admin.exercises.index'));
$this->assertDatabaseHas('exercises', [
'name' => 'Barbell Deadlift',
'slug' => 'barbell-deadlift',
]);
}
public function test_admin_can_update_an_exercise(): void
{
$exercise = Exercise::factory()->create(['name' => 'Old Name']);
$response = $this->actingAs($this->admin())->patch(route('admin.exercises.update', $exercise), [
'name' => 'New Name',
'gif_url' => $exercise->gif_url,
'instructions' => $exercise->instructions,
]);
$response->assertRedirect(route('admin.exercises.index'));
$this->assertDatabaseHas('exercises', [
'id' => $exercise->id,
'name' => 'New Name',
]);
}
public function test_admin_can_delete_an_exercise(): void
{
$exercise = Exercise::factory()->create();
$response = $this->actingAs($this->admin())->delete(route('admin.exercises.destroy', $exercise));
$response->assertRedirect(route('admin.exercises.index'));
$this->assertDatabaseMissing('exercises', ['id' => $exercise->id]);
}
}