Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix collection resolver on menu with invalid channel (#6579)
Damian Wysocki12f3185f55b5
diff --git a/saleor/graphql/menu/tests/test_menu.py b/saleor/graphql/menu/tests/test_menu.pyindex 77107db72f..9fec1b007b 100644--- a/saleor/graphql/menu/tests/test_menu.py+++ b/saleor/graphql/menu/tests/test_menu.py@@ -226,27 +226,30 @@ def test_query_menus_with_sort(assert menus[order]["node"]["name"] == menu_name-def test_menu_item_query(user_api_client, menu_item, published_collection, channel_USD):- query = """- query menuitem($id: ID!, $channel: String) {- menuItem(id: $id, channel: $channel) {+QUERY_MENU_ITEM_BY_ID = """+query menuitem($id: ID!, $channel: String) {+ menuItem(id: $id, channel: $channel) {+ name+ children {+ name+ }+ collection {name- children {- name- }- collection {- name- }- category {- id- }- page {- id- }- url}+ category {+ id+ }+ page {+ id+ }+ url}- """+}+"""+++def test_menu_item_query(user_api_client, menu_item, published_collection, channel_USD):+ query = QUERY_MENU_ITEM_BY_IDmenu_item.collection = published_collectionmenu_item.url = Nonemenu_item.save()@@ -269,6 +272,32 @@ def test_menu_item_query(user_api_client, menu_item, published_collection, channassert data["url"] is None+def test_menu_item_query_with_invalid_channel(+ user_api_client, menu_item, published_collection, channel_USD+):+ query = QUERY_MENU_ITEM_BY_ID+ menu_item.collection = published_collection+ menu_item.url = None+ menu_item.save()+ child_menu = MenuItem.objects.create(+ menu=menu_item.menu, name="Link 2", url="http://example2.com/", parent=menu_item+ )+ variables = {+ "id": graphene.Node.to_global_id("MenuItem", menu_item.pk),+ "channel": "invalid",+ }+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["menuItem"]+ assert data["name"] == menu_item.name+ assert len(data["children"]) == 1+ assert data["children"][0]["name"] == child_menu.name+ assert not data["collection"]+ assert not data["category"]+ assert not data["page"]+ assert data["url"] is None++def test_menu_items_query(user_api_client, menu_with_items, published_collection, channel_USD, category):diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.pyindex fb1a723c14..9a7019f4d4 100644--- a/saleor/graphql/menu/types.py+++ b/saleor/graphql/menu/types.py@@ -122,6 +122,8 @@ class MenuItem(ChannelContextType, CountableDjangoObjectType):def calculate_collection_availability(collection_channel_listing):def calculate_collection_availability_with_channel(channel):+ if not channel:+ return Nonecollection_is_visible = (collection_channel_listing.is_visibleif collection_channel_listing