178 lines
6.1 KiB
PHP
178 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domains\Event\Actions\CreateEvent\CreateEventCommand;
|
|
use App\Domains\Event\Actions\CreateEvent\CreateEventRequest;
|
|
use App\Domains\Event\Actions\UpdateEvent\UpdateEventCommand;
|
|
use App\Domains\Event\Actions\UpdateEvent\UpdateEventRequest;
|
|
use App\Enumerations\CostUnitType;
|
|
use App\Enumerations\EatingHabit;
|
|
use App\Enumerations\ParticipationFeeType;
|
|
use App\Models\CostUnit;
|
|
use App\Models\Event;
|
|
use App\Models\Tenant;
|
|
use App\Resources\EventResource;
|
|
use App\ValueObjects\Amount;
|
|
use DateTime;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class EventAddressTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Tenant $tenant;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->tenant = Tenant::create([
|
|
'slug' => 'tv',
|
|
'name' => 'Test',
|
|
'email' => 't@example.com',
|
|
'email_finance' => 'finance@example.com',
|
|
'url' => 'test.local',
|
|
'account_name' => 'Test e.V.',
|
|
'account_iban' => 'DE00',
|
|
'account_bic' => 'XY',
|
|
'city' => 'Stadt',
|
|
'postcode' => '00000',
|
|
'is_active_local_group' => true,
|
|
'has_active_instance' => true,
|
|
'tax_liable' => false,
|
|
'vat_rate' => 0,
|
|
'vat_pricing_mode' => 'inclusive',
|
|
]);
|
|
|
|
app()->instance('tenant', $this->tenant);
|
|
|
|
DB::table('cost_unit_types')->insert(['slug' => CostUnitType::COST_UNIT_TYPE_EVENT, 'name' => 'Veranstaltung']);
|
|
DB::table('participation_types')->insert(['slug' => 'participant', 'name' => 'Teilnehmer']);
|
|
DB::table('participation_fee_types')->insert(['slug' => 'fixed', 'name' => 'Fix']);
|
|
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGAN, 'name' => 'Vegan']);
|
|
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGETARIAN, 'name' => 'Vegetarisch']);
|
|
}
|
|
|
|
private function createEvent(?string $street = null, ?string $houseNumber = null): Event
|
|
{
|
|
$response = new CreateEventCommand(new CreateEventRequest(
|
|
name: 'Sommerlager',
|
|
location: 'Leipzig',
|
|
postalCode: '04103',
|
|
email: 'e@example.com',
|
|
begin: new DateTime('2026-09-01'),
|
|
end: new DateTime('2026-09-05'),
|
|
earlyBirdEnd: new DateTime('2026-08-20'),
|
|
registrationFinalEnd: new DateTime('2026-08-25'),
|
|
earlyBirdEndAmountIncrease: 0,
|
|
participationFeeType: ParticipationFeeType::where('slug', 'fixed')->first(),
|
|
accountOwner: 'Owner',
|
|
accountIban: 'DE00',
|
|
payPerDay: false,
|
|
street: $street,
|
|
houseNumber: $houseNumber,
|
|
))->execute();
|
|
|
|
$this->assertTrue($response->success);
|
|
|
|
return $response->event->fresh();
|
|
}
|
|
|
|
private function updateEvent(Event $event, ?string $street, ?string $houseNumber): Event
|
|
{
|
|
$response = new UpdateEventCommand(new UpdateEventRequest(
|
|
event: $event,
|
|
eventName: $event->name,
|
|
eventLocation: $event->location,
|
|
postalCode: $event->postal_code,
|
|
email: $event->email,
|
|
earlyBirdEnd: new DateTime('2026-08-20'),
|
|
registrationFinalEnd: new DateTime('2026-08-25'),
|
|
alcoholicsAge: 16,
|
|
sendWeeklyReports: true,
|
|
registrationAllowed: true,
|
|
flatSupport: Amount::fromString('0,00'),
|
|
supportPerPerson: Amount::fromString('0,00'),
|
|
contributingLocalGroups: [],
|
|
eatingHabits: [],
|
|
street: $street,
|
|
houseNumber: $houseNumber,
|
|
))->execute();
|
|
|
|
$this->assertTrue($response->success);
|
|
|
|
return $event->fresh();
|
|
}
|
|
|
|
public function test_anlage_speichert_strasse_und_hausnummer(): void
|
|
{
|
|
$event = $this->createEvent('Musterweg', '12');
|
|
|
|
$this->assertSame('Musterweg', $event->street);
|
|
$this->assertSame('12', $event->house_number);
|
|
}
|
|
|
|
public function test_anlage_ohne_angabe_laesst_beide_felder_leer(): void
|
|
{
|
|
$event = $this->createEvent();
|
|
|
|
$this->assertNull($event->street);
|
|
$this->assertNull($event->house_number);
|
|
}
|
|
|
|
public function test_leere_eingaben_werden_bei_der_anlage_zu_null(): void
|
|
{
|
|
$event = $this->createEvent('', ' ');
|
|
|
|
$this->assertNull($event->street);
|
|
$this->assertNull($event->house_number);
|
|
}
|
|
|
|
public function test_einstellungen_ergaenzen_und_leeren_die_anschrift(): void
|
|
{
|
|
$event = $this->updateEvent($this->createEvent(), 'Musterweg', '12');
|
|
|
|
$this->assertSame('Musterweg', $event->street);
|
|
$this->assertSame('12', $event->house_number);
|
|
|
|
$event = $this->updateEvent($event, '', '');
|
|
|
|
$this->assertNull($event->street);
|
|
$this->assertNull($event->house_number);
|
|
}
|
|
|
|
public function test_anschrift_enthaelt_strasse_nur_wenn_sie_gefuellt_ist(): void
|
|
{
|
|
$this->assertSame('Musterweg 12, 04103 Leipzig', $this->createEvent('Musterweg', '12')->getFullAddress());
|
|
$this->assertSame('04103 Leipzig', $this->createEvent()->getFullAddress());
|
|
}
|
|
|
|
public function test_resource_liefert_einzelfelder_und_fertige_anschrift(): void
|
|
{
|
|
$event = $this->createEvent('Musterweg', '12');
|
|
|
|
// Die Resource gibt auch die Kostenstelle aus; im Betrieb legt der Controller sie direkt nach
|
|
// der Veranstaltung an.
|
|
$event->cost_unit_id = CostUnit::create([
|
|
'tenant' => $this->tenant->slug,
|
|
'name' => 'Sommerlager',
|
|
'type' => CostUnitType::COST_UNIT_TYPE_EVENT,
|
|
'distance_allowance' => 0.25,
|
|
'mail_on_new' => false,
|
|
'allow_new' => true,
|
|
'archived' => false,
|
|
])->id;
|
|
$event->save();
|
|
|
|
$resource = new EventResource($event)->toArray(new Request());
|
|
|
|
$this->assertSame('Musterweg', $resource['street']);
|
|
$this->assertSame('12', $resource['houseNumber']);
|
|
$this->assertSame('Musterweg 12, 04103 Leipzig', $resource['fullAddress']);
|
|
}
|
|
}
|