Skip to content

Commit 2e4ea72

Browse files
author
David Verholen
committed
GraphQL-43: add test to retrieve wishlist
1 parent 0286f17 commit 2e4ea72

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Wishlist;
9+
10+
use Magento\Integration\Api\CustomerTokenServiceInterface;
11+
use Magento\TestFramework\TestCase\GraphQlAbstract;
12+
use Magento\Wishlist\Model\Item;
13+
14+
class WishlistTest extends GraphQlAbstract
15+
{
16+
/**
17+
* @var \Magento\TestFramework\ObjectManager
18+
*/
19+
private $objectManager;
20+
/**
21+
* @var CustomerTokenServiceInterface
22+
*/
23+
private $customerTokenService;
24+
25+
protected function setUp()
26+
{
27+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
28+
$this->customerTokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
29+
}
30+
31+
/**
32+
* Verify the fields of CMS Block selected by identifiers
33+
*
34+
* @magentoApiDataFixture Magento/Wishlist/_files/wishlist.php
35+
* @throws \Magento\Framework\Exception\AuthenticationException
36+
* @throws \Exception
37+
*/
38+
public function testGetCustomersWishlist(): void
39+
{
40+
/** @var \Magento\Wishlist\Model\Wishlist $wishlist */
41+
$wishlist = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
42+
\Magento\Wishlist\Model\Wishlist::class
43+
);
44+
$wishlist->loadByCustomerId(1, true);
45+
/** @var Item $wishlistItem */
46+
$wishlistItem = $wishlist->getItemCollection()->getFirstItem();
47+
$wishlistItemProduct = $wishlistItem->getProduct();
48+
$query =
49+
<<<QUERY
50+
{
51+
wishlist {
52+
items {
53+
id
54+
qty
55+
product {
56+
sku
57+
name
58+
}
59+
description
60+
added_at
61+
}
62+
sharing_code
63+
updated_at
64+
}
65+
}
66+
QUERY;
67+
68+
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders('customer@example.com', 'password'));
69+
$this->assertEquals($wishlist->getSharingCode(), $response['wishlist']['sharing_code']);
70+
$this->assertEquals($wishlistItem->getData('qty'), $response['wishlist']['items'][0]['qty']);
71+
$this->assertEquals($wishlistItem->getDescription(), $response['wishlist']['items'][0]['description']);
72+
$this->assertEquals($wishlistItemProduct->getSku(), $response['wishlist']['items'][0]['product']['sku']);
73+
$this->assertEquals($wishlistItemProduct->getName(), $response['wishlist']['items'][0]['product']['name']);
74+
}
75+
76+
/**
77+
* @param string $email
78+
* @param string $password
79+
* @return array
80+
* @throws \Magento\Framework\Exception\AuthenticationException
81+
*/
82+
private function getCustomerAuthHeaders(string $email, string $password): array
83+
{
84+
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password);
85+
return ['Authorization' => 'Bearer ' . $customerToken];
86+
}
87+
}

0 commit comments

Comments
 (0)