Fix demo starter package seeding
This commit is contained in:
@@ -165,10 +165,10 @@ class SeedDemoSwitcherTenants extends Command
|
|||||||
{
|
{
|
||||||
$tenant = $this->upsertTenant(
|
$tenant = $this->upsertTenant(
|
||||||
slug: 'demo-standard-empty',
|
slug: 'demo-standard-empty',
|
||||||
name: 'Demo Standard (ohne Event)',
|
name: 'Demo Starter (ohne Event)',
|
||||||
contactEmail: 'standard-empty@demo.fotospiel',
|
contactEmail: 'standard-empty@demo.fotospiel',
|
||||||
attributes: [
|
attributes: [
|
||||||
'subscription_tier' => 'standard',
|
'subscription_tier' => 'starter',
|
||||||
'subscription_status' => 'active',
|
'subscription_status' => 'active',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -176,9 +176,9 @@ class SeedDemoSwitcherTenants extends Command
|
|||||||
$this->upsertAdmin($tenant, 'standard-empty@demo.fotospiel');
|
$this->upsertAdmin($tenant, 'standard-empty@demo.fotospiel');
|
||||||
|
|
||||||
TenantPackage::updateOrCreate(
|
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),
|
'purchased_at' => Carbon::now()->subDays(1),
|
||||||
'expires_at' => Carbon::now()->addMonths(12),
|
'expires_at' => Carbon::now()->addMonths(12),
|
||||||
'used_events' => 0,
|
'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
|
private function seedCustomerStarterWedding(array $packages, array $eventTypes): void
|
||||||
@@ -204,19 +204,19 @@ class SeedDemoSwitcherTenants extends Command
|
|||||||
$this->upsertAdmin($tenant, 'starter-wedding@demo.fotospiel');
|
$this->upsertAdmin($tenant, 'starter-wedding@demo.fotospiel');
|
||||||
|
|
||||||
TenantPackage::updateOrCreate(
|
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),
|
'purchased_at' => Carbon::now()->subDays(1),
|
||||||
'expires_at' => Carbon::now()->addMonths(12),
|
'expires_at' => Carbon::now()->addMonths(12),
|
||||||
'used_events' => 0,
|
'used_events' => 1,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$event = $this->upsertEvent(
|
$event = $this->upsertEvent(
|
||||||
tenant: $tenant,
|
tenant: $tenant,
|
||||||
package: $packages['standard'],
|
package: $packages['starter'],
|
||||||
eventType: $eventTypes['wedding'] ?? null,
|
eventType: $eventTypes['wedding'] ?? null,
|
||||||
attributes: [
|
attributes: [
|
||||||
'name' => ['de' => 'Hochzeit Mia & Jonas', 'en' => 'Wedding Mia & Jonas'],
|
'name' => ['de' => 'Hochzeit Mia & Jonas', 'en' => 'Wedding Mia & Jonas'],
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Button } from '@tamagui/button';
|
|||||||
import { useTheme } from '@tamagui/core';
|
import { useTheme } from '@tamagui/core';
|
||||||
|
|
||||||
const DEV_TENANT_KEYS = [
|
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: 'cust-starter-wedding', label: 'Endkunde – Starter (Hochzeit)' },
|
||||||
{ key: 'reseller-s-active', label: 'Reseller S – 3 aktive Events' },
|
{ key: 'reseller-s-active', label: 'Reseller S – 3 aktive Events' },
|
||||||
{ key: 'reseller-s-full', label: 'Reseller S – voll belegt (5/5)' },
|
{ key: 'reseller-s-full', label: 'Reseller S – voll belegt (5/5)' },
|
||||||
|
|||||||
@@ -2,82 +2,93 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Console\Commands\SeedDemoSwitcherTenants;
|
use App\Models\EventType;
|
||||||
use App\Models\Event;
|
use App\Models\Package;
|
||||||
use App\Models\MediaStorageTarget;
|
use App\Models\Tenant;
|
||||||
use App\Models\Photo;
|
use App\Models\TenantPackage;
|
||||||
use Illuminate\Console\OutputStyle;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class SeedDemoSwitcherTenantsTest extends TestCase
|
class SeedDemoSwitcherTenantsTest extends TestCase
|
||||||
{
|
{
|
||||||
use RefreshDatabase;
|
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([
|
$this->seedDemoPackages();
|
||||||
'key' => 'local-ssd',
|
$this->seedEventTypes();
|
||||||
'name' => 'Local SSD',
|
|
||||||
'driver' => 'local',
|
Artisan::call('demo:seed-switcher');
|
||||||
'config' => [],
|
|
||||||
'is_hot' => true,
|
$starterEmpty = Tenant::where('slug', 'demo-standard-empty')->firstOrFail();
|
||||||
'is_default' => true,
|
$starterPackage = TenantPackage::where('tenant_id', $starterEmpty->id)->with('package')->firstOrFail();
|
||||||
'is_active' => true,
|
|
||||||
'priority' => 10,
|
$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();
|
Package::factory()->create([
|
||||||
|
'slug' => 'standard',
|
||||||
$originalUrl = 'https://images.test/demo-original.jpg';
|
'name' => 'Standard',
|
||||||
$thumbUrl = 'https://images.test/demo-thumb.jpg';
|
'type' => 'endcustomer',
|
||||||
|
'max_events_per_year' => 5,
|
||||||
Http::fake([
|
|
||||||
$originalUrl => Http::response('demo-original', 200, ['Content-Type' => 'image/jpeg']),
|
|
||||||
$thumbUrl => Http::response('demo-thumb', 200, ['Content-Type' => 'image/jpeg']),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$command = app(SeedDemoSwitcherTenants::class);
|
Package::factory()->create([
|
||||||
$command->setOutput(new OutputStyle(new ArrayInput([]), new NullOutput));
|
'slug' => 's-small-reseller',
|
||||||
$method = new \ReflectionMethod($command, 'storePhotos');
|
'name' => 'Partner Start',
|
||||||
$method->setAccessible(true);
|
'type' => 'reseller',
|
||||||
|
'max_events_per_year' => 5,
|
||||||
$method->invoke($command, $event, [
|
'included_package_slug' => 'starter',
|
||||||
[
|
|
||||||
'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,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user