Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for creating voucher
akjanikb0c6e79b24c1
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex 81aa59d865..dc421e05c5 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -1,6 +1,11 @@+import json+from django.shortcuts import reversefrom tests.utils import get_graphql_content+from saleor.discount import (+ DiscountValueType, VoucherApplyToProduct, VoucherType)+def test_voucher_permissions(staff_api_client, staff_group, staff_user, permission_view_voucher):@@ -89,3 +94,53 @@ def test_sale_query(assert data['type'] == sale.type.upper()assert data['name'] == sale.nameassert data['value'] == sale.value+++def test_create_voucher(user_api_client, admin_api_client):+ query = """+ mutation voucherCreate(+ $type: String, $name: String, $code: String, $applyTo: String+ $discountValueType: String, $discountValue: Decimal, $limit: Decimal) {+ voucherCreate(input: {+ name: $name, type: $type, code: $code, applyTo: $applyTo,+ discountValueType: $discountValueType, discountValue: $discountValue,+ limit: $limit}) {+ errors {+ field+ message+ }+ voucher {+ type+ limit {+ amount+ }+ applyTo+ name+ code+ discountValueType+ }+ }+ }+ """+ variables = json.dumps(+ {+ 'name': 'test voucher',+ 'type': VoucherType.VALUE,+ 'code': 'testcode123',+ 'applyTo': VoucherApplyToProduct.ALL_PRODUCTS,+ 'discountValueType': DiscountValueType.FIXED,+ 'discountValue': "10.12",+ 'limit': "1.12"+ }+ )+ response = admin_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ assert 'errors' not in content+ data = content['data']['voucherCreate']['voucher']+ assert data['type'] == VoucherType.VALUE.upper()+ assert data['limit']['amount'] == float("1.12")+ assert data['applyTo'] == VoucherApplyToProduct.ALL_PRODUCTS+ assert data['name'] == 'test voucher'+ assert data['code'] == 'testcode123'+ assert data['discountValueType'] == DiscountValueType.FIXED.upper()