feat: enhance cart functionality with quantity update and removal features, integrating toast notifications for user feedback

This commit is contained in:
2026-07-02 10:38:26 -03:00
parent f2cc42e0cc
commit c9d8265790
5 changed files with 91 additions and 13 deletions

View File

@@ -91,8 +91,8 @@ describe('CartService', () => {
const updatedCart = { ...mockCart, subtotal: '30.00' };
updatedCart.items[0].cantidad = 3;
service.updateItemQuantity(10, 3).subscribe((cart) => {
expect(cart).toEqual(updatedCart);
service.updateItemQuantity(10, 3).subscribe((res) => {
expect(res.data).toEqual(updatedCart);
expect(service.cart()).toEqual(updatedCart);
});
@@ -112,8 +112,8 @@ describe('CartService', () => {
subtotal: '0.00'
};
service.removeItem(10).subscribe((cart) => {
expect(cart).toEqual(emptyCart);
service.removeItem(10).subscribe((res) => {
expect(res.data).toEqual(emptyCart);
expect(service.cart()).toEqual(emptyCart);
});

View File

@@ -44,7 +44,7 @@ export class CartService {
);
}
updateItemQuantity(productVariantId: number, cantidad: number): Observable<Cart> {
updateItemQuantity(productVariantId: number, cantidad: number): Observable<ApiResponse<Cart>> {
return this.http
.patch<ApiResponse<Cart>>(
`${this.tenantApiUrl}/cart/items/${productVariantId}`,
@@ -52,20 +52,18 @@ export class CartService {
{ withCredentials: true }
)
.pipe(
map((response) => response.data),
tap((cart) => this.cartState.set(cart))
tap((response) => this.cartState.set(response.data))
);
}
removeItem(productVariantId: number): Observable<Cart> {
removeItem(productVariantId: number): Observable<ApiResponse<Cart>> {
return this.http
.delete<ApiResponse<Cart>>(
`${this.tenantApiUrl}/cart/items/${productVariantId}`,
{ withCredentials: true }
)
.pipe(
map((response) => response.data),
tap((cart) => this.cartState.set(cart))
tap((response) => this.cartState.set(response.data))
);
}
}