From f74bf41931f72f91d9ffe6901e11d4714e9004f6 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 2 Sep 2026 12:42:00 -0300 Subject: [PATCH] feat(forms): expose grouped admin sale statuses --- .../Forms/Services/SaleFormService.php | 23 +++----- .../Forms/AdminAppSaleFormControllerTest.php | 55 ++++++++++++++----- tests/Unit/Forms/SaleFormServiceTest.php | 27 +++++---- 3 files changed, 66 insertions(+), 39 deletions(-) diff --git a/app/Domains/Forms/Services/SaleFormService.php b/app/Domains/Forms/Services/SaleFormService.php index 8064968..8ddcead 100644 --- a/app/Domains/Forms/Services/SaleFormService.php +++ b/app/Domains/Forms/Services/SaleFormService.php @@ -6,27 +6,18 @@ use App\Domains\Purchase\Models\Purchase; class SaleFormService { - /** @return array{statuses: list} */ + /** @return array{statuses: list}>} */ public function get(): array { - $names = [ - Purchase::STATUS_CREATED => 'Creada', - Purchase::STATUS_PENDING_PAYMENT => 'Esperando pago', - Purchase::STATUS_IN_REVIEW => 'En revisión', - Purchase::STATUS_PAID => 'Confirmada', - Purchase::STATUS_CANCELLED => 'Cancelada', - Purchase::STATUS_REJECTED => 'Rechazada', - Purchase::STATUS_EXPIRED => 'Vencida', - Purchase::STATUS_SUPERSEDED => 'Reemplazada', - ]; - return [ 'statuses' => array_map( - fn (string $status): array => [ - 'code' => $status, - 'name' => $names[$status], + fn (string $code, array $definition): array => [ + 'value' => $code, + 'label' => $definition['name'], + 'real_statuses' => $definition['statuses'], ], - Purchase::statuses(), + array_keys(Purchase::adminStatuses()), + array_values(Purchase::adminStatuses()), ), ]; } diff --git a/tests/Feature/Forms/AdminAppSaleFormControllerTest.php b/tests/Feature/Forms/AdminAppSaleFormControllerTest.php index da33dd9..4b90bcb 100644 --- a/tests/Feature/Forms/AdminAppSaleFormControllerTest.php +++ b/tests/Feature/Forms/AdminAppSaleFormControllerTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Forms; +use App\Domains\Attachable\Enums\AttachmentType; +use App\Domains\Attachable\Models\Attachment; use App\Domains\Auth\Models\User; use App\Domains\Authorization\Enums\RoleCode; use App\Domains\Purchase\Models\Purchase; @@ -34,12 +36,7 @@ class AdminAppSaleFormControllerTest extends TestCase public function test_an_adminapp_user_can_get_the_sale_form(): void { - $tenant = Tenant::query()->create([ - 'codigo' => 'acme', - 'nombre' => 'Acme', - 'dominio' => 'acme.test', - 'website_type_code' => 'onticket', - ]); + $tenant = $this->createTenant('acme'); Sanctum::actingAs(User::factory()->create([ 'rol_codigo' => RoleCode::AdminApp->value, 'tenant_codigo' => $tenant->codigo, @@ -47,13 +44,15 @@ class AdminAppSaleFormControllerTest extends TestCase $this->getJson('/api/v1/adminapp/forms/sale') ->assertOk() - ->assertJsonCount(count(Purchase::statuses()), 'data.statuses') - ->assertJsonPath('data.statuses.0.code', Purchase::STATUS_CREATED) - ->assertJsonPath('data.statuses.0.name', 'Creada') - ->assertJsonPath('data.statuses.1.code', Purchase::STATUS_PENDING_PAYMENT) - ->assertJsonPath('data.statuses.2.code', Purchase::STATUS_IN_REVIEW) - ->assertJsonPath('data.statuses.3.code', Purchase::STATUS_PAID) - ->assertJsonPath('data.statuses.6.code', Purchase::STATUS_EXPIRED); + ->assertJsonCount(count(Purchase::adminStatusCodes()), 'data.statuses') + ->assertJsonPath('data.statuses.0.value', Purchase::ADMIN_STATUS_INCOMPLETE) + ->assertJsonPath('data.statuses.0.label', 'Por completar datos') + ->assertJsonPath('data.statuses.0.real_statuses.0', Purchase::STATUS_CREATED) + ->assertJsonPath('data.statuses.1.value', Purchase::ADMIN_STATUS_AWAITING_PAYMENT) + ->assertJsonPath('data.statuses.1.real_statuses.0', Purchase::STATUS_PENDING_PAYMENT) + ->assertJsonPath('data.statuses.1.real_statuses.1', Purchase::STATUS_IN_REVIEW) + ->assertJsonPath('data.statuses.2.value', Purchase::ADMIN_STATUS_CONFIRMED) + ->assertJsonPath('data.statuses.3.value', Purchase::ADMIN_STATUS_CANCELLED); } public function test_a_customer_cannot_get_the_sale_form(): void @@ -65,4 +64,34 @@ class AdminAppSaleFormControllerTest extends TestCase $this->getJson('/api/v1/adminapp/forms/sale')->assertForbidden(); } + + private function createTenant(string $code): Tenant + { + $headerLogo = $this->createAttachment("{$code}-header"); + $footerLogo = $this->createAttachment("{$code}-footer"); + + return Tenant::query()->create([ + 'codigo' => $code, + 'nombre' => ucfirst($code), + 'dominio' => "{$code}.test", + 'primary_color' => '#000000', + 'secondary_color' => '#ffffff', + 'danger_color' => '#dc3545', + 'header_bg_color' => '#ffffff', + 'footer_bg_color' => '#000000', + 'header_logo_id' => $headerLogo->id, + 'footer_logo_id' => $footerLogo->id, + 'website_type_code' => 'onticket', + ]); + } + + private function createAttachment(string $name): Attachment + { + return Attachment::query()->create([ + 'path' => "test/{$name}.png", + 'filename' => "{$name}.png", + 'type' => AttachmentType::Image, + 'mime_type' => 'image/png', + ]); + } } diff --git a/tests/Unit/Forms/SaleFormServiceTest.php b/tests/Unit/Forms/SaleFormServiceTest.php index e2f5518..741e2d4 100644 --- a/tests/Unit/Forms/SaleFormServiceTest.php +++ b/tests/Unit/Forms/SaleFormServiceTest.php @@ -8,20 +8,27 @@ use PHPUnit\Framework\TestCase; class SaleFormServiceTest extends TestCase { - public function test_it_returns_every_purchase_status_as_a_form_option(): void + public function test_it_returns_admin_statuses_with_their_real_statuses(): void { $form = (new SaleFormService)->get(); - $this->assertSame(Purchase::statuses(), array_column($form['statuses'], 'code')); + $this->assertSame(Purchase::adminStatusCodes(), array_column($form['statuses'], 'value')); $this->assertSame([ - 'Creada', + 'Por completar datos', 'Esperando pago', - 'En revisión', - 'Confirmada', - 'Cancelada', - 'Rechazada', - 'Vencida', - 'Reemplazada', - ], array_column($form['statuses'], 'name')); + 'Confirmado', + 'Anulado', + ], array_column($form['statuses'], 'label')); + $this->assertSame([ + [Purchase::STATUS_CREATED], + [Purchase::STATUS_PENDING_PAYMENT, Purchase::STATUS_IN_REVIEW], + [Purchase::STATUS_PAID], + [ + Purchase::STATUS_CANCELLED, + Purchase::STATUS_REJECTED, + Purchase::STATUS_EXPIRED, + Purchase::STATUS_SUPERSEDED, + ], + ], array_column($form['statuses'], 'real_statuses')); } }