Skip to content

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

Add filterable subscription for order webhooks (#16323)

Maciej Korycinskif3a0bc28797b
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 62751606fd..baf95cb8c7 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -32447,6 +32447,216 @@ type Subscription @doc(category: "Miscellaneous") {
Added in Saleor 3.2.
"""
event: Event
+
+ """
+ Event sent when new draft order is created.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ draftOrderCreated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): DraftOrderCreated
+
+ """
+ Event sent when draft order is updated.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ draftOrderUpdated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): DraftOrderUpdated
+
+ """
+ Event sent when draft order is deleted.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ draftOrderDeleted(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): DraftOrderDeleted
+
+ """
+ Event sent when new order is created.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderCreated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderCreated
+
+ """
+ Event sent when order is updated.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderUpdated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderUpdated
+
+ """
+ Event sent when order is confirmed.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderConfirmed(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderConfirmed
+
+ """
+ Payment has been made. The order may be partially or fully paid.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderPaid(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderPaid
+
+ """
+ Event sent when order is fully paid.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderFullyPaid(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderFullyPaid
+
+ """
+ The order received a refund. The order may be partially or fully refunded.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderRefunded(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderRefunded
+
+ """
+ The order is fully refunded.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderFullyRefunded(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderFullyRefunded
+
+ """
+ Event sent when order is fulfilled.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderFulfilled(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderFulfilled
+
+ """
+ Event sent when order is cancelled.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderCancelled(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderCancelled
+
+ """
+ Event sent when order becomes expired.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderExpired(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderExpired
+
+ """
+ Event sent when order metadata is updated.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderMetadataUpdated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderMetadataUpdated
+
+ """
+ Event sent when orders are imported.
+
+ Added in Saleor 3.20.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+ """
+ orderBulkCreated(
+ """
+ List of channel slugs. The event will be sent only if the order belongs to one of the provided channels. If the channel slug list is empty, orders that belong to any channel will be sent. Maximally 500 items.
+ """
+ channels: [String!]
+ ): OrderBulkCreated
}
interface Event {
@@ -32465,53 +32675,12 @@ interface Event {
union IssuingPrincipal = App | User
-"""An enumeration."""
-enum DistanceUnitsEnum {
- MM
- CM
- DM
- M
- KM
- FT
- YD
- INCH
-}
-
-"""An enumeration."""
-enum AreaUnitsEnum {
- SQ_MM
- SQ_CM
- SQ_DM
- SQ_M
- SQ_KM
- SQ_FT
- SQ_YD
- SQ_INCH
-}
-
-"""An enumeration."""
-enum VolumeUnitsEnum {
- CUBIC_MILLIMETER
- CUBIC_CENTIMETER
- CUBIC_DECIMETER
- CUBIC_METER
- LITER
- CUBIC_FOOT
- CUBIC_INCH
- CUBIC_YARD
- QT
- PINT
- FL_OZ
- ACRE_IN
- ACRE_FT
-}
-
"""
-Event sent when account confirmation requested. This event is always sent. enableAccountConfirmationByEmail flag set to True is not required.
+Event sent when new draft order is created.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountConfirmationRequested implements Event @doc(category: "Users") {
+type DraftOrderCreated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32524,28 +32693,16 @@ type AccountConfirmationRequested implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when account change email is requested.
+Event sent when draft order is updated.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountChangeEmailRequested implements Event @doc(category: "Users") {
+type DraftOrderUpdated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32558,31 +32715,16 @@ type AccountChangeEmailRequested implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
-
- """The new email address the user wants to change to."""
- newEmail: String
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when account email is changed.
+Event sent when draft order is deleted.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountEmailChanged implements Event @doc(category: "Users") {
+type DraftOrderDeleted implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32595,31 +32737,16 @@ type AccountEmailChanged implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
-
- """The new email address."""
- newEmail: String
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when setting a new password is requested.
+Event sent when new order is created.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountSetPasswordRequested implements Event @doc(category: "Users") {
+type OrderCreated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32632,28 +32759,16 @@ type AccountSetPasswordRequested implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when account is confirmed.
+Event sent when order is updated.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountConfirmed implements Event @doc(category: "Users") {
+type OrderUpdated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32666,28 +32781,16 @@ type AccountConfirmed implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when account delete is requested.
+Event sent when order is confirmed.
-Added in Saleor 3.15.
+Added in Saleor 3.2.
"""
-type AccountDeleteRequested implements Event @doc(category: "Users") {
+type OrderConfirmed implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32700,28 +32803,18 @@ type AccountDeleteRequested implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when account is deleted.
+Payment has been made. The order may be partially or fully paid.
-Added in Saleor 3.15.
+Added in Saleor 3.14.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type AccountDeleted implements Event @doc(category: "Users") {
+type OrderPaid implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32734,28 +32827,16 @@ type AccountDeleted implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The URL to redirect the user after he accepts the request."""
- redirectUrl: String
-
- """The user the event relates to."""
- user: User
-
- """The channel data."""
- channel: Channel
-
- """The token required to confirm request."""
- token: String
-
- """Shop data."""
- shop: Shop
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when new address is created.
+Event sent when order is fully paid.
-Added in Saleor 3.5.
+Added in Saleor 3.2.
"""
-type AddressCreated implements Event @doc(category: "Users") {
+type OrderFullyPaid implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32768,16 +32849,18 @@ type AddressCreated implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The address the event relates to."""
- address: Address
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when address is updated.
+The order received a refund. The order may be partially or fully refunded.
-Added in Saleor 3.5.
+Added in Saleor 3.14.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type AddressUpdated implements Event @doc(category: "Users") {
+type OrderRefunded implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32790,16 +32873,18 @@ type AddressUpdated implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The address the event relates to."""
- address: Address
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when address is deleted.
+The order is fully refunded.
-Added in Saleor 3.5.
+Added in Saleor 3.14.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type AddressDeleted implements Event @doc(category: "Users") {
+type OrderFullyRefunded implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32812,16 +32897,16 @@ type AddressDeleted implements Event @doc(category: "Users") {
"""The application receiving the webhook."""
recipient: App
- """The address the event relates to."""
- address: Address
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when new app is installed.
+Event sent when order is fulfilled.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type AppInstalled implements Event @doc(category: "Apps") {
+type OrderFulfilled implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32834,16 +32919,16 @@ type AppInstalled implements Event @doc(category: "Apps") {
"""The application receiving the webhook."""
recipient: App
- """The application the event relates to."""
- app: App
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when app is updated.
+Event sent when order is canceled.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type AppUpdated implements Event @doc(category: "Apps") {
+type OrderCancelled implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32856,16 +32941,18 @@ type AppUpdated implements Event @doc(category: "Apps") {
"""The application receiving the webhook."""
recipient: App
- """The application the event relates to."""
- app: App
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when app is deleted.
+Event sent when order becomes expired.
-Added in Saleor 3.4.
+Added in Saleor 3.13.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type AppDeleted implements Event @doc(category: "Apps") {
+type OrderExpired implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32878,16 +32965,16 @@ type AppDeleted implements Event @doc(category: "Apps") {
"""The application receiving the webhook."""
recipient: App
- """The application the event relates to."""
- app: App
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when app status has changed.
+Event sent when order metadata is updated.
-Added in Saleor 3.4.
+Added in Saleor 3.8.
"""
-type AppStatusChanged implements Event @doc(category: "Apps") {
+type OrderMetadataUpdated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32900,16 +32987,18 @@ type AppStatusChanged implements Event @doc(category: "Apps") {
"""The application receiving the webhook."""
recipient: App
- """The application the event relates to."""
- app: App
+ """The order the event relates to."""
+ order: Order
}
"""
-Event sent when new attribute is created.
+Event sent when orders are imported.
-Added in Saleor 3.5.
+Added in Saleor 3.14.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type AttributeCreated implements Event @doc(category: "Attributes") {
+type OrderBulkCreated implements Event @doc(category: "Orders") {
"""Time of the event."""
issuedAt: DateTime
@@ -32922,16 +33011,57 @@ type AttributeCreated implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute the event relates to."""
- attribute: Attribute
+ """The orders the event relates to."""
+ orders: [Order!]
+}
+
+"""An enumeration."""
+enum DistanceUnitsEnum {
+ MM
+ CM
+ DM
+ M
+ KM
+ FT
+ YD
+ INCH
+}
+
+"""An enumeration."""
+enum AreaUnitsEnum {
+ SQ_MM
+ SQ_CM
+ SQ_DM
+ SQ_M
+ SQ_KM
+ SQ_FT
+ SQ_YD
+ SQ_INCH
+}
+
+"""An enumeration."""
+enum VolumeUnitsEnum {
+ CUBIC_MILLIMETER
+ CUBIC_CENTIMETER
+ CUBIC_DECIMETER
+ CUBIC_METER
+ LITER
+ CUBIC_FOOT
+ CUBIC_INCH
+ CUBIC_YARD
+ QT
+ PINT
+ FL_OZ
+ ACRE_IN
+ ACRE_FT
}
"""
-Event sent when attribute is updated.
+Event sent when account confirmation requested. This event is always sent. enableAccountConfirmationByEmail flag set to True is not required.
-Added in Saleor 3.5.
+Added in Saleor 3.15.
"""
-type AttributeUpdated implements Event @doc(category: "Attributes") {
+type AccountConfirmationRequested implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -32944,16 +33074,28 @@ type AttributeUpdated implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute the event relates to."""
- attribute: Attribute
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
}
"""
-Event sent when attribute is deleted.
+Event sent when account change email is requested.
-Added in Saleor 3.5.
+Added in Saleor 3.15.
"""
-type AttributeDeleted implements Event @doc(category: "Attributes") {
+type AccountChangeEmailRequested implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -32966,16 +33108,31 @@ type AttributeDeleted implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute the event relates to."""
- attribute: Attribute
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
+
+ """The new email address the user wants to change to."""
+ newEmail: String
}
"""
-Event sent when new attribute value is created.
+Event sent when account email is changed.
-Added in Saleor 3.5.
+Added in Saleor 3.15.
"""
-type AttributeValueCreated implements Event @doc(category: "Attributes") {
+type AccountEmailChanged implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -32988,16 +33145,31 @@ type AttributeValueCreated implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute value the event relates to."""
- attributeValue: AttributeValue
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
+
+ """The new email address."""
+ newEmail: String
}
"""
-Event sent when attribute value is updated.
+Event sent when setting a new password is requested.
-Added in Saleor 3.5.
+Added in Saleor 3.15.
"""
-type AttributeValueUpdated implements Event @doc(category: "Attributes") {
+type AccountSetPasswordRequested implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33010,16 +33182,28 @@ type AttributeValueUpdated implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute value the event relates to."""
- attributeValue: AttributeValue
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
}
"""
-Event sent when attribute value is deleted.
+Event sent when account is confirmed.
-Added in Saleor 3.5.
+Added in Saleor 3.15.
"""
-type AttributeValueDeleted implements Event @doc(category: "Attributes") {
+type AccountConfirmed implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33032,16 +33216,28 @@ type AttributeValueDeleted implements Event @doc(category: "Attributes") {
"""The application receiving the webhook."""
recipient: App
- """The attribute value the event relates to."""
- attributeValue: AttributeValue
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
}
"""
-Event sent when new category is created.
+Event sent when account delete is requested.
-Added in Saleor 3.2.
+Added in Saleor 3.15.
"""
-type CategoryCreated implements Event @doc(category: "Products") {
+type AccountDeleteRequested implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33054,16 +33250,28 @@ type CategoryCreated implements Event @doc(category: "Products") {
"""The application receiving the webhook."""
recipient: App
- """The category the event relates to."""
- category: Category
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
}
"""
-Event sent when category is updated.
+Event sent when account is deleted.
-Added in Saleor 3.2.
+Added in Saleor 3.15.
"""
-type CategoryUpdated implements Event @doc(category: "Products") {
+type AccountDeleted implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33076,16 +33284,28 @@ type CategoryUpdated implements Event @doc(category: "Products") {
"""The application receiving the webhook."""
recipient: App
- """The category the event relates to."""
- category: Category
+ """The URL to redirect the user after he accepts the request."""
+ redirectUrl: String
+
+ """The user the event relates to."""
+ user: User
+
+ """The channel data."""
+ channel: Channel
+
+ """The token required to confirm request."""
+ token: String
+
+ """Shop data."""
+ shop: Shop
}
"""
-Event sent when category is deleted.
+Event sent when new address is created.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type CategoryDeleted implements Event @doc(category: "Products") {
+type AddressCreated implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33098,16 +33318,16 @@ type CategoryDeleted implements Event @doc(category: "Products") {
"""The application receiving the webhook."""
recipient: App
- """The category the event relates to."""
- category: Category
+ """The address the event relates to."""
+ address: Address
}
"""
-Event sent when new channel is created.
+Event sent when address is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type ChannelCreated implements Event @doc(category: "Channels") {
+type AddressUpdated implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33120,16 +33340,16 @@ type ChannelCreated implements Event @doc(category: "Channels") {
"""The application receiving the webhook."""
recipient: App
- """The channel the event relates to."""
- channel: Channel
+ """The address the event relates to."""
+ address: Address
}
"""
-Event sent when channel is updated.
+Event sent when address is deleted.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type ChannelUpdated implements Event @doc(category: "Channels") {
+type AddressDeleted implements Event @doc(category: "Users") {
"""Time of the event."""
issuedAt: DateTime
@@ -33142,16 +33362,16 @@ type ChannelUpdated implements Event @doc(category: "Channels") {
"""The application receiving the webhook."""
recipient: App
- """The channel the event relates to."""
- channel: Channel
+ """The address the event relates to."""
+ address: Address
}
"""
-Event sent when channel is deleted.
+Event sent when new app is installed.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type ChannelDeleted implements Event @doc(category: "Channels") {
+type AppInstalled implements Event @doc(category: "Apps") {
"""Time of the event."""
issuedAt: DateTime
@@ -33164,16 +33384,16 @@ type ChannelDeleted implements Event @doc(category: "Channels") {
"""The application receiving the webhook."""
recipient: App
- """The channel the event relates to."""
- channel: Channel
+ """The application the event relates to."""
+ app: App
}
"""
-Event sent when channel status has changed.
+Event sent when app is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type ChannelStatusChanged implements Event @doc(category: "Channels") {
+type AppUpdated implements Event @doc(category: "Apps") {
"""Time of the event."""
issuedAt: DateTime
@@ -33186,16 +33406,16 @@ type ChannelStatusChanged implements Event @doc(category: "Channels") {
"""The application receiving the webhook."""
recipient: App
- """The channel the event relates to."""
- channel: Channel
+ """The application the event relates to."""
+ app: App
}
"""
-Event sent when channel metadata is updated.
+Event sent when app is deleted.
-Added in Saleor 3.15.
+Added in Saleor 3.4.
"""
-type ChannelMetadataUpdated implements Event @doc(category: "Channels") {
+type AppDeleted implements Event @doc(category: "Apps") {
"""Time of the event."""
issuedAt: DateTime
@@ -33208,16 +33428,16 @@ type ChannelMetadataUpdated implements Event @doc(category: "Channels") {
"""The application receiving the webhook."""
recipient: App
- """The channel the event relates to."""
- channel: Channel
+ """The application the event relates to."""
+ app: App
}
"""
-Event sent when new gift card is created.
+Event sent when app status has changed.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type GiftCardCreated implements Event @doc(category: "Gift cards") {
+type AppStatusChanged implements Event @doc(category: "Apps") {
"""Time of the event."""
issuedAt: DateTime
@@ -33230,16 +33450,16 @@ type GiftCardCreated implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
+ """The application the event relates to."""
+ app: App
}
"""
-Event sent when gift card is updated.
+Event sent when new attribute is created.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type GiftCardUpdated implements Event @doc(category: "Gift cards") {
+type AttributeCreated implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33252,16 +33472,16 @@ type GiftCardUpdated implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
+ """The attribute the event relates to."""
+ attribute: Attribute
}
"""
-Event sent when gift card is deleted.
+Event sent when attribute is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type GiftCardDeleted implements Event @doc(category: "Gift cards") {
+type AttributeUpdated implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33274,18 +33494,16 @@ type GiftCardDeleted implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
+ """The attribute the event relates to."""
+ attribute: Attribute
}
"""
-Event sent when gift card is e-mailed.
-
-Added in Saleor 3.13.
+Event sent when attribute is deleted.
-Note: this API is currently in Feature Preview and can be subject to changes at later point.
+Added in Saleor 3.5.
"""
-type GiftCardSent implements Event @doc(category: "Gift cards") {
+type AttributeDeleted implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33298,22 +33516,16 @@ type GiftCardSent implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
-
- """Slug of a channel for which this gift card email was sent."""
- channel: String
-
- """E-mail address to which gift card was sent."""
- sentToEmail: String
+ """The attribute the event relates to."""
+ attribute: Attribute
}
"""
-Event sent when gift card status has changed.
+Event sent when new attribute value is created.
-Added in Saleor 3.2.
+Added in Saleor 3.5.
"""
-type GiftCardStatusChanged implements Event @doc(category: "Gift cards") {
+type AttributeValueCreated implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33326,16 +33538,16 @@ type GiftCardStatusChanged implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
+ """The attribute value the event relates to."""
+ attributeValue: AttributeValue
}
"""
-Event sent when gift card metadata is updated.
+Event sent when attribute value is updated.
-Added in Saleor 3.8.
+Added in Saleor 3.5.
"""
-type GiftCardMetadataUpdated implements Event @doc(category: "Gift cards") {
+type AttributeValueUpdated implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33348,16 +33560,16 @@ type GiftCardMetadataUpdated implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The gift card the event relates to."""
- giftCard: GiftCard
+ """The attribute value the event relates to."""
+ attributeValue: AttributeValue
}
"""
-Event sent when gift card export is completed.
+Event sent when attribute value is deleted.
-Added in Saleor 3.16.
+Added in Saleor 3.5.
"""
-type GiftCardExportCompleted implements Event @doc(category: "Gift cards") {
+type AttributeValueDeleted implements Event @doc(category: "Attributes") {
"""Time of the event."""
issuedAt: DateTime
@@ -33370,16 +33582,16 @@ type GiftCardExportCompleted implements Event @doc(category: "Gift cards") {
"""The application receiving the webhook."""
recipient: App
- """The export file for gift cards."""
- export: ExportFile
+ """The attribute value the event relates to."""
+ attributeValue: AttributeValue
}
"""
-Event sent when new menu is created.
+Event sent when new category is created.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuCreated implements Event @doc(category: "Menu") {
+type CategoryCreated implements Event @doc(category: "Products") {
"""Time of the event."""
issuedAt: DateTime
@@ -33392,19 +33604,16 @@ type MenuCreated implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu the event relates to."""
- menu(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): Menu
+ """The category the event relates to."""
+ category: Category
}
"""
-Event sent when menu is updated.
+Event sent when category is updated.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuUpdated implements Event @doc(category: "Menu") {
+type CategoryUpdated implements Event @doc(category: "Products") {
"""Time of the event."""
issuedAt: DateTime
@@ -33417,19 +33626,16 @@ type MenuUpdated implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu the event relates to."""
- menu(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): Menu
+ """The category the event relates to."""
+ category: Category
}
"""
-Event sent when menu is deleted.
+Event sent when category is deleted.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuDeleted implements Event @doc(category: "Menu") {
+type CategoryDeleted implements Event @doc(category: "Products") {
"""Time of the event."""
issuedAt: DateTime
@@ -33442,19 +33648,16 @@ type MenuDeleted implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu the event relates to."""
- menu(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): Menu
+ """The category the event relates to."""
+ category: Category
}
"""
-Event sent when new menu item is created.
+Event sent when new channel is created.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuItemCreated implements Event @doc(category: "Menu") {
+type ChannelCreated implements Event @doc(category: "Channels") {
"""Time of the event."""
issuedAt: DateTime
@@ -33467,19 +33670,16 @@ type MenuItemCreated implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu item the event relates to."""
- menuItem(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): MenuItem
+ """The channel the event relates to."""
+ channel: Channel
}
"""
-Event sent when menu item is updated.
+Event sent when channel is updated.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuItemUpdated implements Event @doc(category: "Menu") {
+type ChannelUpdated implements Event @doc(category: "Channels") {
"""Time of the event."""
issuedAt: DateTime
@@ -33492,19 +33692,16 @@ type MenuItemUpdated implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu item the event relates to."""
- menuItem(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): MenuItem
+ """The channel the event relates to."""
+ channel: Channel
}
"""
-Event sent when menu item is deleted.
+Event sent when channel is deleted.
-Added in Saleor 3.4.
+Added in Saleor 3.2.
"""
-type MenuItemDeleted implements Event @doc(category: "Menu") {
+type ChannelDeleted implements Event @doc(category: "Channels") {
"""Time of the event."""
issuedAt: DateTime
@@ -33517,19 +33714,16 @@ type MenuItemDeleted implements Event @doc(category: "Menu") {
"""The application receiving the webhook."""
recipient: App
- """The menu item the event relates to."""
- menuItem(
- """Slug of a channel for which the data should be returned."""
- channel: String
- ): MenuItem
+ """The channel the event relates to."""
+ channel: Channel
}
"""
-Event sent when new order is created.
+Event sent when channel status has changed.
Added in Saleor 3.2.
"""
-type OrderCreated implements Event @doc(category: "Orders") {
+type ChannelStatusChanged implements Event @doc(category: "Channels") {
"""Time of the event."""
issuedAt: DateTime
@@ -33542,16 +33736,16 @@ type OrderCreated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The channel the event relates to."""
+ channel: Channel
}
"""
-Event sent when order is updated.
+Event sent when channel metadata is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.15.
"""
-type OrderUpdated implements Event @doc(category: "Orders") {
+type ChannelMetadataUpdated implements Event @doc(category: "Channels") {
"""Time of the event."""
issuedAt: DateTime
@@ -33564,16 +33758,16 @@ type OrderUpdated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The channel the event relates to."""
+ channel: Channel
}
"""
-Event sent when order is confirmed.
+Event sent when new gift card is created.
Added in Saleor 3.2.
"""
-type OrderConfirmed implements Event @doc(category: "Orders") {
+type GiftCardCreated implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33586,16 +33780,16 @@ type OrderConfirmed implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
}
"""
-Event sent when order is fully paid.
+Event sent when gift card is updated.
Added in Saleor 3.2.
"""
-type OrderFullyPaid implements Event @doc(category: "Orders") {
+type GiftCardUpdated implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33608,18 +33802,16 @@ type OrderFullyPaid implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
}
"""
-Payment has been made. The order may be partially or fully paid.
-
-Added in Saleor 3.14.
+Event sent when gift card is deleted.
-Note: this API is currently in Feature Preview and can be subject to changes at later point.
+Added in Saleor 3.2.
"""
-type OrderPaid implements Event @doc(category: "Orders") {
+type GiftCardDeleted implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33632,18 +33824,18 @@ type OrderPaid implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
}
"""
-The order received a refund. The order may be partially or fully refunded.
+Event sent when gift card is e-mailed.
-Added in Saleor 3.14.
+Added in Saleor 3.13.
Note: this API is currently in Feature Preview and can be subject to changes at later point.
"""
-type OrderRefunded implements Event @doc(category: "Orders") {
+type GiftCardSent implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33656,18 +33848,22 @@ type OrderRefunded implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
+
+ """Slug of a channel for which this gift card email was sent."""
+ channel: String
+
+ """E-mail address to which gift card was sent."""
+ sentToEmail: String
}
"""
-The order is fully refunded.
-
-Added in Saleor 3.14.
+Event sent when gift card status has changed.
-Note: this API is currently in Feature Preview and can be subject to changes at later point.
+Added in Saleor 3.2.
"""
-type OrderFullyRefunded implements Event @doc(category: "Orders") {
+type GiftCardStatusChanged implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33680,16 +33876,16 @@ type OrderFullyRefunded implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
}
"""
-Event sent when order is fulfilled.
+Event sent when gift card metadata is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.8.
"""
-type OrderFulfilled implements Event @doc(category: "Orders") {
+type GiftCardMetadataUpdated implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33702,16 +33898,16 @@ type OrderFulfilled implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The gift card the event relates to."""
+ giftCard: GiftCard
}
"""
-Event sent when order is canceled.
+Event sent when gift card export is completed.
-Added in Saleor 3.2.
+Added in Saleor 3.16.
"""
-type OrderCancelled implements Event @doc(category: "Orders") {
+type GiftCardExportCompleted implements Event @doc(category: "Gift cards") {
"""Time of the event."""
issuedAt: DateTime
@@ -33724,18 +33920,16 @@ type OrderCancelled implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The export file for gift cards."""
+ export: ExportFile
}
"""
-Event sent when order becomes expired.
-
-Added in Saleor 3.13.
+Event sent when new menu is created.
-Note: this API is currently in Feature Preview and can be subject to changes at later point.
+Added in Saleor 3.4.
"""
-type OrderExpired implements Event @doc(category: "Orders") {
+type MenuCreated implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33748,16 +33942,19 @@ type OrderExpired implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The menu the event relates to."""
+ menu(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): Menu
}
"""
-Event sent when order metadata is updated.
+Event sent when menu is updated.
-Added in Saleor 3.8.
+Added in Saleor 3.4.
"""
-type OrderMetadataUpdated implements Event @doc(category: "Orders") {
+type MenuUpdated implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33770,18 +33967,19 @@ type OrderMetadataUpdated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The menu the event relates to."""
+ menu(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): Menu
}
"""
-Event sent when orders are imported.
-
-Added in Saleor 3.14.
+Event sent when menu is deleted.
-Note: this API is currently in Feature Preview and can be subject to changes at later point.
+Added in Saleor 3.4.
"""
-type OrderBulkCreated implements Event @doc(category: "Orders") {
+type MenuDeleted implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33794,16 +33992,19 @@ type OrderBulkCreated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The orders the event relates to."""
- orders: [Order!]
+ """The menu the event relates to."""
+ menu(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): Menu
}
"""
-Event sent when new draft order is created.
+Event sent when new menu item is created.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type DraftOrderCreated implements Event @doc(category: "Orders") {
+type MenuItemCreated implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33816,16 +34017,19 @@ type DraftOrderCreated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The menu item the event relates to."""
+ menuItem(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): MenuItem
}
"""
-Event sent when draft order is updated.
+Event sent when menu item is updated.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type DraftOrderUpdated implements Event @doc(category: "Orders") {
+type MenuItemUpdated implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33838,16 +34042,19 @@ type DraftOrderUpdated implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The menu item the event relates to."""
+ menuItem(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): MenuItem
}
"""
-Event sent when draft order is deleted.
+Event sent when menu item is deleted.
-Added in Saleor 3.2.
+Added in Saleor 3.4.
"""
-type DraftOrderDeleted implements Event @doc(category: "Orders") {
+type MenuItemDeleted implements Event @doc(category: "Menu") {
"""Time of the event."""
issuedAt: DateTime
@@ -33860,8 +34067,11 @@ type DraftOrderDeleted implements Event @doc(category: "Orders") {
"""The application receiving the webhook."""
recipient: App
- """The order the event relates to."""
- order: Order
+ """The menu item the event relates to."""
+ menuItem(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): MenuItem
}
"""
diff --git a/saleor/graphql/webhook/mutations/webhook_create.py b/saleor/graphql/webhook/mutations/webhook_create.py
index 472e20d339..9f03fc88cf 100644
--- a/saleor/graphql/webhook/mutations/webhook_create.py
+++ b/saleor/graphql/webhook/mutations/webhook_create.py
@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError
from ....permission.auth_filters import AuthorizationFilters
from ....permission.enums import AppPermission
from ....webhook import models
+from ....webhook.const import MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT
from ....webhook.error_codes import WebhookErrorCode
from ....webhook.validators import (
HEADERS_LENGTH_LIMIT,
@@ -136,6 +137,17 @@ class WebhookCreate(ModelMutation, NotifyUserEventValidationMixin):
code=subscription_query.error_code,
)
instance.subscription_query = query
+ filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ if len(filterable_channel_slugs) > MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT:
+ raise_validation_error(
+ field="query",
+ message=(
+ "Too many channels provided in the filter, the maximum number "
+ f"is {MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT}"
+ ),
+ code=WebhookErrorCode.INVALID,
+ )
+ cleaned_data["filterable_channel_slugs"] = filterable_channel_slugs
if headers := cleaned_data.get("custom_headers"):
try:
diff --git a/saleor/graphql/webhook/subscription_payload.py b/saleor/graphql/webhook/subscription_payload.py
index aa863970e0..a492fb3153 100644
--- a/saleor/graphql/webhook/subscription_payload.py
+++ b/saleor/graphql/webhook/subscription_payload.py
@@ -207,7 +207,14 @@ def generate_payload_from_subscription(
return None
payload_instance = payload[0]
- event_payload = get_event_payload(payload_instance.data.get("event")) or {}
+ payload_data_keys = payload_instance.data.keys()
+ for key in payload_data_keys:
+ extracted_payload = get_event_payload(payload_instance.data.get(key))
+ payload_instance.data[key] = extracted_payload
+ if "event" in payload_instance.data or not payload_instance.data:
+ event_payload = payload_instance.data.get("event") or {}
+ else:
+ event_payload = {"data": payload_instance.data}
if payload_instance.errors:
event_payload["errors"] = [
diff --git a/saleor/graphql/webhook/subscription_query.py b/saleor/graphql/webhook/subscription_query.py
index 139ae3bba5..e99008dab6 100644
--- a/saleor/graphql/webhook/subscription_query.py
+++ b/saleor/graphql/webhook/subscription_query.py
@@ -1,5 +1,5 @@
from enum import Flag
-from typing import Optional, Union
+from typing import Optional, Union, cast
from django.core.exceptions import ValidationError
from graphene.utils.str_converters import to_snake_case
@@ -32,6 +32,52 @@ class SubscriptionQuery:
self.errors = self.validate_query()
self.error_msg: str = ";".join(set([str(err.message) for err in self.errors]))
+ def get_filterable_channel_slugs(self) -> list[str]:
+ """Get filterable channel slugs from the subscription.
+
+ Subscription is filterable if it has arguments provided that can be used to
+ filter out records. If arguments are not provided, the subscription is not
+ filterable, then needs to be treated as normal subscription.
+ """
+ if not self.is_valid:
+ return []
+ subscription = self._get_subscription(self.ast)
+ # subscription is not optional as validation from init already passed
+ subscription = cast(OperationDefinition, subscription)
+
+ field_names = [
+ selection.name.value for selection in subscription.selection_set.selections
+ ]
+ # Skip if there is non-filterable subscription
+ if len(field_names) > 1 or set(field_names) == {"event"}:
+ return []
+
+ selection = subscription.selection_set.selections[0]
+ if not selection.arguments:
+ return []
+ channels = []
+ for arg in selection.arguments:
+ argument_name = arg.name.value
+ argument_values = getattr(arg.value, "values", [])
+ if argument_name == "channels":
+ channels = [value.value for value in argument_values]
+ break
+ return channels
+
+ def _check_if_invalid_top_field_selection(self, subscription: OperationDefinition):
+ """Check if subscription selects only one top field.
+
+ Filterable subscription can select only one top field. If more than one field
+ is selected, the subscription is invalid.
+ """
+ is_invalid = False
+ field_names = [
+ selection.name.value for selection in subscription.selection_set.selections
+ ]
+ if len(field_names) > 1 and set(field_names) != {"event"}:
+ is_invalid = True
+ return is_invalid
+
def validate_query(self) -> list[Union[GraphQLSyntaxError, ValidationError]]:
from ..api import schema
@@ -48,8 +94,27 @@ class SubscriptionQuery:
self.error_code = WebhookErrorCode.GRAPHQL_ERROR.value
return errors
+ subscription = self._get_subscription(self.ast)
+ if not subscription:
+ self.error_code = WebhookErrorCode.MISSING_SUBSCRIPTION.value
+ return [
+ ValidationError(
+ message="Subscription operation can't be found.",
+ code=WebhookErrorCode.MISSING_SUBSCRIPTION.value,
+ )
+ ]
+
+ if self._check_if_invalid_top_field_selection(subscription):
+ self.error_code = WebhookErrorCode.INVALID.value
+ return [
+ ValidationError(
+ message="Subscription must select only one top field.",
+ code=WebhookErrorCode.INVALID.value,
+ )
+ ]
+
try:
- self.events = self.get_events_from_subscription()
+ self.events = self.get_events_from_subscription(subscription)
except ValidationError as err:
self.error_code = err.code
return [err]
@@ -57,13 +122,13 @@ class SubscriptionQuery:
self.is_valid = True
return []
- def get_events_from_subscription(self) -> list[str]:
- subscription = self._get_subscription(self.ast)
- if not subscription:
- raise ValidationError(
- message="Subscription operation can't be found.",
- code=WebhookErrorCode.MISSING_SUBSCRIPTION.value,
- )
+ def get_events_from_subscription(self, subscription) -> list[str]:
+ subscription_name = subscription.selection_set.selections[0].name.value
+ if subscription_name != "event":
+ return [
+ to_snake_case(selection.name.value)
+ for selection in subscription.selection_set.selections
+ ]
event_types = self._get_event_types_from_subscription(subscription)
if not event_types:
diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.py
index 4d90834acb..53d7f1d62d 100644
--- a/saleor/graphql/webhook/subscription_types.py
+++ b/saleor/graphql/webhook/subscription_types.py
@@ -1,4 +1,5 @@
import graphene
+from django.conf import settings
from graphene import AbstractType, Union
from rx import Observable
@@ -33,6 +34,7 @@ from ...product.models import (
)
from ...shipping.models import ShippingMethodTranslation
from ...thumbnail.views import TYPE_TO_MODEL_DATA_MAPPING
+from ...webhook.const import MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT
from ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ..account.types import User as UserType
from ..app.types import App as AppType
@@ -58,6 +60,7 @@ from ..core.descriptions import (
ADDED_IN_317,
ADDED_IN_318,
ADDED_IN_319,
+ ADDED_IN_320,
DEPRECATED_IN_3X_EVENT,
PREVIEW_FEATURE,
)
@@ -2700,11 +2703,150 @@ class WarehouseMetadataUpdated(SubscriptionObjectType, WarehouseBase):
description = "Event sent when warehouse metadata is updated." + ADDED_IN_38
+def default_order_resolver(root, info, channels=None):
+ return Observable.from_([root])
+
+
+channels_argument = graphene.Argument(
+ NonNullList(graphene.String),
+ description=(
+ "List of channel slugs. The event will be sent only if the order "
+ "belongs to one of the provided channels. If the channel slug list is "
+ "empty, orders that belong to any channel will be sent. Maximally "
+ f"{MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT} items."
+ ),
+)
+
+
class Subscription(SubscriptionObjectType):
event = graphene.Field(
Event,
description="Look up subscription event." + ADDED_IN_32,
)
+ draft_order_created = graphene.Field(
+ DraftOrderCreated,
+ description=(
+ "Event sent when new draft order is created."
+ + ADDED_IN_320
+ + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ draft_order_updated = graphene.Field(
+ DraftOrderUpdated,
+ description=(
+ "Event sent when draft order is updated." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ draft_order_deleted = graphene.Field(
+ DraftOrderDeleted,
+ description=(
+ "Event sent when draft order is deleted." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_created = graphene.Field(
+ OrderCreated,
+ description=(
+ "Event sent when new order is created." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_updated = graphene.Field(
+ OrderUpdated,
+ description=(
+ "Event sent when order is updated." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_confirmed = graphene.Field(
+ OrderConfirmed,
+ description=(
+ "Event sent when order is confirmed." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_paid = graphene.Field(
+ OrderPaid,
+ description=(
+ "Payment has been made. The order may be partially or fully paid."
+ + ADDED_IN_320
+ + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_fully_paid = graphene.Field(
+ OrderFullyPaid,
+ description=(
+ "Event sent when order is fully paid." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_refunded = graphene.Field(
+ OrderRefunded,
+ description=(
+ "The order received a refund. The order may be partially or fully "
+ "refunded." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_fully_refunded = graphene.Field(
+ OrderFullyRefunded,
+ description=("The order is fully refunded." + ADDED_IN_320 + PREVIEW_FEATURE),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_fulfilled = graphene.Field(
+ OrderFulfilled,
+ description=(
+ "Event sent when order is fulfilled." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_cancelled = graphene.Field(
+ OrderCancelled,
+ description=(
+ "Event sent when order is cancelled." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_expired = graphene.Field(
+ OrderExpired,
+ description=(
+ "Event sent when order becomes expired." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_metadata_updated = graphene.Field(
+ OrderMetadataUpdated,
+ description=(
+ "Event sent when order metadata is updated."
+ + ADDED_IN_320
+ + PREVIEW_FEATURE
+ ),
+ resolver=default_order_resolver,
+ channels=channels_argument,
+ )
+ order_bulk_created = graphene.Field(
+ OrderBulkCreated,
+ description=(
+ "Event sent when orders are imported." + ADDED_IN_320 + PREVIEW_FEATURE
+ ),
+ channels=channels_argument,
+ )
class Meta:
doc_category = DOC_CATEGORY_MISC
@@ -2713,6 +2855,26 @@ class Subscription(SubscriptionObjectType):
def resolve_event(root, info: ResolveInfo):
return Observable.from_([root])
+ @staticmethod
+ def resolve_order_bulk_created(root, info: ResolveInfo, channels=None):
+ event_type, orders = root
+ if event_type != WebhookEventAsyncType.ORDER_BULK_CREATED:
+ return Observable.from_([])
+
+ orders_to_return = []
+ if channels:
+ channel_ids = (
+ Channel.objects.using(settings.DATABASE_CONNECTION_REPLICA_NAME)
+ .filter(slug__in=channels)
+ .values_list("id", flat=True)
+ )
+ for order in orders:
+ if order.channel_id in channel_ids:
+ orders_to_return.append(order)
+ root = (event_type, orders_to_return)
+ return Observable.from_([root])
+ return Observable.from_([root])
+
class ThumbnailCreated(SubscriptionObjectType):
id = graphene.ID(description="Thumbnail id." + ADDED_IN_312)
diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_create.py b/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
index 5715fc053c..96e001a3fb 100644
--- a/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
@@ -1,6 +1,8 @@
import json
+from unittest.mock import patch
import graphene
+import pytest
from .....app.error_codes import AppErrorCode
from .....webhook.error_codes import WebhookErrorCode
@@ -57,6 +59,7 @@ def test_webhook_create_by_app(app_api_client, permission_manage_orders):
# then
new_webhook = Webhook.objects.get()
+ assert new_webhook.filterable_channel_slugs == []
assert new_webhook.name == "New integration"
assert new_webhook.target_url == "https://www.example.com"
assert new_webhook.custom_headers == {
@@ -149,6 +152,7 @@ def test_webhook_create_by_staff(
# then
new_webhook = Webhook.objects.get()
+ assert new_webhook.filterable_channel_slugs == []
assert new_webhook.target_url == "https://www.example.com"
assert new_webhook.app == app
events = new_webhook.events.all()
@@ -306,6 +310,7 @@ def test_webhook_create_inherit_events_from_query(
new_webhook = Webhook.objects.get()
assert new_webhook.target_url == "https://www.example.com"
assert new_webhook.app == app
+ assert new_webhook.filterable_channel_slugs == []
events = new_webhook.events.all()
assert len(events) == 2
@@ -378,3 +383,92 @@ def test_webhook_create_notify_user_with_another_event(app_api_client):
error = data["errors"][0]
assert error["field"] == "asyncEvents"
assert error["code"] == WebhookErrorCode.INVALID_NOTIFY_WITH_SUBSCRIPTION.name
+
+
+FILTERABLE_SUBSCRIPTION = """
+subscription {
+ orderCreated(channels: [%s]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+ "channel_slugs",
+ [
+ ["channel-1", "channel-2"],
+ ["channel-1"],
+ [],
+ ],
+)
+def test_webhook_create_assigns_filterable_channel_slugs(channel_slugs, app_api_client):
+ # given
+ query = WEBHOOK_CREATE
+ variables = {
+ "input": {
+ "name": "Webhook for default-channel",
+ "targetUrl": "https://www.example.com",
+ "query": FILTERABLE_SUBSCRIPTION
+ % ",".join([f'"{slug}"' for slug in channel_slugs]),
+ }
+ }
+
+ # when
+ response = app_api_client.post_graphql(query, variables=variables)
+ get_graphql_content(response)
+
+ # then
+ new_webhook = Webhook.objects.get()
+ assert new_webhook.filterable_channel_slugs == channel_slugs
+ assert new_webhook.target_url == "https://www.example.com"
+ assert new_webhook.app == app_api_client.app
+ events = new_webhook.events.all()
+ assert len(events) == 1
+ assert events[0].event_type == WebhookEventTypeAsyncEnum.ORDER_CREATED.value
+
+
+ "channel_slugs",
+ [
+ ["channel-1", "channel-2"],
+ ["channel-1", "channel-2", "channel-3"],
+ ],
+)
+@patch(
+ "saleor.graphql.webhook.mutations.webhook_create.MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT"
+)
+def test_webhook_create_assigns_filterable_channel_slugs_above_max_limit(
+ mocked_limit, channel_slugs, app_api_client
+):
+ # given
+ mocked_limit.__lt__ = lambda self, compare: True
+
+ query = WEBHOOK_CREATE
+ variables = {
+ "input": {
+ "name": "Webhook for default-channel",
+ "targetUrl": "https://www.example.com",
+ "query": FILTERABLE_SUBSCRIPTION
+ % ",".join([f'"{slug}"' for slug in channel_slugs]),
+ }
+ }
+
+ # when
+ response = app_api_client.post_graphql(query, variables=variables)
+ content = get_graphql_content(response)
+
+ # then
+ assert len(content["data"]["webhookCreate"]["errors"]) == 1
+ error = content["data"]["webhookCreate"]["errors"][0]
+ assert error["field"] == "query"
+ assert error["code"] == WebhookErrorCode.INVALID.name
diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_update.py b/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
index c676d8f6e5..85fe987e36 100644
--- a/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
@@ -1,6 +1,8 @@
import json
+from unittest.mock import patch
import graphene
+import pytest
from .....app.models import App
from ....core.enums import WebhookErrorCode
@@ -49,6 +51,7 @@ def test_webhook_update_by_app(app_api_client, app, webhook):
# then
assert webhook.is_active is False
+ assert webhook.filterable_channel_slugs == []
events = webhook.events.all()
assert len(events) == 1
assert events[0].event_type == WebhookEventTypeAsyncEnum.ORDER_CREATED.value
@@ -172,6 +175,7 @@ def test_webhook_update_by_staff(staff_api_client, webhook, permission_manage_ap
# then
assert webhook.is_active is False
+ assert webhook.filterable_channel_slugs == []
assert webhook.custom_headers == {"x-key": "Value", "authorization-key": "Value"}
events = webhook.events.all()
assert len(events) == 1
@@ -332,3 +336,97 @@ def test_webhook_update_notify_user_with_another_event(app_api_client, webhook):
error = data["errors"][0]
assert error["field"] == "asyncEvents"
assert error["code"] == WebhookErrorCode.INVALID_NOTIFY_WITH_SUBSCRIPTION.name
+
+
+FILTERABLE_SUBSCRIPTION = """
+subscription {
+ orderCreated(channels: [%s]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+ ("channel_slugs", "previous_slugs"),
+ [
+ (["channel-1", "channel-2"], ["previous-channel"]),
+ (["channel-1"], ["previous-channel"]),
+ (["channel-1"], ["channel-1"]),
+ (["channel-1", "channel-2"], []),
+ ([], ["previous-channel"]),
+ ],
+)
+def test_webhook_update_filterable_channel_slugs(
+ channel_slugs, previous_slugs, app_api_client, app, webhook
+):
+ # given
+ webhook_id = graphene.Node.to_global_id("Webhook", webhook.pk)
+ webhook.filterable_channel_slugs = previous_slugs
+ webhook.save()
+ variables = {
+ "id": webhook_id,
+ "input": {
+ "query": FILTERABLE_SUBSCRIPTION
+ % ",".join([f'"{slug}"' for slug in channel_slugs])
+ },
+ }
+
+ # when
+ response = app_api_client.post_graphql(WEBHOOK_UPDATE, variables=variables)
+ get_graphql_content(response)
+ webhook.refresh_from_db()
+
+ # then
+ assert webhook.filterable_channel_slugs == channel_slugs
+ events = webhook.events.all()
+ assert len(events) == 1
+ assert events[0].event_type == WebhookEventTypeAsyncEnum.ORDER_CREATED.value
+
+
+ "channel_slugs",
+ [
+ ["channel-1", "channel-2"],
+ ["channel-1", "channel-2", "channel-3"],
+ ],
+)
+@patch(
+ "saleor.graphql.webhook.mutations.webhook_create.MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT"
+)
+def test_webhook_create_assigns_filterable_channel_slugs_above_max_limit(
+ mocked_limit, channel_slugs, app_api_client, webhook
+):
+ # given
+ mocked_limit.__lt__ = lambda self, compare: True
+
+ webhook_id = graphene.Node.to_global_id("Webhook", webhook.pk)
+ webhook.filterable_channel_slugs = ["previous-channel"]
+ webhook.save()
+
+ variables = {
+ "id": webhook_id,
+ "input": {
+ "query": FILTERABLE_SUBSCRIPTION
+ % ",".join([f'"{slug}"' for slug in channel_slugs])
+ },
+ }
+
+ # when
+ response = app_api_client.post_graphql(WEBHOOK_UPDATE, variables=variables)
+ content = get_graphql_content(response)
+
+ # then
+ assert len(content["data"]["webhookUpdate"]["errors"]) == 1
+ error = content["data"]["webhookUpdate"]["errors"][0]
+ assert error["field"] == "query"
+ assert error["code"] == WebhookErrorCode.INVALID.name
diff --git a/saleor/graphql/webhook/tests/test_subscription_query.py b/saleor/graphql/webhook/tests/test_subscription_query.py
index d70e43f3b3..3fac661392 100644
--- a/saleor/graphql/webhook/tests/test_subscription_query.py
+++ b/saleor/graphql/webhook/tests/test_subscription_query.py
@@ -50,271 +50,530 @@ def test_subscription_query():
]
+SUBSCRIPTION_ORDER_CREATED = """
+subscription {
+ event {
+ ...on OrderCreated {
+ order {
+ id
+ }
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_ORDER_CREATED_WITH_FRAGMENT = """
+fragment OrderFragment on Order {
+ id
+ number
+ lines {
+ id
+ }
+}
+subscription {
+ event {
+ ...on OrderCreated {
+ order {
+ ...OrderFragment
+ }
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_ORDER_UPDATED_WITH_FRAGMENT = """
+fragment OrderFragment on Order {
+ id
+}
+
+fragment EventFragment on Event {
+ issuedAt
+ ... on OrderUpdated {
+ order {
+ ... OrderFragment
+ }
+ }
+}
+
+subscription {
+ event {
+ ... EventFragment
+ }
+}
+"""
+
+SUBSCRIPTION_MULTIPLE_EVENTS = """
+subscription {
+ event{
+ ... on OrderCreated{
+ order{
+ id
+ }
+ }
+ ... on OrderFullyPaid{
+ order{
+ id
+ }
+ }
+ ... on ProductCreated{
+ product{
+ id
+ }
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_MULTIPLE_EVENTS_WITH_FRAGMENT = """
+fragment MyFragment on Event {
+ ... on OrderCreated{
+ order{
+ id
+ }
+ }
+ ... on OrderUpdated{
+ order{
+ id
+ }
+ }
+ ... on ProductCreated{
+ product{
+ id
+ }
+ }
+}
+subscription {
+ event {
+ ... MyFragment
+ }
+}
+"""
+
+SUBSCRIPTION_MULTIPLE_EVENTS_WITH_PARTIALLY_FRAGMENT = """
+fragment EventFragment on Event {
+ ... on OrderUpdated {
+ order {
+ id
+ }
+ }
+ ... on OrderCreated {
+ order {
+ id
+ }
+ }
+}
+
+subscription {
+ event {
+ ... EventFragment
+ ... on ProductCreated {
+ product {
+ id
+ }
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_INVOICE_REQUESTED_WITH_FRAGMENT = """
+subscription InvoiceRequested {
+ event {
+ ...InvoiceRequestedPayload
+ }
+ }
+ fragment InvoiceRequestedPayload on InvoiceRequested {
+ invoice {
+ id
+ }
+ }
+"""
+
+SUBSCRIPTION_WITH_MULTIPLE_EVENT_FIELD = """
+subscription{
+ event{
+ ...on ProductUpdated{
+ product{
+ id
+ }
+ }
+ }
+ event{
+ ...on ProductCreated{
+ product{
+ id
+ }
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_FILTERABLE_ORDER_CREATED = """
+subscription{
+ orderCreated(channels:["default"]){
+ order{
+ id
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_FILTERABLE_ORDER_CREATED_WITH_FRAGMENT = """
+fragment OrderFragment on Order {
+ id
+ number
+ lines {
+ id
+ }
+}
+subscription {
+ orderCreated{
+ order{
+ ...OrderFragment
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_FILTERABLE_WITHOUT_ARGUMENTS = """
+fragment OrderFragment on Order {
+ id
+ number
+ lines {
+ id
+ }
+}
+subscription {
+ updated: orderUpdated{
+ order{
+ ...OrderFragment
+ }
+ }
+}
+"""
+
+
@pytest.mark.parametrize(
("query", "events"),
[
(
- """
- subscription {
- event {
- ...on OrderCreated {
- order {
- id
- }
- }
- }
- }
- """,
+ SUBSCRIPTION_ORDER_CREATED,
["order_created"],
),
(
- """
- fragment OrderFragment on Order {
- id
- number
- lines {
- id
- }
- }
- subscription {
- event {
- ...on OrderCreated {
- order {
- ...OrderFragment
- }
- }
- }
- }
- """,
+ SUBSCRIPTION_ORDER_CREATED_WITH_FRAGMENT,
["order_created"],
),
(
- """
- fragment OrderFragment on Order {
- id
- }
-
- fragment EventFragment on Event {
- issuedAt
- ... on OrderUpdated {
- order {
- ... OrderFragment
- }
- }
- }
-
- subscription {
- event {
- ... EventFragment
- }
- }
- """,
+ SUBSCRIPTION_ORDER_UPDATED_WITH_FRAGMENT,
["order_updated"],
),
(
- """
- subscription {
- event{
- ... on OrderCreated{
- order{
- id
- }
- }
- ... on OrderFullyPaid{
- order{
- id
- }
- }
- ... on ProductCreated{
- product{
- id
- }
- }
- }
- }
- """,
+ SUBSCRIPTION_MULTIPLE_EVENTS,
["order_created", "order_fully_paid", "product_created"],
),
(
- """
- fragment MyFragment on Event {
- ... on OrderCreated{
- order{
- id
- }
- }
- ... on OrderUpdated{
- order{
+ SUBSCRIPTION_MULTIPLE_EVENTS_WITH_FRAGMENT,
+ ["order_created", "order_updated", "product_created"],
+ ),
+ (
+ SUBSCRIPTION_MULTIPLE_EVENTS_WITH_PARTIALLY_FRAGMENT,
+ ["order_updated", "order_created", "product_created"],
+ ),
+ (
+ SUBSCRIPTION_INVOICE_REQUESTED_WITH_FRAGMENT,
+ ["invoice_requested"],
+ ),
+ (
+ SUBSCRIPTION_WITH_MULTIPLE_EVENT_FIELD,
+ ["product_updated", "product_created"],
+ ),
+ (
+ SUBSCRIPTION_FILTERABLE_ORDER_CREATED,
+ ["order_created"],
+ ),
+ (
+ SUBSCRIPTION_FILTERABLE_ORDER_CREATED_WITH_FRAGMENT,
+ ["order_created"],
+ ),
+ (
+ SUBSCRIPTION_FILTERABLE_WITHOUT_ARGUMENTS,
+ ["order_updated"],
+ ),
+ ],
+)
+def test_get_event_type_from_subscription(query, events):
+ subscription_query = SubscriptionQuery(query)
+ assert subscription_query.is_valid
+ assert subscription_query.events == sorted(events)
+
+
+SUBSCRIPTION_MUTATION_AS_INPUT = """
+mutation SomeMutation {
+ someMutation(input: {}) {
+ result {
+ id
+ }
+ }
+}
+"""
+SUBSCRIPTION_UNKNOWN_FRAGMENT = """
+subscription {
+ event {
+ ... MyFragment
+ }
+}
+"""
+
+SUBSCRIPTION_NOT_USED_FRAGMENT = """
+fragment NotUsedEvents on Order {
+ id
+}
+subscription {
+ event {
+ ... on OrderUpdated {
+ order {
+ id
+ }
+ }
+ }
+}
+"""
+SUBSCRIPTION_SYNTAX_ERROR = """
+query {{
+}
+"""
+
+SUBSCRIPTION_QUERY_USED = """
+query {
+ channels {
+ name
+ }
+}
+"""
+SUBSCRIPTION_MISSING_EVENT = """
+subscription {
+ event {
+ issuedAt
+ }
+}
+"""
+SUBSCRIPTION_FILTERABLE_ORDER_CREATED_AND_EVENT_MANY_TOP_FIELDS = """
+subscription {
+ event{
+ ...on OrderCreated{
+ order{
+ id
+ }
+ }
+ }
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
- }
+ product{
+ id
+ }
}
- ... on ProductCreated{
- product{
+ }
+ }
+ }
+}
+"""
+SUBSCRIPTION_MANY_TOP_FILTERABLE_FIELDS = """
+subscription {
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
- }
+ product{
+ id
+ }
}
}
- subscription {
- event {
- ... MyFragment
+ }
+ }
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
+ id
+ product{
+ id
+ }
}
}
- """,
- ["order_created", "order_updated", "product_created"],
- ),
- (
- """
- fragment EventFragment on Event {
- ... on OrderUpdated {
- order {
+ }
+ }
+}
+"""
+
+SUBSCRIPTION_MANY_TOP_FILTERABLE_FIELDS_WITH_ALIAS = """
+subscription {
+ alias: orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
+ product{
+ id
+ }
}
- }
- ... on OrderCreated {
- order {
+ }
+ }
+ }
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
+ product{
+ id
+ }
}
- }
}
+ }
+ }
+}
+"""
- subscription {
- event {
- ... EventFragment
- ... on ProductCreated {
- product {
+SUBSCRIPTION_MANY_TOP_FILTERABLE_DIFFERENT_FIELDS = """
+subscription {
+ orderUpdated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
+ id
+ product{
id
}
}
- }
}
- """,
- ["order_updated", "order_created", "product_created"],
- ),
- (
- """
- subscription InvoiceRequested {
- event {
- ...InvoiceRequestedPayload
- }
- }
- fragment InvoiceRequestedPayload on InvoiceRequested {
- invoice {
- id
+ }
+ }
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
+ id
+ product{
+ id
+ }
}
- }
- """,
- ["invoice_requested"],
- ),
- (
- """
- subscription{
- event{
- ...on ProductUpdated{
- product{
+ }
+ }
+ }
+}
+"""
+SUBSCRIPTION_MANY_TOP_FILTERABLE_DIFFERENT_FIELDS_WITH_ALIAS = """
+subscription {
+ alias: orderUpdated(channels:["different-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
- }
+ product{
+ id
+ }
}
- }
- event{
- ...on ProductCreated{
- product{
+ }
+ }
+ }
+ orderCreated(channels:["default-channel"]){
+ order{
+ lines{
+ id
+ variant{
id
- }
+ product{
+ id
+ }
}
- }
}
- """,
- ["product_updated", "product_created"],
- ),
- ],
-)
-def test_get_event_type_from_subscription(query, events):
- subscription_query = SubscriptionQuery(query)
- assert subscription_query.is_valid
- assert subscription_query.events == sorted(events)
+ }
+ }
+}
+"""
@pytest.mark.parametrize(
("query", "error_msg", "error_type", "error_code"),
[
(
- """
- mutation SomeMutation {
- someMutation(input: {}) {
- result {
- id
- }
- }
- }
- """,
+ SUBSCRIPTION_MUTATION_AS_INPUT,
'Cannot query field "someMutation" on type "Mutation".',
GraphQLError,
WebhookErrorCode.GRAPHQL_ERROR,
),
(
- """
- subscription {
- event {
- ... MyFragment
- }
- }
- """,
+ SUBSCRIPTION_UNKNOWN_FRAGMENT,
'Unknown fragment "MyFragment".',
GraphQLError,
WebhookErrorCode.GRAPHQL_ERROR,
),
(
- """
- fragment NotUsedEvents on Order {
- id
- }
- subscription {
- event {
- ... on OrderUpdated {
- order {
- id
- }
- }
- }
- }
- """,
+ SUBSCRIPTION_NOT_USED_FRAGMENT,
'Fragment "NotUsedEvents" is never used.',
GraphQLError,
WebhookErrorCode.GRAPHQL_ERROR,
),
(
- """
- query {{
- }
- """,
- "Syntax Error GraphQL (2:20) Expected Name, found",
+ SUBSCRIPTION_SYNTAX_ERROR,
+ "Syntax Error GraphQL (2:8) Expected Name, found",
GraphQLSyntaxError,
WebhookErrorCode.SYNTAX,
),
(
- """
- query {
- channels {
- name
- }
- }
- """,
+ SUBSCRIPTION_QUERY_USED,
"Subscription operation can't be found.",
ValidationError,
WebhookErrorCode.MISSING_SUBSCRIPTION,
),
(
- """
- subscription {
- event {
- issuedAt
- }
- }
- """,
+ SUBSCRIPTION_MISSING_EVENT,
"Can't find a single event.",
ValidationError,
WebhookErrorCode.MISSING_EVENT,
),
+ (
+ SUBSCRIPTION_FILTERABLE_ORDER_CREATED_AND_EVENT_MANY_TOP_FIELDS,
+ "Subscription must select only one top field.",
+ ValidationError,
+ WebhookErrorCode.INVALID,
+ ),
+ (
+ SUBSCRIPTION_MANY_TOP_FILTERABLE_FIELDS,
+ "Subscription must select only one top field.",
+ ValidationError,
+ WebhookErrorCode.INVALID,
+ ),
+ (
+ SUBSCRIPTION_MANY_TOP_FILTERABLE_FIELDS_WITH_ALIAS,
+ "Subscription must select only one top field.",
+ ValidationError,
+ WebhookErrorCode.INVALID,
+ ),
+ (
+ SUBSCRIPTION_MANY_TOP_FILTERABLE_DIFFERENT_FIELDS,
+ "Subscription must select only one top field.",
+ ValidationError,
+ WebhookErrorCode.INVALID,
+ ),
+ (
+ SUBSCRIPTION_MANY_TOP_FILTERABLE_DIFFERENT_FIELDS_WITH_ALIAS,
+ "Subscription must select only one top field.",
+ ValidationError,
+ WebhookErrorCode.INVALID,
+ ),
],
)
def test_query_validation(query, error_msg, error_type, error_code):
@@ -369,3 +628,94 @@ def test_get_events_from_field():
"OrderFullyPaid": IsFragment.FALSE,
"EventFragment": IsFragment.TRUE,
}
+
+
+def test_get_filterable_channel_slugs_for_query_with_filters():
+ # given
+ query = """
+ subscription {
+ orderConfirmed(channels: ["default-channel"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }
+ """
+ subscription_query = SubscriptionQuery(query)
+
+ # when
+ result = subscription_query.get_filterable_channel_slugs()
+
+ # then
+ assert result == ["default-channel"]
+
+
+def test_get_filterable_channel_slugs_with_empty_filters():
+ # given
+ query = """
+ subscription {
+ orderConfirmed {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }
+ """
+ subscription_query = SubscriptionQuery(query)
+
+ # when
+ result = subscription_query.get_filterable_channel_slugs()
+
+ # then
+ assert result == []
+
+
+def test_get_filterable_channel_slugs_for_non_filterable_query():
+ # given
+ query = """
+ fragment EventFragment on Event {
+ ... on OrderUpdated {
+ order {
+ id
+ }
+ }
+ }
+ subscription {
+ event {
+ ... on OrderCreated {
+ order {
+ id
+ }
+ }
+ something
+ somethingElse
+ ... on OrderFullyPaid {
+ order {
+ id
+ }
+ }
+ ... EventFragment
+ }
+ }
+ """
+ subscription_query = SubscriptionQuery(query)
+
+ # when
+ result = subscription_query.get_filterable_channel_slugs()
+
+ # then
+ assert result == []
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 3938160c3e..0c8af9650c 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -10,6 +10,7 @@ import graphene
from django.conf import settings
from ...app.models import App
+from ...channel.models import Channel
from ...checkout.fetch import CheckoutInfo, CheckoutLineInfo
from ...checkout.models import Checkout
from ...core import EventDeliveryStatus
@@ -121,7 +122,6 @@ from ..base_plugin import BasePlugin, ExcludedShippingMethod
if TYPE_CHECKING:
from ...account.models import Address, Group, User
from ...attribute.models import Attribute, AttributeValue
- from ...channel.models import Channel
from ...core.utils.translations import Translation
from ...csv.models import ExportFile
from ...discount.models import Promotion, PromotionRule, Voucher, VoucherCode
@@ -728,11 +728,38 @@ class WebhookPlugin(BasePlugin):
export,
)
+ def _get_webhooks_for_order_events(
+ self,
+ event_type: str,
+ order: "Order",
+ webhooks: Optional[Iterable["Webhook"]] = None,
+ ) -> Iterable["Webhook"]:
+ """Get webhooks for order events.
+
+ Fetch all valid webhooks and filter out the ones that have a subscription query
+ with filter that doesn't match to the order.
+ """
+ order_channel_slug = order.channel.slug
+ if webhooks is None:
+ webhooks = get_webhooks_for_event(event_type)
+ filtered_webhooks = []
+ for webhook in webhooks:
+ if not webhook.subscription_query:
+ filtered_webhooks.append(webhook)
+ continue
+ filterable_channel_slugs = list(webhook.filterable_channel_slugs)
+ if not filterable_channel_slugs:
+ filtered_webhooks.append(webhook)
+ continue
+ if order_channel_slug in filterable_channel_slugs:
+ filtered_webhooks.append(webhook)
+ return filtered_webhooks
+
def order_created(self, order: "Order", previous_value: Any, webhooks=None) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_CREATED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -825,7 +852,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_CONFIRMED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -845,7 +872,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULLY_PAID
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -863,7 +890,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_PAID
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -881,7 +908,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_REFUNDED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -901,7 +928,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULLY_REFUNDED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -919,7 +946,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_UPDATED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -937,7 +964,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_EXPIRED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1239,7 +1266,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_CANCELLED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1259,7 +1286,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULFILLED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1278,18 +1305,48 @@ class WebhookPlugin(BasePlugin):
) -> Any:
if not self.active:
return previous_value
+ event_type = WebhookEventAsyncType.ORDER_METADATA_UPDATED
+ webhooks = self._get_webhooks_for_order_events(event_type, order, webhooks)
self._trigger_metadata_updated_event(
- WebhookEventAsyncType.ORDER_METADATA_UPDATED,
+ event_type,
order,
webhooks=webhooks,
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
+ def _get_webhooks_for_order_bulk_created_event(
+ self, order_channel_slugs: set[str]
+ ) -> Iterable["Webhook"]:
+ """Get webhooks for order events.
+
+ Fetch all valid webhooks and filter out the ones that have a subscription query
+ with filter that doesn't match to the order.
+ """
+ webhooks = get_webhooks_for_event(WebhookEventAsyncType.ORDER_BULK_CREATED)
+ filtered_webhooks = []
+ for webhook in webhooks:
+ if not webhook.subscription_query:
+ filtered_webhooks.append(webhook)
+ continue
+ filterable_channel_slugs = list(webhook.filterable_channel_slugs)
+ if not filterable_channel_slugs:
+ filtered_webhooks.append(webhook)
+ continue
+ if order_channel_slugs.intersection(filterable_channel_slugs):
+ filtered_webhooks.append(webhook)
+ return filtered_webhooks
+
def order_bulk_created(self, orders: list["Order"], previous_value: Any) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_BULK_CREATED
- if webhooks := get_webhooks_for_event(event_type):
+ channel_ids = {order.channel_id for order in orders}
+ channel_slugs = Channel.objects.filter(id__in=channel_ids).values_list(
+ "slug", flat=True
+ )
+ if webhooks := self._get_webhooks_for_order_bulk_created_event(
+ set(channel_slugs)
+ ):
def generate_bulk_order_payload():
return [
@@ -1312,7 +1369,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_CREATED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1332,7 +1389,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_UPDATED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1352,7 +1409,7 @@ class WebhookPlugin(BasePlugin):
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_DELETED
- if webhooks := self._get_webhooks_for_event(event_type, webhooks):
+ if webhooks := self._get_webhooks_for_order_events(event_type, order, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/__init__.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_created.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_created.py
new file mode 100644
index 0000000000..eaaf053329
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_created.py
@@ -0,0 +1,235 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+DRAFT_ORDER_CREATED_SUBSCRIPTION = """
+subscription {
+ draftOrderCreated(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_created(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_CREATED
+
+ query = DRAFT_ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_created(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderCreated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_created_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_CREATED
+
+ query = """subscription {
+ draftOrderCreated {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_created(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderCreated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_created_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+
+ manager = get_plugins_manager(False)
+
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = DRAFT_ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_created(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = DRAFT_ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_created(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_deleted.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_deleted.py
new file mode 100644
index 0000000000..d6383444ae
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_deleted.py
@@ -0,0 +1,194 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+DRAFT_ORDER_DELETED_SUBSCRIPTION = """
+subscription {
+ draftOrderDeleted(channels: ["%s"]) {
+ order {
+ id
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_deleted(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_DELETED
+
+ query = DRAFT_ORDER_DELETED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_deleted(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderDeleted": {
+ "order": {
+ "id": order_id,
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_deleted_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_DELETED
+
+ query = """subscription {
+ draftOrderDeleted {
+ order {
+ id
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_deleted(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderDeleted": {
+ "order": {
+ "id": order_id,
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_updated_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_DELETED
+
+ query = DRAFT_ORDER_DELETED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_deleted(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = DRAFT_ORDER_DELETED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_deleted(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_updated.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_updated.py
new file mode 100644
index 0000000000..87856c46c7
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_draft_order_updated.py
@@ -0,0 +1,233 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+DRAFT_ORDER_UPDATED_SUBSCRIPTION = """
+subscription {
+ draftOrderUpdated(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_updated(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_UPDATED
+
+ query = DRAFT_ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_updated_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_UPDATED
+
+ query = """subscription {
+ draftOrderUpdated {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.draft_order_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "draftOrderUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_draft_order_updated_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.DRAFT_ORDER_UPDATED
+
+ query = DRAFT_ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = DRAFT_ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.draft_order_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_bulk_created.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_bulk_created.py
new file mode 100644
index 0000000000..cd1e098087
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_bulk_created.py
@@ -0,0 +1,237 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_BULK_CREATED_SUBSCRIPTION = """
+subscription {
+ orderBulkCreated(channels: ["%s"]) {
+ orders {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_bulk_created(
+ mocked_async,
+ order_line,
+ subscription_webhook,
+ order_with_lines_channel_PLN,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ second_channel = order_with_lines_channel_PLN.channel
+ assert second_channel.slug == "c-pln"
+
+ event_type = WebhookEventAsyncType.ORDER_BULK_CREATED
+
+ query = ORDER_BULK_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_bulk_created([order, order_with_lines_channel_PLN])
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderBulkCreated": {
+ "orders": [
+ {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ ]
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_bulk_created_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ query = """subscription {
+ orderBulkCreated {
+ orders {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, WebhookEventAsyncType.ORDER_BULK_CREATED)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_bulk_created([order])
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderBulkCreated": {
+ "orders": [
+ {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ ]
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_bulk_created_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ query = ORDER_BULK_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, WebhookEventAsyncType.ORDER_BULK_CREATED)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_bulk_created([order])
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ query = ORDER_BULK_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, WebhookEventAsyncType.ORDER_CREATED)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_bulk_created([order])
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_cancelled.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_cancelled.py
new file mode 100644
index 0000000000..8058c2e9f3
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_cancelled.py
@@ -0,0 +1,229 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_CANCELLED_SUBSCRIPTION = """
+subscription {
+ orderCancelled(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_cancelled(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CANCELLED
+
+ query = ORDER_CANCELLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_cancelled(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderCancelled": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_cancelled_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_CANCELLED
+ query = """subscription {
+ orderCancelled {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_cancelled(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderCancelled": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_cancelled_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CANCELLED
+
+ query = ORDER_CANCELLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_cancelled(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_CANCELLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_cancelled(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_confirmed.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_confirmed.py
new file mode 100644
index 0000000000..851b37e2fe
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_confirmed.py
@@ -0,0 +1,230 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_CONFIRMED_SUBSCRIPTION = """
+subscription {
+ orderConfirmed(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_confirmed(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CONFIRMED
+
+ query = ORDER_CONFIRMED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_confirmed(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderConfirmed": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_confirmed_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_CONFIRMED
+
+ query = """subscription {
+ orderConfirmed {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_confirmed(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderConfirmed": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_confirmed_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CONFIRMED
+
+ query = ORDER_CONFIRMED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_confirmed(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_CONFIRMED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_confirmed(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_created.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_created.py
new file mode 100644
index 0000000000..798c9d2a67
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_created.py
@@ -0,0 +1,228 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_CREATED_SUBSCRIPTION = """
+subscription {
+ orderCreated(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_created(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_created(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderCreated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_created_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = """subscription {
+ orderCreated {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_created(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderCreated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_created_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_created(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = ORDER_CREATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_created(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_expired.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_expired.py
new file mode 100644
index 0000000000..cb7a9200dc
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_expired.py
@@ -0,0 +1,231 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_EXPIRED_SUBSCRIPTION = """
+subscription {
+ orderExpired(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_expired(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_EXPIRED
+
+ query = ORDER_EXPIRED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_expired(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderExpired": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_expired_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_EXPIRED
+
+ query = """subscription {
+ orderExpired {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_expired(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderExpired": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_expired_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_EXPIRED
+
+ query = ORDER_EXPIRED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_expired(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_EXPIRED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_expired(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fulfilled.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fulfilled.py
new file mode 100644
index 0000000000..4575f84682
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fulfilled.py
@@ -0,0 +1,230 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_FULFILLED_SUBSCRIPTION = """
+subscription {
+ orderFulfilled(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fulfilled(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULFILLED
+
+ query = ORDER_FULFILLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fulfilled(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFulfilled": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fulfilled_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_FULFILLED
+
+ query = """subscription {
+ orderFulfilled {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fulfilled(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFulfilled": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fulfilled_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULFILLED
+ query = ORDER_FULFILLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fulfilled(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_FULFILLED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fulfilled(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_paid.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_paid.py
new file mode 100644
index 0000000000..94d4b86294
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_paid.py
@@ -0,0 +1,230 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_FULLY_PAID_SUBSCRIPTION = """
+subscription {
+ orderFullyPaid(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_paid(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_PAID
+
+ query = ORDER_FULLY_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fully_paid(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFullyPaid": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_paid_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_PAID
+
+ query = """subscription {
+ orderFullyPaid {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fully_paid(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFullyPaid": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_paid_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_PAID
+
+ query = ORDER_FULLY_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fully_paid(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_FULLY_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fully_paid(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_refunded.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_refunded.py
new file mode 100644
index 0000000000..bddf2dd090
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_fully_refunded.py
@@ -0,0 +1,231 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_FULLY_REFUNDED_SUBSCRIPTION = """
+subscription {
+ orderFullyRefunded(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_refunded(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_REFUNDED
+
+ query = ORDER_FULLY_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fully_refunded(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFullyRefunded": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_refunded_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_REFUNDED
+
+ query = """subscription {
+ orderFullyRefunded {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_fully_refunded(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderFullyRefunded": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_fully_refunded_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_FULLY_REFUNDED
+
+ query = ORDER_FULLY_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fully_refunded(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_FULLY_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_fully_refunded(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_metadata_updated.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_metadata_updated.py
new file mode 100644
index 0000000000..80e757fc3a
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_metadata_updated.py
@@ -0,0 +1,232 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_METADATA_UPDATED_SUBSCRIPTION = """
+subscription {
+ orderMetadataUpdated(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_metadata_updated(
+ mocked_async, order_line, subscription_webhook, settings
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_METADATA_UPDATED
+
+ query = ORDER_METADATA_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_metadata_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderMetadataUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_metadata_updated_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_METADATA_UPDATED
+
+ query = """subscription {
+ orderMetadataUpdated {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_metadata_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderMetadataUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_metadata_updated_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_METADATA_UPDATED
+
+ query = ORDER_METADATA_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_metadata_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_METADATA_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_metadata_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_paid.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_paid.py
new file mode 100644
index 0000000000..fd3520f9b2
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_paid.py
@@ -0,0 +1,231 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_PAID_SUBSCRIPTION = """
+subscription {
+ orderPaid(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_paid(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_PAID
+
+ query = ORDER_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_paid(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderPaid": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_paid_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_PAID
+
+ query = """subscription {
+ orderPaid {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_paid(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderPaid": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_paid_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_PAID
+
+ query = ORDER_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_paid(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_PAID_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_paid(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_refunded.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_refunded.py
new file mode 100644
index 0000000000..d6db128562
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_refunded.py
@@ -0,0 +1,229 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_REFUNDED_SUBSCRIPTION = """
+subscription {
+ orderRefunded(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_refunded(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_REFUNDED
+
+ query = ORDER_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_refunded(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderRefunded": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_refunded_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+
+ event_type = WebhookEventAsyncType.ORDER_REFUNDED
+
+ query = """subscription {
+ orderRefunded {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_refunded(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderRefunded": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_refunded_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_REFUNDED
+ query = ORDER_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_refunded(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_REFUNDED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_refunded(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_updated.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_updated.py
new file mode 100644
index 0000000000..e2fd421e0f
--- /dev/null
+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_order_updated.py
@@ -0,0 +1,231 @@
+import json
+from unittest.mock import patch
+
+import graphene
+from django.test import override_settings
+
+from ......core.models import EventDelivery
+from ......graphql.webhook.subscription_query import SubscriptionQuery
+from ......webhook.event_types import WebhookEventAsyncType
+from .....manager import get_plugins_manager
+
+ORDER_UPDATED_SUBSCRIPTION = """
+subscription {
+ orderUpdated(channels: ["%s"]) {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_updated(mocked_async, order_line, subscription_webhook, settings):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+ query = ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_updated_without_channels_input(
+ mocked_async, order_line, subscription_webhook
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = """subscription {
+ orderUpdated {
+ order {
+ id
+ number
+ lines {
+ id
+ variant {
+ id
+ }
+ }
+ }
+ }
+ }"""
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ order_id = graphene.Node.to_global_id("Order", order.id)
+
+ # when
+ manager.order_updated(order)
+
+ # then
+ expected_payload = json.dumps(
+ {
+ "data": {
+ "orderUpdated": {
+ "order": {
+ "id": order_id,
+ "number": str(order.number),
+ "lines": [
+ {
+ "id": graphene.Node.to_global_id(
+ "OrderLine", order_line.id
+ ),
+ "variant": {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", order_line.variant_id
+ )
+ },
+ }
+ ],
+ }
+ }
+ }
+ }
+ )
+
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 1
+ assert deliveries[0].payload.get_payload() == expected_payload
+ assert deliveries[0].webhook == webhook
+ assert mocked_async.called
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_order_updated_with_different_channel(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_with_lines_channel_PLN,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+
+ order = order_with_lines_channel_PLN
+ channel = order.channel
+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_UPDATED
+
+ query = ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
+
+
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"
+)
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_different_event_doesnt_trigger_webhook(
+ mocked_async,
+ mocked_create_event_delivery_list_for_webhooks,
+ order_line,
+ subscription_webhook,
+ settings,
+):
+ # given
+ manager = get_plugins_manager(False)
+ order = order_line.order
+ channel = order.channel
+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG
+
+ event_type = WebhookEventAsyncType.ORDER_CREATED
+
+ query = ORDER_UPDATED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG
+
+ webhook = subscription_webhook(query, event_type)
+ subscription_query = SubscriptionQuery(query)
+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()
+ webhook.save()
+
+ # when
+ manager.order_updated(order)
+
+ # then
+ assert not mocked_async.called
+ assert not mocked_create_event_delivery_list_for_webhooks.called
+ deliveries = EventDelivery.objects.all()
+ assert len(deliveries) == 0
diff --git a/saleor/webhook/const.py b/saleor/webhook/const.py
index 429f02b038..10b03fb11a 100644
--- a/saleor/webhook/const.py
+++ b/saleor/webhook/const.py
@@ -1,3 +1,5 @@
CACHE_EXCLUDED_SHIPPING_TIME = 60 * 3
WEBHOOK_CACHE_DEFAULT_TIMEOUT: int = 5 * 60 # 5 minutes
APP_ID_PREFIX = "app"
+
+MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT = 500
diff --git a/saleor/webhook/migrations/0011_webhook_filterable_channel_slugs.py b/saleor/webhook/migrations/0011_webhook_filterable_channel_slugs.py
new file mode 100644
index 0000000000..4cd05cc4a0
--- /dev/null
+++ b/saleor/webhook/migrations/0011_webhook_filterable_channel_slugs.py
@@ -0,0 +1,31 @@
+# Generated by Django 4.2.15 on 2024-08-20 07:42
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("webhook", "0010_drop_transaction_request_action_event"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="webhook",
+ name="filterable_channel_slugs",
+ field=django.contrib.postgres.fields.ArrayField(
+ base_field=models.CharField(max_length=255),
+ default=list,
+ size=500,
+ blank=True,
+ ),
+ ),
+ migrations.RunSQL(
+ """
+ ALTER TABLE webhook_webhook
+ ALTER COLUMN filterable_channel_slugs
+ SET DEFAULT array[]::varchar[];
+ """,
+ migrations.RunSQL.noop,
+ ),
+ ]
diff --git a/saleor/webhook/migrations/0012_webhook_filterable_channel_slugs_idx.py b/saleor/webhook/migrations/0012_webhook_filterable_channel_slugs_idx.py
new file mode 100644
index 0000000000..518bcec3f0
--- /dev/null
+++ b/saleor/webhook/migrations/0012_webhook_filterable_channel_slugs_idx.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2024-08-20 08:30
+
+import django.contrib.postgres.indexes
+from django.contrib.postgres.operations import AddIndexConcurrently
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("webhook", "0011_webhook_filterable_channel_slugs"),
+ ]
+
+ operations = [
+ AddIndexConcurrently(
+ model_name="webhook",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["filterable_channel_slugs"],
+ name="filterable_channel_slugs_idx",
+ ),
+ ),
+ ]
diff --git a/saleor/webhook/models.py b/saleor/webhook/models.py
index eeb453c1d3..27d61f179e 100644
--- a/saleor/webhook/models.py
+++ b/saleor/webhook/models.py
@@ -1,8 +1,11 @@
+from django.contrib.postgres.fields import ArrayField
+from django.contrib.postgres.indexes import GinIndex
from django.db import models
from ..app.models import App
from ..app.validators import AppURLValidator
from ..core.utils.json_serializer import CustomJsonEncoder
+from .const import MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT
from .validators import custom_headers_validator
@@ -26,9 +29,21 @@ class Webhook(models.Model):
encoder=CustomJsonEncoder,
validators=[custom_headers_validator],
)
+ filterable_channel_slugs = ArrayField(
+ models.CharField(max_length=255),
+ blank=True,
+ default=list,
+ size=MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT,
+ )
class Meta:
ordering = ("pk",)
+ indexes = [
+ GinIndex(
+ name="filterable_channel_slugs_idx",
+ fields=["filterable_channel_slugs"],
+ )
+ ]
def __str__(self):
return self.name