Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Modify Sale/Voucher Inputs to use Date

Michał Jelonek10a86c6ee694
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index f382ec07f0..2c474e1692 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -82,9 +82,9 @@ class VoucherInput(graphene.InputObjectType):
description='Voucher type: product, category shipping or value.')
name = graphene.String(description='Voucher name.')
code = graphene.String(decription='Code to use the voucher.')
- start_date = graphene.types.datetime.DateTime(
+ start_date = graphene.types.datetime.Date(
description='Start date of the voucher in ISO 8601 format.')
- end_date = graphene.types.datetime.DateTime(
+ end_date = graphene.types.datetime.Date(
description='End date of the voucher in ISO 8601 format.')
discount_value_type = DiscountValueTypeEnum(
description='Choices: fixed or percentage.')
@@ -216,9 +216,9 @@ class SaleInput(graphene.InputObjectType):
collections = graphene.List(
graphene.ID, description='Collections related to the discount.',
name='collections')
- start_date = graphene.types.datetime.DateTime(
+ start_date = graphene.types.datetime.Date(
description='Start date of the sale in ISO 8601 format.')
- end_date = graphene.types.datetime.DateTime(
+ end_date = graphene.types.datetime.Date(
description='End date of the sale in ISO 8601 format.')
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 79991290f4..545a3aa495 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1696,8 +1696,8 @@ input SaleInput {
products: [ID]
categories: [ID]
collections: [ID]
- startDate: DateTime
- endDate: DateTime
+ startDate: Date
+ endDate: Date
}
type SaleRemoveCatalogues {
@@ -2110,8 +2110,8 @@ input VoucherInput {
type: VoucherTypeEnum
name: String
code: String
- startDate: DateTime
- endDate: DateTime
+ startDate: Date
+ endDate: Date
discountValueType: DiscountValueTypeEnum
discountValue: Decimal
products: [ID]
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.py
index 32c6e11797..f292185d7b 100644
--- a/tests/api/test_discount.py
+++ b/tests/api/test_discount.py
@@ -1,3 +1,5 @@
+from datetime import date
+
import graphene
import pytest
from django_countries import countries
@@ -99,12 +101,14 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):
mutation voucherCreate(
$type: VoucherTypeEnum, $name: String, $code: String,
$discountValueType: DiscountValueTypeEnum,
- $discountValue: Decimal, $minAmountSpent: Decimal) {
+ $discountValue: Decimal, $minAmountSpent: Decimal,
+ $startDate: Date, $endDate: Date) {
voucherCreate(input: {
name: $name, type: $type, code: $code,
discountValueType: $discountValueType,
discountValue: $discountValue,
- minAmountSpent: $minAmountSpent}) {
+ minAmountSpent: $minAmountSpent,
+ startDate: $startDate, endDate: $endDate}) {
errors {
field
message
@@ -117,17 +121,23 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):
name
code
discountValueType
+ startDate
+ endDate
}
}
}
"""
+ start_date = date(day=1, month=1, year=2018)
+ end_date = date(day=1, month=1, year=2019)
variables = {
'name': 'test voucher',
'type': VoucherTypeEnum.VALUE.name,
'code': 'testcode123',
'discountValueType': DiscountValueTypeEnum.FIXED.name,
'discountValue': 10.12,
- 'minAmountSpent': 1.12}
+ 'minAmountSpent': 1.12,
+ 'startDate': start_date.isoformat(),
+ 'endDate': end_date.isoformat()}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_discounts])
@@ -138,6 +148,8 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):
assert data['name'] == 'test voucher'
assert data['code'] == 'testcode123'
assert data['discountValueType'] == DiscountValueType.FIXED.upper()
+ assert data['startDate'] == start_date.isoformat()
+ assert data['endDate'] == end_date.isoformat()
def test_update_voucher(
@@ -340,31 +352,44 @@ def test_voucher_remove_no_catalogues(
def test_create_sale(staff_api_client, permission_manage_discounts):
query = """
mutation saleCreate(
- $type: DiscountValueTypeEnum, $name: String, $value: Decimal) {
- saleCreate(input: {name: $name, type: $type, value: $value}) {
- errors {
- field
- message
- }
- sale {
- type
- name
- value
- }
+ $type: DiscountValueTypeEnum, $name: String, $value: Decimal,
+ $startDate: Date, $endDate: Date) {
+ saleCreate(input: {
+ name: $name, type: $type, value: $value,
+ startDate: $startDate, endDate: $endDate}) {
+ sale {
+ type
+ name
+ value
+ startDate
+ endDate
+ }
+ errors {
+ field
+ message
}
}
+ }
"""
+ start_date = date(day=1, month=1, year=2018)
+ end_date = date(day=1, month=1, year=2019)
variables = {
'name': 'test sale',
'type': DiscountValueTypeEnum.FIXED.name,
- 'value': '10.12'}
+ 'value': '10.12',
+ 'startDate': start_date.isoformat(),
+ 'endDate': end_date.isoformat()}
+
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_discounts])
content = get_graphql_content(response)
data = content['data']['saleCreate']['sale']
+
assert data['type'] == DiscountValueType.FIXED.upper()
assert data['name'] == 'test sale'
assert data['value'] == 10.12
+ assert data['startDate'] == start_date.isoformat()
+ assert data['endDate'] == end_date.isoformat()
def test_update_sale(staff_api_client, sale, permission_manage_discounts):