Add favorite toggle to yoga poses

Exercises and workouts both have a favorite toggle; yoga poses had an
otherwise identical browse/filter UX but no way to favorite them - an
inconsistency rather than a deliberate omission. Mirrors the existing
exercise/workout favorite pattern exactly: a pivot table, a
belongsToMany on User, and a toggle button on the pose detail page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 12:04:50 +03:00
co-authored by Claude Sonnet 5
parent 0a44b97232
commit 7769d2038a
6 changed files with 94 additions and 0 deletions
+22
View File
@@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Models\Exercise;
use App\Models\User;
use App\Models\Workout;
use App\Models\YogaPose;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -44,4 +45,25 @@ class FavoriteTest extends TestCase
$this->actingAs($user)->post(route('workouts.favorite', $workout));
$this->assertFalse($user->favoriteWorkouts()->where('workout_id', $workout->id)->exists());
}
public function test_guest_cannot_favorite_a_yoga_pose(): void
{
$pose = YogaPose::factory()->create();
$response = $this->post(route('yoga.favorite', $pose));
$response->assertRedirect(route('login'));
}
public function test_user_can_toggle_yoga_pose_favorite(): void
{
$user = User::factory()->create();
$pose = YogaPose::factory()->create();
$this->actingAs($user)->post(route('yoga.favorite', $pose));
$this->assertTrue($user->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists());
$this->actingAs($user)->post(route('yoga.favorite', $pose));
$this->assertFalse($user->favoriteYogaPoses()->where('yoga_pose_id', $pose->id)->exists());
}
}