Skip to content

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

Fix validation tests

Krzysztof Świąteka137441c59fe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f14171a4f7..e9c8826d3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -85,7 +85,6 @@ All notable, unreleased changes to this project will be documented in this file.
- Add pagination tests - #5363 by @fowczarek
- Add ability to assign multiple warehouses in mutations to create/update a shipping zone - #5399 by @fowczarek
- Add filter by ids to warehouses query - #5414 by @fowczarek
-
- Add product price validation - #5413 by @kswiatek92
## 2.9.0
diff --git a/saleor/graphql/product/bulk_mutations/products.py b/saleor/graphql/product/bulk_mutations/products.py
index df5037253e..982543a356 100644
--- a/saleor/graphql/product/bulk_mutations/products.py
+++ b/saleor/graphql/product/bulk_mutations/products.py
@@ -158,9 +158,9 @@ class ProductVariantBulkCreate(BaseMutation):
if cost_price_amount < 0:
raise ValidationError(
{
- "basePrice": ValidationError(
+ "costPrice": ValidationError(
"Product price cannot be lower than 0.",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
}
)
@@ -171,9 +171,9 @@ class ProductVariantBulkCreate(BaseMutation):
if price_override_amount < 0:
raise ValidationError(
{
- "basePrice": ValidationError(
+ "priceOverride": ValidationError(
"Product price cannot be lower than 0.",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
}
)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index b296f6ad6c..6940f26f64 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -1190,7 +1190,7 @@ class ProductVariantCreate(ModelMutation):
{
"costPrice": ValidationError(
"Product price cannot be lower than 0.",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
}
)
@@ -1203,7 +1203,7 @@ class ProductVariantCreate(ModelMutation):
{
"priceOverride": ValidationError(
"Product price cannot be lower than 0.",
- code=ProductErrorCode.INVALID,
+ code=ProductErrorCode.INVALID.value,
)
}
)
diff --git a/tests/api/test_variant.py b/tests/api/test_variant.py
index 13d2a44519..a377c6db51 100644
--- a/tests/api/test_variant.py
+++ b/tests/api/test_variant.py
@@ -887,6 +887,36 @@ def test_product_variant_bulk_create_by_attribute_id(
assert not product_variant.price_override
+def test_product_variant_bulk_create_by_attribute_id_with_invalid_price(
+ staff_api_client, product, size_attribute, permission_manage_products
+):
+ product_id = graphene.Node.to_global_id("Product", product.pk)
+ attribut_id = graphene.Node.to_global_id("Attribute", size_attribute.pk)
+ attribute_value = size_attribute.values.last()
+ sku = str(uuid4())[:12]
+ variants = [
+ {
+ "sku": sku,
+ "quantity": 1000,
+ "costPrice": None,
+ "priceOverride": "-1",
+ "weight": 2.5,
+ "trackInventory": True,
+ "attributes": [{"id": attribut_id, "values": [attribute_value.name]}],
+ }
+ ]
+
+ variables = {"productId": product_id, "variants": variants}
+ staff_api_client.user.user_permissions.add(permission_manage_products)
+ response = staff_api_client.post_graphql(
+ PRODUCT_VARIANT_BULK_CREATE_MUTATION, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["productVariantBulkCreate"]
+ assert data["bulkProductErrors"][0]["field"] == "priceOverride"
+ assert data["bulkProductErrors"][0]["code"] == ProductErrorCode.INVALID.name
+
+
def test_product_variant_bulk_create_empty_attribute(
staff_api_client, product, size_attribute, permission_manage_products
):