feat: add success messages for cart item operations in CartController

This commit is contained in:
2026-07-02 12:06:00 -03:00
parent 00837850e6
commit 18eedd3209
2 changed files with 11 additions and 9 deletions

View File

@@ -33,7 +33,9 @@ class CartController extends Controller
(int) $request->validated('cantidad'), (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) { if ($result['guest_token'] !== null) {
$response->withCookie($this->cartService->makeGuestTokenCookie($result['guest_token'])); $response->withCookie($this->cartService->makeGuestTokenCookie($result['guest_token']));
@@ -54,13 +56,13 @@ class CartController extends Controller
$productVariant->getKey(), $productVariant->getKey(),
(int) $request->validated('cantidad'), (int) $request->validated('cantidad'),
) )
); )->additional(['message' => 'Cantidad de producto actualizada.']);
} }
public function removeItem(Request $request, Tenant $tenant, ProductVariant $productVariant): CartResource public function removeItem(Request $request, Tenant $tenant, ProductVariant $productVariant): CartResource
{ {
return CartResource::make( return CartResource::make(
$this->cartService->removeItem($tenant, $request, $productVariant->getKey()) $this->cartService->removeItem($tenant, $request, $productVariant->getKey())
); )->additional(['message' => 'Producto eliminado del carrito.']);
} }
} }

View File

@@ -25,18 +25,18 @@ class AttachmentTest extends TestCase
$attachment = app(AttachmentService::class)->store( $attachment = app(AttachmentService::class)->store(
$file, $file,
'attachments/acme/logo.png', 'attachments/acme',
); );
$this->assertSame(AttachmentType::Image, $attachment->type); $this->assertSame(AttachmentType::Image, $attachment->type);
$this->assertTrue(Str::isUuid($attachment->key)); $this->assertTrue(Str::isUuid($attachment->key));
$this->assertSame('logo.png', $attachment->filename); $this->assertSame('logo.png', $attachment->filename);
$this->assertSame('attachments/acme/'.$attachment->key, $attachment->path); $this->assertSame('attachments/acme/'.$attachment->key.'.png', $attachment->path);
Storage::disk('s3')->assertExists('attachments/acme/'.$attachment->key); Storage::disk('s3')->assertExists('attachments/acme/'.$attachment->key.'.png');
$this->assertDatabaseHas('attachments', [ $this->assertDatabaseHas('attachments', [
'id' => $attachment->id, 'id' => $attachment->id,
'key' => $attachment->key, 'key' => $attachment->key,
'path' => 'attachments/acme/'.$attachment->key, 'path' => 'attachments/acme/'.$attachment->key.'.png',
'filename' => 'logo.png', 'filename' => 'logo.png',
'type' => AttachmentType::Image->value, 'type' => AttachmentType::Image->value,
]); ]);
@@ -55,13 +55,13 @@ class AttachmentTest extends TestCase
->andReturn($disk); ->andReturn($disk);
$disk->shouldReceive('putFileAs') $disk->shouldReceive('putFileAs')
->once() ->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); ->andReturn(false);
try { try {
app(AttachmentService::class)->store( app(AttachmentService::class)->store(
UploadedFile::fake()->create('manual.pdf', 10, 'application/pdf'), UploadedFile::fake()->create('manual.pdf', 10, 'application/pdf'),
'attachments/globex/manual.pdf', 'attachments/globex',
); );
$this->fail('Expected an AttachmentStorageException to be thrown.'); $this->fail('Expected an AttachmentStorageException to be thrown.');