feat(ticket): add source IDs to tickets and update related services and tests

This commit is contained in:
2026-07-21 12:27:26 -03:00
parent c0978033c1
commit 38f74739da
6 changed files with 63 additions and 6 deletions

View File

@@ -61,6 +61,8 @@ class TicketGeneratorServiceTest extends TestCase
$this->assertSame($this->user->id, $ticket->user_id);
$this->assertSame($item->nombre, $ticket->name);
$this->assertSame($item->descripcion, $ticket->description);
$this->assertSame($item->id, $ticket->source_catalog_item_id);
$this->assertNull($ticket->source_variant_id);
$this->assertTrue($ticket->starts_at->equalTo($item->minimum_use_date));
$this->assertTrue($ticket->expires_at->equalTo($item->maximum_use_date));
}
@@ -100,6 +102,7 @@ class TicketGeneratorServiceTest extends TestCase
$tickets = $this->service->generate($bundle, $this->user, 2);
$this->assertCount(6, $tickets);
$this->assertCount(6, $tickets->where('source_catalog_item_id', $bundle->id));
$this->assertCount(4, $tickets->where('name', $first->nombre));
$this->assertCount(2, $tickets->where('name', $second->nombre));
}
@@ -139,6 +142,19 @@ class TicketGeneratorServiceTest extends TestCase
$this->assertDatabaseCount('tickets', 2);
}
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
{
$item = $this->createTicketableItem('sourced-ticket');
$purchase = $this->createPurchase($item, 1, 1234);
$purchase->markAsPaid();
$this->assertDatabaseHas('tickets', [
'source_catalog_item_id' => $item->id,
'source_variant_id' => 1234,
]);
}
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
{
$item = $this->createTicketableItem('regular-product');
@@ -195,8 +211,11 @@ class TicketGeneratorServiceTest extends TestCase
]);
}
private function createPurchase(CatalogItem $catalogItem, int $quantity): Purchase
{
private function createPurchase(
CatalogItem $catalogItem,
int $quantity,
?int $sourceVariantId = null,
): Purchase {
$purchase = Purchase::query()->create([
'tenant_codigo' => $this->tenant->codigo,
'user_id' => $this->user->id,
@@ -207,7 +226,7 @@ class TicketGeneratorServiceTest extends TestCase
$purchase->items()->create([
'source_catalog_item_id' => $catalogItem->id,
'source_variant_id' => null,
'source_variant_id' => $sourceVariantId,
'image_attachment_id' => null,
'nombre' => $catalogItem->nombre,
'descripcion' => $catalogItem->descripcion,