feat: Add discountable flag to product (#329)
This commit is contained in:
committed by
GitHub
parent
821d8be733
commit
6053c4a8dd
@@ -18,8 +18,12 @@ describe("/store/carts", () => {
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "address"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
@@ -233,6 +237,44 @@ describe("/store/carts", () => {
|
||||
expect(cartWithShippingMethod.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("adds a giftcard to cart, but ensures discount only applied to discountable items", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// Add standard line item to cart
|
||||
await api.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
// Add gift card to cart
|
||||
await api.post(
|
||||
"/store/carts/test-cart/line-items",
|
||||
{
|
||||
variant_id: "giftcard-denom",
|
||||
quantity: 1,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
// Add a 10% discount to the cart
|
||||
const cartWithGiftcard = await api.post(
|
||||
"/store/carts/test-cart",
|
||||
{
|
||||
discounts: [{ code: "10PERCENT" }],
|
||||
},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
|
||||
// Ensure that the discount is only applied to the standard item
|
||||
expect(cartWithGiftcard.data.cart.total).toBe(1900); // 1000 (giftcard) + 900 (standard item with 10% discount)
|
||||
expect(cartWithGiftcard.data.cart.discount_total).toBe(100);
|
||||
expect(cartWithGiftcard.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("adds no more than 1 shipping method per shipping profile", async () => {
|
||||
const api = useApi();
|
||||
const addShippingMethod = async (option_id) => {
|
||||
|
||||
Reference in New Issue
Block a user