Skip to content

Commit

Permalink
Fix validation error when publishing a product without a category
Browse files Browse the repository at this point in the history
  • Loading branch information
maarcingebala committed Jul 24, 2020
1 parent 273eca0 commit a85dbe3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
5 changes: 3 additions & 2 deletions saleor/graphql/product/mutations/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,9 @@ def clean_input(cls, info, instance, data):
if not category and is_published:
raise ValidationError(
{
"isPublished": ValidationError(
"You must select a category to be able to publish"
"category": ValidationError(
"You must select a category to be able to publish",
code=ProductErrorCode.REQUIRED,
)
}
)
Expand Down
24 changes: 10 additions & 14 deletions saleor/graphql/product/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,8 @@ def test_product_create_without_category_and_true_is_published_value(
product {
id
}
errors {
message
productErrors {
code
field
}
}
Expand All @@ -1604,10 +1604,9 @@ def test_product_create_without_category_and_true_is_published_value(
{"productTypeId": product_type_id},
permissions=[permission_manage_products],
)
errors = get_graphql_content(response)["data"]["productCreate"]["errors"]

assert errors[0]["field"] == "isPublished"
assert errors[0]["message"] == "You must select a category to be able to publish"
errors = get_graphql_content(response)["data"]["productCreate"]["productErrors"]
assert errors[0]["field"] == "category"
assert errors[0]["code"] == ProductErrorCode.REQUIRED.name


def test_product_create_with_collections_webhook(
Expand Down Expand Up @@ -2265,8 +2264,8 @@ def test_update_product_without_category_and_true_is_published_value(
product {
id
}
errors {
message
productErrors {
code
field
}
}
Expand All @@ -2283,12 +2282,9 @@ def test_update_product_without_category_and_true_is_published_value(
)

data = get_graphql_content(response)["data"]["productUpdate"]
assert data["errors"]
assert data["errors"][0]["field"] == "isPublished"
assert (
data["errors"][0]["message"]
== "You must select a category to be able to publish"
)
assert data["productErrors"]
assert data["productErrors"][0]["field"] == "category"
assert data["productErrors"][0]["code"] == ProductErrorCode.REQUIRED.name


UPDATE_PRODUCT = """
Expand Down

0 comments on commit a85dbe3

Please sign in to comment.