File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
app/code/Magento/WishlistGraphQl/Model/Resolver
dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1313use Magento \Wishlist \Model \ResourceModel \Wishlist as WishlistResourceModel ;
1414use Magento \Wishlist \Model \Wishlist ;
1515use Magento \Wishlist \Model \WishlistFactory ;
16+ use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
1617
1718/**
1819 * Fetches the Wishlist data according to the GraphQL schema
@@ -51,6 +52,10 @@ public function resolve(
5152 ) {
5253 $ customerId = $ context ->getUserId ();
5354
55+ /* Guest checking */
56+ if (!$ customerId && 0 === $ customerId ) {
57+ throw new GraphQlAuthorizationException (__ ('The current user cannot perform operations on wishlist ' ));
58+ }
5459 /** @var Wishlist $wishlist */
5560 $ wishlist = $ this ->wishlistFactory ->create ();
5661 $ this ->wishlistResource ->load ($ wishlist , $ customerId , 'customer_id ' );
Original file line number Diff line number Diff line change @@ -93,6 +93,36 @@ public function testGetCustomerWishlist(): void
9393 $ this ->assertEquals ($ wishlistItemProduct ->getName (), $ response ['wishlist ' ]['items ' ][0 ]['product ' ]['name ' ]);
9494 }
9595
96+ /**
97+ * @expectedException \Exception
98+ * @expectedExceptionMessage The current user cannot perform operations on wishlist
99+ */
100+ public function testGetGuestWishlist ()
101+ {
102+ $ query =
103+ <<<QUERY
104+ {
105+ wishlist {
106+ items_count
107+ name
108+ sharing_code
109+ updated_at
110+ items {
111+ id
112+ qty
113+ description
114+ added_at
115+ product {
116+ sku
117+ name
118+ }
119+ }
120+ }
121+ }
122+ QUERY ;
123+ $ this ->graphQlQuery ($ query );
124+ }
125+
96126 /**
97127 * @param string $email
98128 * @param string $password
You can’t perform that action at this time.
0 commit comments