- Datenmodell Property/Season/Extra (Beträge in Cent), Seeder mit Preisliste 2026 - PriceCalculator: Saison-Splitting, Mindestaufenthalt, Zusatzperson, Endreinigung, Extras, Anzahlung/Restzahlung - Filament-Verwaltung: Wohnungen, Saisons (Überschneidungsprüfung, Lückenwarnung, Kopie ins Folgejahr, Preisrechner), Zusatzleistungen - Tests für Preisberechnung und Saisonverwaltung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
130 lines
4.5 KiB
PHP
130 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Actions\CopySeasonsToNextYear;
|
|
use App\Filament\Resources\Properties\Pages\EditProperty;
|
|
use App\Filament\Resources\Properties\PropertyResource;
|
|
use App\Filament\Resources\Properties\RelationManagers\SeasonsRelationManager;
|
|
use App\Models\Property;
|
|
use App\Models\Season;
|
|
use App\Models\User;
|
|
use Carbon\CarbonImmutable;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\Testing\TestAction;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class SeasonManagementTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Property $property;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
$this->property = Property::factory()->create();
|
|
Season::factory()->for($this->property)->create([
|
|
'name' => 'Winter',
|
|
'starts_on' => '2026-01-03',
|
|
'ends_on' => '2026-03-07',
|
|
]);
|
|
}
|
|
|
|
public function test_season_is_created_with_euro_amounts_stored_as_cents(): void
|
|
{
|
|
$this->seasonsManager()
|
|
->callAction(TestAction::make(CreateAction::class)->table(), [
|
|
'name' => 'Nebensaison',
|
|
'starts_on' => '2026-03-07',
|
|
'ends_on' => '2026-04-03',
|
|
'nightly_rate' => '65.50',
|
|
'min_nights' => 2,
|
|
])
|
|
->assertHasNoFormErrors();
|
|
|
|
$this->assertDatabaseHas('seasons', [
|
|
'property_id' => $this->property->id,
|
|
'name' => 'Nebensaison',
|
|
'nightly_rate' => 6550,
|
|
]);
|
|
}
|
|
|
|
public function test_overlapping_season_is_rejected(): void
|
|
{
|
|
$this->seasonsManager()
|
|
->callAction(TestAction::make(CreateAction::class)->table(), [
|
|
'name' => 'Überschneidung',
|
|
'starts_on' => '2026-03-01',
|
|
'ends_on' => '2026-03-14',
|
|
'nightly_rate' => '70',
|
|
'min_nights' => 2,
|
|
])
|
|
->assertHasFormErrors(['starts_on']);
|
|
|
|
$this->assertDatabaseMissing('seasons', ['name' => 'Überschneidung']);
|
|
}
|
|
|
|
public function test_uncovered_periods_are_reported(): void
|
|
{
|
|
Season::factory()->for($this->property)->create(['starts_on' => '2026-04-03', 'ends_on' => '2026-05-23']);
|
|
|
|
$gaps = $this->property->uncoveredPeriods(CarbonImmutable::parse('2026-01-01'), CarbonImmutable::parse('2026-06-01'));
|
|
|
|
$this->assertSame(
|
|
[['2026-01-01', '2026-01-03'], ['2026-03-07', '2026-04-03'], ['2026-05-23', '2026-06-01']],
|
|
array_map(fn (array $gap): array => [$gap['from']->toDateString(), $gap['until']->toDateString()], $gaps),
|
|
);
|
|
}
|
|
|
|
public function test_seasons_are_copied_to_the_next_year_without_overwriting(): void
|
|
{
|
|
Season::factory()->for($this->property)->create(['name' => 'Bereits gepflegt', 'starts_on' => '2027-01-10', 'ends_on' => '2027-01-20']);
|
|
Season::factory()->for($this->property)->create(['name' => 'Sommer', 'starts_on' => '2026-06-20', 'ends_on' => '2026-08-29', 'nightly_rate' => 11500]);
|
|
|
|
$result = (new CopySeasonsToNextYear)->handle($this->property, 2026);
|
|
|
|
$this->assertSame(['created' => 1, 'skipped' => 1], $result);
|
|
$this->assertTrue($this->property->seasons()
|
|
->where('name', 'Sommer')
|
|
->where('nightly_rate', 11500)
|
|
->whereDate('starts_on', '2027-06-20')
|
|
->whereDate('ends_on', '2027-08-29')
|
|
->exists());
|
|
}
|
|
|
|
public function test_admin_pages_render(): void
|
|
{
|
|
$this->get(PropertyResource::getUrl('index'))->assertOk()->assertSee($this->property->name);
|
|
$this->get(PropertyResource::getUrl('edit', ['record' => $this->property]))->assertOk();
|
|
|
|
$this->seasonsManager()
|
|
->set('tableFilters.year.value', '2026')
|
|
->assertCanSeeTableRecords($this->property->seasons)
|
|
->assertSee('Ohne Preis');
|
|
}
|
|
|
|
public function test_price_calculator_action_shows_the_total(): void
|
|
{
|
|
$this->seasonsManager()
|
|
->callAction(TestAction::make('calculatePrice')->table(), [
|
|
'arrival' => '2026-01-10',
|
|
'departure' => '2026-01-13',
|
|
'guests' => 2,
|
|
])
|
|
->assertNotified();
|
|
}
|
|
|
|
private function seasonsManager(): mixed
|
|
{
|
|
return Livewire::test(SeasonsRelationManager::class, [
|
|
'ownerRecord' => $this->property,
|
|
'pageClass' => EditProperty::class,
|
|
]);
|
|
}
|
|
}
|