feat: add migration to expand tenant_codigo in bundles and update related seeders and tests
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Bundle\Models\Bundle;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_seeds_event_attributes_and_bundles(): void
|
||||
{
|
||||
$headerLogo = Attachment::query()->create([
|
||||
'path' => 'tests/header.png',
|
||||
'filename' => 'header.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$footerLogo = Attachment::query()->create([
|
||||
'path' => 'tests/footer.png',
|
||||
'filename' => 'footer.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
|
||||
$tenant = Tenant::query()->create([
|
||||
'codigo' => 'fiesta_futbol_infantil',
|
||||
'nombre' => 'Fiesta Fútbol Infantil',
|
||||
'dominio' => 'fiesta-futbol-infantil.localhost',
|
||||
'primary_color' => '#00973F',
|
||||
'secondary_color' => '#A0A0A0',
|
||||
'danger_color' => '#FF8888',
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#015327',
|
||||
'header_logo_id' => $headerLogo->id,
|
||||
'footer_logo_id' => $footerLogo->id,
|
||||
]);
|
||||
|
||||
$this->seed([
|
||||
AttributeSeeder::class,
|
||||
FiestaFutbolInfantilProductSeeder::class,
|
||||
]);
|
||||
|
||||
$this->assertFalse(Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->whereIn('codigo', ['color', 'talle', 'talle_numerico'])
|
||||
->exists());
|
||||
$this->assertSame(
|
||||
['fecha'],
|
||||
Attribute::query()->where('tenant_codigo', $tenant->codigo)->pluck('codigo')->all()
|
||||
);
|
||||
|
||||
$allDaysBundle = Bundle::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('nombre', 'Entrada General - Todos los días')
|
||||
->with('items.variant.product', 'items.variant.definitions')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('40000.00', $allDaysBundle->precio);
|
||||
$this->assertCount(4, $allDaysBundle->items);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||
$allDaysBundle->items->map(fn ($item) => $item->variant->definitions->sole()->value)->all()
|
||||
);
|
||||
$this->assertTrue($allDaysBundle->items->every(
|
||||
fn ($item) => $item->cantidad === 1 && $item->variant->product->slug === 'entrada-general'
|
||||
));
|
||||
|
||||
$foodBundle = Bundle::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('nombre', 'Combo 2 Panchos + 2 Hamburguesas')
|
||||
->with('items.variant.product')
|
||||
->sole();
|
||||
|
||||
$this->assertSame('24000.00', $foodBundle->precio);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[
|
||||
'pancho' => 2,
|
||||
'hamburguesa-papa-frita' => 2,
|
||||
],
|
||||
$foodBundle->items->mapWithKeys(
|
||||
fn ($item) => [$item->variant->product->slug => $item->cantidad]
|
||||
)->all()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user