Skip to content

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

Webhook type fix typo and add enum descriptions

Krzysztof Wolski34a069d8742c
diff --git a/saleor/graphql/webhook/enums.py b/saleor/graphql/webhook/enums.py
index 3dab9b609f..17ff87fab5 100644
--- a/saleor/graphql/webhook/enums.py
+++ b/saleor/graphql/webhook/enums.py
@@ -3,9 +3,47 @@ import graphene
from ...webhook.event_types import WebhookEventType
from ..core.utils import str_to_enum
+
+def description(enum):
+ if enum == WebhookEventTypeEnum.CHECKOUT_CREATED:
+ return "A new checkout is created."
+ elif enum == WebhookEventTypeEnum.CHECKOUT_UPDATED:
+ return "A checkout is updated. Also triggers for all updates related to a checkout."
+ elif enum == WebhookEventTypeEnum.CUSTOMER_CREATED:
+ return "A new customer account is created."
+ elif enum == WebhookEventTypeEnum.ORDER_CREATED:
+ return "A new order is placed."
+ elif enum == WebhookEventTypeEnum.ORDER_CONFIRMED:
+ return "An order is confirmed (status change unconfirmed -> unfulfilled) by staff user using OrderConfirm mutation. Also triggers when user finish checkout and shop setting `automatically_confirm_all_new_orders` is enabled."
+ elif enum == WebhookEventTypeEnum.ORDER_FULLY_PAID:
+ return "Payment is made and an order is fully paid."
+ elif enum == WebhookEventTypeEnum.ORDER_UPDATED:
+ return "An order is updated; triggered for all changes related to an order; covers all other order webhooks, except for ORDER_CREATED."
+ elif enum == WebhookEventTypeEnum.ORDER_CANCELLED:
+ return "An order is cancelled."
+ elif enum == WebhookEventTypeEnum.ORDER_FULFILLED:
+ return "An order is fulfilled."
+ elif enum == WebhookEventTypeEnum.FULFILLMENT_CREATED:
+ return "A new fulfillment is created."
+ elif enum == WebhookEventTypeEnum.PRODUCT_CREATED:
+ return "A new product is created."
+ elif enum == WebhookEventTypeEnum.PRODUCT_UPDATED:
+ return "A product is updated."
+ elif enum == WebhookEventTypeEnum.INVOICE_REQUESTED:
+ return "An invoice for order requested."
+ elif enum == WebhookEventTypeEnum.INVOICE_DELETED:
+ return "An invoice is deleted."
+ elif enum == WebhookEventTypeEnum.INVOICE_SENT:
+ return "Invoice has been send."
+ elif enum == WebhookEventTypeEnum.ANY_EVENTS:
+ return "All the events."
+ return "Enum determining type of webhook."
+
+
WebhookEventTypeEnum = graphene.Enum(
"WebhookEventTypeEnum",
[(str_to_enum(e_type[0]), e_type[0]) for e_type in WebhookEventType.CHOICES],
+ description=description,
)
WebhookSampleEventTypeEnum = graphene.Enum(
"WebhookSampleEventTypeEnum",
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 41430da7da..903090cbf6 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -185,7 +185,7 @@ class WebhookPlugin(BasePlugin):
return previous_value
checkout_data = generate_checkout_payload(checkout)
trigger_webhooks_for_event.delay(
- WebhookEventType.CHECKOUT_UPADTED, checkout_data
+ WebhookEventType.CHECKOUT_UPDATED, checkout_data
)
def notify(self, event: "NotifyEventType", payload: dict, previous_value) -> Any:
diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.py
index f863988ea9..ab4169b31b 100644
--- a/saleor/plugins/webhook/tests/test_webhook.py
+++ b/saleor/plugins/webhook/tests/test_webhook.py
@@ -282,7 +282,7 @@ def test_checkout_updated(mocked_webhook_trigger, settings, checkout_with_items)
expected_data = generate_checkout_payload(checkout_with_items)
mocked_webhook_trigger.assert_called_once_with(
- WebhookEventType.CHECKOUT_UPADTED, expected_data
+ WebhookEventType.CHECKOUT_UPDATED, expected_data
)
diff --git a/saleor/webhook/event_types.py b/saleor/webhook/event_types.py
index cff6ab9a5e..784635eff0 100644
--- a/saleor/webhook/event_types.py
+++ b/saleor/webhook/event_types.py
@@ -34,7 +34,7 @@ class WebhookEventType:
PRODUCT_VARIANT_DELETED = "product_variant_deleted"
CHECKOUT_CREATED = "checkout_created"
- CHECKOUT_UPADTED = "checkout_updated"
+ CHECKOUT_UPDATED = "checkout_updated"
NOTIFY_USER = "notify_user"
@@ -62,7 +62,7 @@ class WebhookEventType:
PRODUCT_VARIANT_UPDATED: "Product variant updated",
PRODUCT_VARIANT_DELETED: "Product variant deleted",
CHECKOUT_CREATED: "Checkout created",
- CHECKOUT_UPADTED: "Checkout updated",
+ CHECKOUT_UPDATED: "Checkout updated",
FULFILLMENT_CREATED: "Fulfillment_created",
NOTIFY_USER: "Notify user",
PAGE_CREATED: "Page Created",
@@ -90,7 +90,7 @@ class WebhookEventType:
(PRODUCT_VARIANT_UPDATED, DISPLAY_LABELS[PRODUCT_VARIANT_UPDATED]),
(PRODUCT_VARIANT_DELETED, DISPLAY_LABELS[PRODUCT_VARIANT_DELETED]),
(CHECKOUT_CREATED, DISPLAY_LABELS[CHECKOUT_CREATED]),
- (CHECKOUT_UPADTED, DISPLAY_LABELS[CHECKOUT_UPADTED]),
+ (CHECKOUT_UPDATED, DISPLAY_LABELS[CHECKOUT_UPDATED]),
(FULFILLMENT_CREATED, DISPLAY_LABELS[FULFILLMENT_CREATED]),
(NOTIFY_USER, DISPLAY_LABELS[NOTIFY_USER]),
(PAGE_CREATED, DISPLAY_LABELS[PAGE_CREATED]),
@@ -117,7 +117,7 @@ class WebhookEventType:
PRODUCT_VARIANT_UPDATED: ProductPermissions.MANAGE_PRODUCTS,
PRODUCT_VARIANT_DELETED: ProductPermissions.MANAGE_PRODUCTS,
CHECKOUT_CREATED: CheckoutPermissions.MANAGE_CHECKOUTS,
- CHECKOUT_UPADTED: CheckoutPermissions.MANAGE_CHECKOUTS,
+ CHECKOUT_UPDATED: CheckoutPermissions.MANAGE_CHECKOUTS,
FULFILLMENT_CREATED: OrderPermissions.MANAGE_ORDERS,
NOTIFY_USER: AccountPermissions.MANAGE_USERS,
PAGE_CREATED: PagePermissions.MANAGE_PAGES,
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index a5bbc5158f..242e6f6e62 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -430,7 +430,7 @@ def _generate_sample_order_payload(event_name):
def generate_sample_payload(event_name: str) -> Optional[dict]:
checkout_events = [
- WebhookEventType.CHECKOUT_UPADTED,
+ WebhookEventType.CHECKOUT_UPDATED,
WebhookEventType.CHECKOUT_CREATED,
]
pages_events = [
diff --git a/saleor/webhook/tests/test_webhook_sample_payloads.py b/saleor/webhook/tests/test_webhook_sample_payloads.py
index cad313b236..d67aa02c91 100644
--- a/saleor/webhook/tests/test_webhook_sample_payloads.py
+++ b/saleor/webhook/tests/test_webhook_sample_payloads.py
@@ -148,7 +148,7 @@ def _remove_anonymized_checkout_data(checkout_data: dict) -> dict:
def test_generate_sample_checkout_payload(user_checkout_with_items):
checkout = user_checkout_with_items
- payload = generate_sample_payload(WebhookEventType.CHECKOUT_UPADTED)
+ payload = generate_sample_payload(WebhookEventType.CHECKOUT_UPDATED)
checkout_payload = json.loads(generate_checkout_payload(checkout))
# Check anonymized data differ
assert checkout.token != payload[0]["token"]