Skip to content

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

Added subscription to CUSTOMER_DELETED (#19173)

Lukasz Ostrowski06b063ab9985
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 7936064a87..64e126cb96 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -36225,6 +36225,28 @@ type CustomerUpdated implements Event @doc(category: "Users") {
user: User
}
+"""
+Event sent when customer user is deleted.
+
+Added in Saleor 3.23.
+"""
+type CustomerDeleted implements Event @doc(category: "Users") {
+ """Time of the event."""
+ issuedAt: DateTime
+
+ """Saleor version that triggered the event."""
+ version: String
+
+ """The user or application that triggered the event."""
+ issuingPrincipal: IssuingPrincipal
+
+ """The application receiving the webhook."""
+ recipient: App
+
+ """The user the event relates to."""
+ user: User
+}
+
"""Event sent when customer user metadata is updated."""
type CustomerMetadataUpdated implements Event @doc(category: "Users") {
"""Time of the event."""
diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.py
index b3153a9174..ff5ebdff85 100644
--- a/saleor/graphql/webhook/subscription_types.py
+++ b/saleor/graphql/webhook/subscription_types.py
@@ -1601,6 +1601,14 @@ class CustomerMetadataUpdated(SubscriptionObjectType, UserBase):
description = "Event sent when customer user metadata is updated."
+class CustomerDeleted(SubscriptionObjectType, UserBase):
+ class Meta:
+ root_type = "User"
+ enable_dry_run = True
+ interfaces = (Event,)
+ description = "Event sent when customer user is deleted." + ADDED_IN_323
+
+
class CollectionBase(AbstractType):
collection = graphene.Field(
"saleor.graphql.product.types.collections.Collection",
@@ -3270,6 +3278,7 @@ ASYNC_WEBHOOK_TYPES_MAP = {
WebhookEventAsyncType.FULFILLMENT_METADATA_UPDATED: FulfillmentMetadataUpdated,
WebhookEventAsyncType.CUSTOMER_CREATED: CustomerCreated,
WebhookEventAsyncType.CUSTOMER_UPDATED: CustomerUpdated,
+ WebhookEventAsyncType.CUSTOMER_DELETED: CustomerDeleted,
WebhookEventAsyncType.CUSTOMER_METADATA_UPDATED: CustomerMetadataUpdated,
WebhookEventAsyncType.COLLECTION_CREATED: CollectionCreated,
WebhookEventAsyncType.COLLECTION_UPDATED: CollectionUpdated,
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index eff2bb8c7f..4e1ee2aec8 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -1477,6 +1477,7 @@ def async_subscription_webhooks_with_root_objects(
],
events.CUSTOMER_CREATED: [subscription_customer_created_webhook, customer_user],
events.CUSTOMER_UPDATED: [subscription_customer_updated_webhook, customer_user],
+ events.CUSTOMER_DELETED: [subscription_customer_deleted_webhook, customer_user],
events.CUSTOMER_METADATA_UPDATED: [
subscription_customer_metadata_updated_webhook,
customer_user,
diff --git a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
index 196a1a1a86..d3d61778c6 100644
--- a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
+++ b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
@@ -2238,17 +2238,17 @@ def test_customer_updated(customer_user, subscription_customer_updated_webhook):
assert deliveries[0].webhook == webhooks[0]
-def test_customer_deleted(customer_user, subscription_customer_created_webhook):
+def test_customer_deleted(customer_user, subscription_customer_deleted_webhook):
# given
customer_user_id = customer_user.id
customer_user.delete()
customer_user.id = customer_user_id
- webhooks = [subscription_customer_created_webhook]
- event_type = WebhookEventAsyncType.CUSTOMER_CREATED
+ webhooks = [subscription_customer_deleted_webhook]
+ event_type = WebhookEventAsyncType.CUSTOMER_DELETED
expected_payload = json.dumps(
generate_customer_payload(
- customer_user, subscription_customer_created_webhook.app
+ customer_user, subscription_customer_deleted_webhook.app
)
)