feat(ticket): add tickets endpoint and resource for sales; implement ticket retrieval logic and tests
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Models\PurchaseItem;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
@@ -85,6 +86,71 @@ class AdminAppSaleControllerTest extends TestCase
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_an_adminapp_user_can_read_all_tickets_from_a_sale_in_its_tenant(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$purchase = Purchase::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '20000.00',
|
||||
]);
|
||||
$firstTicket = Ticket::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'ticket' => '11111111-1111-4111-8111-111111111111',
|
||||
'name' => 'Abono general',
|
||||
'description' => 'Acceso general',
|
||||
'source_purchase_id' => $purchase->id,
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
$usedTicket = Ticket::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'ticket' => '22222222-2222-4222-8222-222222222222',
|
||||
'name' => 'Abono general',
|
||||
'description' => 'Acceso general',
|
||||
'source_purchase_id' => $purchase->id,
|
||||
'used_at' => now()->subMinute(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
$this->getJson("/api/v1/adminapp/tenant/sales/{$purchase->id}/tickets")
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'data' => [
|
||||
[
|
||||
'product' => 'Abono general',
|
||||
'id' => $firstTicket->id,
|
||||
'expires_at' => null,
|
||||
'status' => Ticket::STATUS_ACTIVE,
|
||||
],
|
||||
[
|
||||
'product' => 'Abono general',
|
||||
'id' => $usedTicket->id,
|
||||
'expires_at' => null,
|
||||
'status' => Ticket::STATUS_USED,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_an_adminapp_user_cannot_read_tickets_from_another_tenant_sale(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$foreignPurchase = Purchase::query()->create([
|
||||
'tenant_codigo' => $otherTenant->codigo,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '10000.00',
|
||||
]);
|
||||
|
||||
$this->getJson("/api/v1/adminapp/tenant/sales/{$foreignPurchase->id}/tickets")
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_an_adminapp_user_can_confirm_a_pending_sale(): void
|
||||
{
|
||||
Event::fake([PurchasePaid::class]);
|
||||
|
||||
Reference in New Issue
Block a user