Skip to content

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

Secure invoice request and create mutations to deny unconfirmed order

Tomasz Szymanskiba474736c837
diff --git a/saleor/graphql/invoice/mutations.py b/saleor/graphql/invoice/mutations.py
index 95ba6930e4..0b1ceea4c1 100644
--- a/saleor/graphql/invoice/mutations.py
+++ b/saleor/graphql/invoice/mutations.py
@@ -35,11 +35,11 @@ class InvoiceRequest(ModelMutation):
@staticmethod
def clean_order(order):
- if order.status == OrderStatus.DRAFT:
+ if order.status in (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED):
raise ValidationError(
{
"orderId": ValidationError(
- "Cannot request an invoice for draft order.",
+ "Cannot request an invoice for draft or unconfirmed order.",
code=InvoiceErrorCode.INVALID_STATUS,
)
}
@@ -121,11 +121,11 @@ class InvoiceCreate(ModelMutation):
@classmethod
def clean_order(cls, info, order):
- if order.status == OrderStatus.DRAFT:
+ if order.status in (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED):
raise ValidationError(
{
"orderId": ValidationError(
- "Cannot request an invoice for draft order.",
+ "Cannot create an invoice for draft or unconfirmed order.",
code=InvoiceErrorCode.INVALID_STATUS,
)
}
@@ -135,7 +135,7 @@ class InvoiceCreate(ModelMutation):
raise ValidationError(
{
"orderId": ValidationError(
- "Cannot request an invoice for order without billing address.",
+ "Cannot create an invoice for order without billing address.",
code=InvoiceErrorCode.NOT_READY,
)
}
diff --git a/saleor/graphql/invoice/tests/test_invoice_create.py b/saleor/graphql/invoice/tests/test_invoice_create.py
index 58f954a8f8..be437f837f 100644
--- a/saleor/graphql/invoice/tests/test_invoice_create.py
+++ b/saleor/graphql/invoice/tests/test_invoice_create.py
@@ -1,4 +1,5 @@
import graphene
+import pytest
from ....core import JobStatus
from ....graphql.tests.utils import get_graphql_content
@@ -86,10 +87,11 @@ def test_create_invoice_no_billing_address(
assert not order.events.filter(type=OrderEvents.INVOICE_GENERATED).exists()
-def test_create_invoice_for_draft_order(
- staff_api_client, permission_manage_orders, order
[email protected]("status", [OrderStatus.DRAFT, OrderStatus.UNCONFIRMED])
+def test_create_invoice_invalid_order_status(
+ status, staff_api_client, permission_manage_orders, order
):
- order.status = OrderStatus.DRAFT
+ order.status = status
order.save()
number = "01/12/2020/TEST"
url = "http://www.example.com"
diff --git a/saleor/graphql/invoice/tests/test_invoice_request.py b/saleor/graphql/invoice/tests/test_invoice_request.py
index 6878517e83..0208ddd28b 100644
--- a/saleor/graphql/invoice/tests/test_invoice_request.py
+++ b/saleor/graphql/invoice/tests/test_invoice_request.py
@@ -78,8 +78,11 @@ def test_invoice_request(
).exists()
-def test_invoice_request_draft_order(staff_api_client, permission_manage_orders, order):
- order.status = OrderStatus.DRAFT
[email protected]("status", [OrderStatus.DRAFT, OrderStatus.UNCONFIRMED])
+def test_invoice_request_invalid_order_status(
+ status, staff_api_client, permission_manage_orders, order
+):
+ order.status = status
order.save()
number = "01/12/2020/TEST"
variables = {
@@ -128,7 +131,7 @@ def test_invoice_request_no_number(staff_api_client, permission_manage_orders, o
assert not OrderEvent.objects.filter(type=OrderEvents.INVOICE_REQUESTED).exists()
-def test_invoice_request_invalid_order(staff_api_client, permission_manage_orders):
+def test_invoice_request_invalid_id(staff_api_client, permission_manage_orders):
variables = {"orderId": "T3JkZXI6MTMzNzEzMzc=", "number": "01/12/2020/TEST"}
response = staff_api_client.post_graphql(
INVOICE_REQUEST_MUTATION, variables, permissions=[permission_manage_orders]