Skip to content

Commit 2c9ff46

Browse files
committed
Agregar check para carrito ID
1 parent c2465b6 commit 2c9ff46

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

services/cartService.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class CartService {
3636
}
3737

3838
static async getCartItems(cartId) {
39+
if (isNaN(cartId)) {
40+
throw new Error('Cart ID should be a number');
41+
}
42+
3943
const cart = await Cart.findByPk(cartId)
4044
if (!cart) {
4145
return null;

tests/routes/cart.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ describe('Cart Routes', () => {
5858
.get('/api/carts/1/items')
5959
.expect(404);
6060
});
61+
62+
it('should return 400 when cart id wrong format', async () => {
63+
const response = await request(app)
64+
.get('/api/carts/nonidad123/items')
65+
.expect(400);
66+
});
6167
});
6268
});

0 commit comments

Comments
 (0)