Files
daily-meal-api/tests/Feature/DemoContentSeederTest.php
T
leonm 238a044d98
CI / 🧪 Tests Laravel (push) Successful in 2m33s
CI / 🐳 Build & Push Images (push) Successful in 49s
feat: seeder
2026-08-14 13:43:35 +02:00

57 lines
2.1 KiB
PHP

<?php
use App\Enums\MealPostVisibility;
use App\Models\MealPostIngredients;
use App\Models\MealPosts;
use App\Models\PostReviews;
use App\Models\User;
use Database\Seeders\DemoContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
uses(RefreshDatabase::class);
it('creates a complete local demonstration dataset', function () {
$this->seed();
$demoUser = User::query()->where('email', 'test@example.com')->firstOrFail();
$onboardingUser = User::query()->where('email', 'onboarding@example.com')->firstOrFail();
expect(User::query()->count())->toBe(10)
->and($demoUser->hasCompletedNutritionOnboarding())->toBeTrue()
->and($onboardingUser->hasCompletedNutritionOnboarding())->toBeFalse()
->and($demoUser->weightEntries()->count())->toBe(12)
->and($demoUser->workouts()->count())->toBe(12)
->and($demoUser->following()->count())->toBe(8)
->and(MealPosts::query()->where('visibility', MealPostVisibility::Public)->count())->toBe(48)
->and(MealPostIngredients::query()->count())->toBe(144)
->and(PostReviews::query()->count())->toBe(120)
->and(
MealPosts::query()
->withCount('likedByUsers')
->get()
->sum('liked_by_users_count')
)->toBeGreaterThan(100);
});
it('fills more than one explorer page with usable meal images', function () {
$this->seed(DemoContentSeeder::class);
$demoUser = User::query()->where('email', 'test@example.com')->firstOrFail();
Sanctum::actingAs($demoUser);
$this->getJson('/api/meal-posts?per_page=30&page=1')
->assertOk()
->assertJsonCount(30, 'data')
->assertJsonPath('meta.current_page', 1)
->assertJsonPath('meta.last_page', 2)
->assertJsonPath('meta.total', 48)
->assertJsonPath('data.0.imageUrl', fn (string $url): bool => str_starts_with($url, 'https://images.unsplash.com/'));
$this->getJson('/api/meal-posts?per_page=30&page=2')
->assertOk()
->assertJsonCount(18, 'data')
->assertJsonPath('meta.current_page', 2);
});