From 18eedd3209fb9e5ac5aebcd58bf3b53bf0310028 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 2 Jul 2026 12:06:00 -0300 Subject: [PATCH] feat: add success messages for cart item operations in CartController --- app/Domains/Cart/Controllers/CartController.php | 8 +++++--- tests/Feature/Attachable/AttachmentTest.php | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Domains/Cart/Controllers/CartController.php b/app/Domains/Cart/Controllers/CartController.php index b33ae61..3bd2f7b 100644 --- a/app/Domains/Cart/Controllers/CartController.php +++ b/app/Domains/Cart/Controllers/CartController.php @@ -33,7 +33,9 @@ class CartController extends Controller (int) $request->validated('cantidad'), ); - $response = CartResource::make($result['cart'])->response(); + $response = CartResource::make($result['cart']) + ->additional(['message' => 'Producto agregado al carrito.']) + ->response(); if ($result['guest_token'] !== null) { $response->withCookie($this->cartService->makeGuestTokenCookie($result['guest_token'])); @@ -54,13 +56,13 @@ class CartController extends Controller $productVariant->getKey(), (int) $request->validated('cantidad'), ) - ); + )->additional(['message' => 'Cantidad de producto actualizada.']); } public function removeItem(Request $request, Tenant $tenant, ProductVariant $productVariant): CartResource { return CartResource::make( $this->cartService->removeItem($tenant, $request, $productVariant->getKey()) - ); + )->additional(['message' => 'Producto eliminado del carrito.']); } } diff --git a/tests/Feature/Attachable/AttachmentTest.php b/tests/Feature/Attachable/AttachmentTest.php index 219b2f2..10efecc 100644 --- a/tests/Feature/Attachable/AttachmentTest.php +++ b/tests/Feature/Attachable/AttachmentTest.php @@ -25,18 +25,18 @@ class AttachmentTest extends TestCase $attachment = app(AttachmentService::class)->store( $file, - 'attachments/acme/logo.png', + 'attachments/acme', ); $this->assertSame(AttachmentType::Image, $attachment->type); $this->assertTrue(Str::isUuid($attachment->key)); $this->assertSame('logo.png', $attachment->filename); - $this->assertSame('attachments/acme/'.$attachment->key, $attachment->path); - Storage::disk('s3')->assertExists('attachments/acme/'.$attachment->key); + $this->assertSame('attachments/acme/'.$attachment->key.'.png', $attachment->path); + Storage::disk('s3')->assertExists('attachments/acme/'.$attachment->key.'.png'); $this->assertDatabaseHas('attachments', [ 'id' => $attachment->id, 'key' => $attachment->key, - 'path' => 'attachments/acme/'.$attachment->key, + 'path' => 'attachments/acme/'.$attachment->key.'.png', 'filename' => 'logo.png', 'type' => AttachmentType::Image->value, ]); @@ -55,13 +55,13 @@ class AttachmentTest extends TestCase ->andReturn($disk); $disk->shouldReceive('putFileAs') ->once() - ->with('attachments/globex', Mockery::type(UploadedFile::class), Mockery::on(static fn (string $value): bool => Str::isUuid($value))) + ->with('attachments/globex', Mockery::type(UploadedFile::class), Mockery::on(static fn (string $value): bool => Str::isUuid(pathinfo($value, PATHINFO_FILENAME)))) ->andReturn(false); try { app(AttachmentService::class)->store( UploadedFile::fake()->create('manual.pdf', 10, 'application/pdf'), - 'attachments/globex/manual.pdf', + 'attachments/globex', ); $this->fail('Expected an AttachmentStorageException to be thrown.');