2026-08-10 11:47:51 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
|
|
use App\Models\Exercise;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workout;
|
2026-08-10 12:04:50 +03:00
|
|
|
use App\Models\YogaPose;
|
2026-08-10 11:47:51 +03:00
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
class FavoriteTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
public function test_guest_cannot_favorite_an_exercise(): void
|
|
|
|
|
{
|
|
|
|
|
$exercise = Exercise::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->post(route('exercises.favorite', $exercise));
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_user_can_toggle_exercise_favorite(): void
|
|
|
|
|
{
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$exercise = Exercise::factory()->create();
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)->post(route('exercises.favorite', $exercise));
|
|
|
|
|
$this->assertTrue($user->favoriteExercises()->where('exercise_id', $exercise->id)->exists());
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)->post(route('exercises.favorite', $exercise));
|
|
|
|
|
$this->assertFalse($user->favoriteExercises()->where('exercise_id', $exercise->id)->exists());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_user_can_toggle_workout_favorite(): void
|
|
|
|
|
{
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$workout = Workout::factory()->create();
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)->post(route('workouts.favorite', $workout));
|
|
|
|
|
$this->assertTrue($user->favoriteWorkouts()->where('workout_id', $workout->id)->exists());
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)->post(route('workouts.favorite', $workout));
|
|
|
|
|
$this->assertFalse($user->favoriteWorkouts()->where('workout_id', $workout->id)->exists());
|
|
|
|
|
}
|
2026-08-10 12:04:50 +03:00
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
2026-08-10 11:47:51 +03:00
|
|
|
}
|