Fix demo starter package seeding
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-16 13:52:32 +01:00
parent a3f153de6f
commit 63956087a4
3 changed files with 84 additions and 73 deletions

View File

@@ -165,10 +165,10 @@ class SeedDemoSwitcherTenants extends Command
{
$tenant = $this->upsertTenant(
slug: 'demo-standard-empty',
name: 'Demo Standard (ohne Event)',
name: 'Demo Starter (ohne Event)',
contactEmail: 'standard-empty@demo.fotospiel',
attributes: [
'subscription_tier' => 'standard',
'subscription_tier' => 'starter',
'subscription_status' => 'active',
],
);
@@ -176,9 +176,9 @@ class SeedDemoSwitcherTenants extends Command
$this->upsertAdmin($tenant, 'standard-empty@demo.fotospiel');
TenantPackage::updateOrCreate(
['tenant_id' => $tenant->id, 'package_id' => $packages['standard']->id],
['tenant_id' => $tenant->id, 'package_id' => $packages['starter']->id],
[
'price' => $packages['standard']->price,
'price' => $packages['starter']->price,
'purchased_at' => Carbon::now()->subDays(1),
'expires_at' => Carbon::now()->addMonths(12),
'used_events' => 0,
@@ -186,7 +186,7 @@ class SeedDemoSwitcherTenants extends Command
]
);
$this->comment('Seeded Standard tenant without events.');
$this->comment('Seeded Starter tenant without events.');
}
private function seedCustomerStarterWedding(array $packages, array $eventTypes): void
@@ -204,19 +204,19 @@ class SeedDemoSwitcherTenants extends Command
$this->upsertAdmin($tenant, 'starter-wedding@demo.fotospiel');
TenantPackage::updateOrCreate(
['tenant_id' => $tenant->id, 'package_id' => $packages['standard']->id],
['tenant_id' => $tenant->id, 'package_id' => $packages['starter']->id],
[
'price' => $packages['standard']->price,
'price' => $packages['starter']->price,
'purchased_at' => Carbon::now()->subDays(1),
'expires_at' => Carbon::now()->addMonths(12),
'used_events' => 0,
'used_events' => 1,
'active' => true,
]
);
$event = $this->upsertEvent(
tenant: $tenant,
package: $packages['standard'],
package: $packages['starter'],
eventType: $eventTypes['wedding'] ?? null,
attributes: [
'name' => ['de' => 'Hochzeit Mia & Jonas', 'en' => 'Wedding Mia & Jonas'],

View File

@@ -6,7 +6,7 @@ import { Button } from '@tamagui/button';
import { useTheme } from '@tamagui/core';
const DEV_TENANT_KEYS = [
{ key: 'cust-standard-empty', label: 'Endkunde Standard (kein Event)' },
{ key: 'cust-standard-empty', label: 'Endkunde Starter (kein Event)' },
{ key: 'cust-starter-wedding', label: 'Endkunde Starter (Hochzeit)' },
{ key: 'reseller-s-active', label: 'Reseller S 3 aktive Events' },
{ key: 'reseller-s-full', label: 'Reseller S voll belegt (5/5)' },

View File

@@ -2,82 +2,93 @@
namespace Tests\Feature;
use App\Console\Commands\SeedDemoSwitcherTenants;
use App\Models\Event;
use App\Models\MediaStorageTarget;
use App\Models\Photo;
use Illuminate\Console\OutputStyle;
use App\Models\EventType;
use App\Models\Package;
use App\Models\Tenant;
use App\Models\TenantPackage;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class SeedDemoSwitcherTenantsTest extends TestCase
{
use RefreshDatabase;
public function test_demo_seeder_records_media_assets_on_event_disk(): void
public function testStarterEmptyTenantHasOneRemainingEvent(): void
{
Storage::fake('local-ssd');
config(['app.env' => 'local']);
app()->detectEnvironment(fn () => 'local');
MediaStorageTarget::create([
'key' => 'local-ssd',
'name' => 'Local SSD',
'driver' => 'local',
'config' => [],
'is_hot' => true,
'is_default' => true,
'is_active' => true,
'priority' => 10,
$this->seedDemoPackages();
$this->seedEventTypes();
Artisan::call('demo:seed-switcher');
$starterEmpty = Tenant::where('slug', 'demo-standard-empty')->firstOrFail();
$starterPackage = TenantPackage::where('tenant_id', $starterEmpty->id)->with('package')->firstOrFail();
$this->assertSame('starter', $starterPackage->package->slug);
$this->assertSame(0, $starterPackage->used_events);
$this->assertSame(1, $starterPackage->package->max_events_per_year - $starterPackage->used_events);
}
public function testStarterWeddingTenantConsumesEvent(): void
{
config(['app.env' => 'local']);
app()->detectEnvironment(fn () => 'local');
$this->seedDemoPackages();
$this->seedEventTypes();
Artisan::call('demo:seed-switcher');
$starterWedding = Tenant::where('slug', 'demo-starter-wedding')->firstOrFail();
$starterPackage = TenantPackage::where('tenant_id', $starterWedding->id)->with('package')->firstOrFail();
$this->assertSame('starter', $starterPackage->package->slug);
$this->assertSame(1, $starterPackage->used_events);
$this->assertSame(0, $starterPackage->package->max_events_per_year - $starterPackage->used_events);
}
private function seedDemoPackages(): void
{
Package::factory()->create([
'slug' => 'starter',
'name' => 'Starter',
'type' => 'endcustomer',
'max_events_per_year' => 1,
]);
$event = Event::factory()->create();
$originalUrl = 'https://images.test/demo-original.jpg';
$thumbUrl = 'https://images.test/demo-thumb.jpg';
Http::fake([
$originalUrl => Http::response('demo-original', 200, ['Content-Type' => 'image/jpeg']),
$thumbUrl => Http::response('demo-thumb', 200, ['Content-Type' => 'image/jpeg']),
Package::factory()->create([
'slug' => 'standard',
'name' => 'Standard',
'type' => 'endcustomer',
'max_events_per_year' => 5,
]);
$command = app(SeedDemoSwitcherTenants::class);
$command->setOutput(new OutputStyle(new ArrayInput([]), new NullOutput));
$method = new \ReflectionMethod($command, 'storePhotos');
$method->setAccessible(true);
$method->invoke($command, $event, [
[
'src' => [
'large2x' => $originalUrl,
'medium' => $thumbUrl,
],
],
], 1);
$photo = Photo::where('event_id', $event->id)->first();
$this->assertNotNull($photo);
$this->assertNotNull($photo->media_asset_id);
$this->assertSame('approved', $photo->status);
Storage::disk('local-ssd')->assertExists($photo->file_path);
Storage::disk('local-ssd')->assertExists($photo->thumbnail_path);
$this->assertDatabaseHas('event_media_assets', [
'photo_id' => $photo->id,
'variant' => 'original',
'disk' => 'local-ssd',
'path' => $photo->file_path,
]);
$this->assertDatabaseHas('event_media_assets', [
'photo_id' => $photo->id,
'variant' => 'thumbnail',
'disk' => 'local-ssd',
'path' => $photo->thumbnail_path,
Package::factory()->create([
'slug' => 's-small-reseller',
'name' => 'Partner Start',
'type' => 'reseller',
'max_events_per_year' => 5,
'included_package_slug' => 'starter',
]);
}
private function seedEventTypes(): void
{
$types = [
'wedding' => ['de' => 'Hochzeit', 'en' => 'Wedding'],
'corporate' => ['de' => 'Business', 'en' => 'Corporate'],
'birthday' => ['de' => 'Geburtstag', 'en' => 'Birthday'],
'festival' => ['de' => 'Festival', 'en' => 'Festival'],
];
foreach ($types as $slug => $name) {
EventType::factory()->create([
'slug' => $slug,
'name' => $name,
]);
}
}
}