shopit-back/tests/Unit/FiestaFutbolInfantil/EntryResourceTest.php

46 lines
1.7 KiB
PHP

<?php
namespace Tests\Unit\FiestaFutbolInfantil;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Inventory;
use App\Domains\Catalog\Models\Variant;
use App\Domains\Event\Models\EventDate;
use App\Domains\FiestaFutbolInfantil\Resources\EntryResource;
use Illuminate\Http\Request;
use Illuminate\Support\MultipleItemsFoundException;
use Tests\TestCase;
class EntryResourceTest extends TestCase
{
public function test_it_reads_the_final_replacement_even_with_disabled_sales(): void
{
$original = new Variant(['replaced_by_variant_id' => 2]);
$intermediate = new Variant(['replaced_by_variant_id' => 3]);
$current = new Variant(['sales_disabled_at' => now()]);
$date = new EventDate;
$date->id = 13;
$current->setRelation('eventDates', collect([$date]));
$current->setRelation('inventory', new Inventory(['real_stock' => 20]));
$entry = new CatalogItem(['nombre' => 'Abono', 'precio' => 100]);
$entry->setRelation('variants', collect([$original, $intermediate, $current]));
$data = (new EntryResource($entry))->resolve(Request::create('/'));
$this->assertSame([13], $data['event_date_ids']->all());
$this->assertSame(20, $data['stock']);
$this->assertSame('Abono', $data['title']);
$this->assertNotNull($current->sales_disabled_at);
}
public function test_it_does_not_choose_arbitrarily_between_current_variants(): void
{
$entry = new CatalogItem;
$entry->setRelation('variants', collect([new Variant, new Variant]));
$this->expectException(MultipleItemsFoundException::class);
(new EntryResource($entry))->resolve(Request::create('/'));
}
}