Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for collection voucher amonut calculation with sale
fowczarekc04939bcce22
diff --git a/tests/api/test_checkout_promo_codes.py b/tests/api/test_checkout_promo_codes.pyindex 12ac636d3c..b675532549 100644--- a/tests/api/test_checkout_promo_codes.py+++ b/tests/api/test_checkout_promo_codes.py@@ -345,6 +345,29 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(voucher.type = VoucherType.PRODUCTvoucher.save()voucher.products.add(product)++ assert checkout.get_subtotal() > checkout.get_subtotal(discounts=[discount_info])+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ variables = {"checkoutId": checkout_id, "promoCode": voucher.code}+ data = _mutate_checkout_add_promo_code(api_client, variables)++ checkout.refresh_from_db()+ assert not data["errors"]+ assert checkout.voucher_code == voucher.code+ assert checkout.discount_amount.amount == 1.5+++def test_checkout_add_collection_voucher_code_checkout_with_sale(+ api_client, checkout_with_item, voucher_percentage, discount_info, collection+):+ checkout = checkout_with_item+ voucher = voucher_percentage+ product = checkout.lines.first().variant.product+ product.collections.add(collection)+ voucher.type = VoucherType.COLLECTION+ voucher.save()+ voucher.collections.add(collection)+assert checkout.get_subtotal() > checkout.get_subtotal(discounts=[discount_info])checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)variables = {"checkoutId": checkout_id, "promoCode": voucher.code}diff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex 835756438f..e8ade8f36b 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -1174,9 +1174,10 @@ def test_get_discount_for_checkout_product_voucher_not_applicable(monkeypatch):def test_get_discount_for_checkout_collection_voucher_not_applicable(monkeypatch):+ discounts = []monkeypatch.setattr("saleor.checkout.utils.get_prices_of_products_in_discounted_collections", # noqa- lambda checkout, product: [],+ lambda checkout, discounts, product: [],)voucher = Voucher(code="unique",@@ -1188,7 +1189,7 @@ def test_get_discount_for_checkout_collection_voucher_not_applicable(monkeypatchcheckout = Mock()with pytest.raises(NotApplicable) as e:- get_voucher_discount_for_checkout(voucher, checkout)+ get_voucher_discount_for_checkout(voucher, checkout, discounts)assert str(e.value) == "This offer is only valid for selected items."