toBeTrue(); expect(Schema::hasColumn('songs', 'ccli_source_url'))->toBeTrue(); }); test('imported_from_ccli_at defaults to null', function (): void { $song = Song::factory()->create(); expect($song->fresh()->imported_from_ccli_at)->toBeNull(); }); test('ccli_source_url defaults to null', function (): void { $song = Song::factory()->create(); expect($song->fresh()->ccli_source_url)->toBeNull(); }); test('imported_from_ccli_at casts to Carbon instance', function (): void { $song = Song::factory()->create(['imported_from_ccli_at' => '2026-05-10 12:00:00']); expect($song->fresh()->imported_from_ccli_at)->toBeInstanceOf(Carbon::class); }); test('fromCcli factory state populates both fields', function (): void { $song = Song::factory()->fromCcli()->create(); $fresh = $song->fresh(); expect($fresh->imported_from_ccli_at)->not->toBeNull(); expect($fresh->imported_from_ccli_at)->toBeInstanceOf(Carbon::class); expect($fresh->ccli_source_url)->not->toBeNull(); expect($fresh->ccli_source_url)->toContain('songselect.ccli.com'); }); test('migration rolls back cleanly', function (): void { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Destruktive Migration'); // create_song_sections_and_rescope_slides is a destructive migration whose down() // throws by design. RefreshDatabase applies every migration in a single batch, so a // full-batch rollback proceeds newest -> oldest and reaches the guard before touching // anything older. This stays correct no matter how many migrations are added above the // guard later: they simply roll back first, then the guard throws the RuntimeException. Artisan::call('migrate:rollback'); });