<?php

use App\Models\CtsSyncLog;
use App\Models\Service;
use App\Models\ServiceSong;
use App\Models\Slide;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\SongArrangementGroup;
use App\Models\SongGroup;
use App\Models\SongSlide;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Schema;

uses(RefreshDatabase::class);

test('all expected database tables exist', function () {
    $expectedTables = [
        'users',
        'password_reset_tokens',
        'sessions',
        'cache',
        'cache_locks',
        'jobs',
        'job_batches',
        'failed_jobs',
        'services',
        'songs',
        'song_groups',
        'song_slides',
        'song_arrangements',
        'song_arrangement_groups',
        'service_songs',
        'slides',
        'cts_sync_log',
    ];

    foreach ($expectedTables as $table) {
        expect(Schema::hasTable($table))->toBeTrue("Table [{$table}] should exist.");
    }
});

test('all factories create valid records', function () {
    Service::factory()->create();
    Song::factory()->create();
    SongGroup::factory()->create();
    SongSlide::factory()->create();
    SongArrangement::factory()->create();
    SongArrangementGroup::factory()->create();
    ServiceSong::factory()->create();
    Slide::factory()->create();
    CtsSyncLog::factory()->create();

    expect(Service::count())->toBeGreaterThan(0)
        ->and(Song::count())->toBeGreaterThan(0)
        ->and(SongGroup::count())->toBeGreaterThan(0)
        ->and(SongSlide::count())->toBeGreaterThan(0)
        ->and(SongArrangement::count())->toBeGreaterThan(0)
        ->and(SongArrangementGroup::count())->toBeGreaterThan(0)
        ->and(ServiceSong::count())->toBeGreaterThan(0)
        ->and(Slide::count())->toBeGreaterThan(0)
        ->and(CtsSyncLog::count())->toBeGreaterThan(0);
});
