Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Actions\SendOffer;
|
|
use App\Models\Booking;
|
|
use App\Models\Page;
|
|
use App\Models\Property;
|
|
use App\Models\Site;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class WebsiteTenancyTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->withoutVite();
|
|
}
|
|
|
|
public function test_one_landlord_still_answers_on_any_address(): void
|
|
{
|
|
$site = $this->website('Einzige Wohnung');
|
|
|
|
$this->get('http://fremd.test/')->assertOk()->assertSee('Einzige Wohnung');
|
|
$this->assertSame($site->id, Site::query()->where('is_default', true)->value('id'));
|
|
}
|
|
|
|
public function test_a_second_landlord_is_reached_only_on_their_own_address(): void
|
|
{
|
|
$this->website('Nordhaus', 'nordhaus.test');
|
|
$this->website('Südheim', 'suedheim.test');
|
|
|
|
$this->get('http://nordhaus.test/')->assertOk()->assertSee('Nordhaus')->assertDontSee('Südheim');
|
|
$this->get('http://suedheim.test/')->assertOk()->assertSee('Südheim')->assertDontSee('Nordhaus');
|
|
$this->get('http://unbekannt.test/')->assertNotFound();
|
|
}
|
|
|
|
public function test_the_offer_link_uses_the_website_address(): void
|
|
{
|
|
$site = $this->website('Nordhaus', 'nordhaus.test');
|
|
$property = Property::factory()->create(['site_id' => $site->id]);
|
|
$booking = Booking::factory()->for($property)->create([
|
|
'hold_expires_at' => now()->addDay(),
|
|
'offer_version' => 1,
|
|
]);
|
|
|
|
$url = app(SendOffer::class)->offerUrl($booking);
|
|
|
|
$this->assertStringStartsWith('https://nordhaus.test/angebot/', $url);
|
|
$this->assertStringContainsString('signature=', $url);
|
|
}
|
|
|
|
private function website(string $name, ?string $domain = null): Site
|
|
{
|
|
$tenant = Tenant::factory()->create();
|
|
$site = Site::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => $name,
|
|
'domain' => $domain,
|
|
'is_default' => $domain === null,
|
|
]);
|
|
Page::factory()->create([
|
|
'site_id' => $site->id,
|
|
'slug' => Page::HOME,
|
|
'title' => $name,
|
|
'sections' => [],
|
|
]);
|
|
|
|
return $site;
|
|
}
|
|
}
|