Skip to content

Commit cc13123

Browse files
committed
GraphQL-676: Test unsubscribe customer
1 parent 02bca98 commit cc13123

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/SubscriptionStatusTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Exception;
11+
use Magento\Framework\Exception\AuthenticationException;
1012
use Magento\Integration\Api\CustomerTokenServiceInterface;
1113
use Magento\Newsletter\Model\SubscriberFactory;
1214
use Magento\TestFramework\Helper\Bootstrap;
@@ -55,7 +57,7 @@ public function testGetSubscriptionStatusTest()
5557
}
5658

5759
/**
58-
* @expectedException \Exception
60+
* @expectedException Exception
5961
* @expectedExceptionMessage The current customer isn't authorized.
6062
*/
6163
public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest()
@@ -101,7 +103,7 @@ public function testChangeSubscriptionStatusTest()
101103
}
102104

103105
/**
104-
* @expectedException \Exception
106+
* @expectedException Exception
105107
* @expectedExceptionMessage The current customer isn't authorized.
106108
*/
107109
public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest()
@@ -122,10 +124,37 @@ public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest()
122124
$this->graphQlMutation($query);
123125
}
124126

127+
/**
128+
* @magentoApiDataFixture Magento/Newsletter/_files/subscribers.php
129+
*/
130+
public function testUnsubscribeCustomer()
131+
{
132+
$currentEmail = 'customer@example.com';
133+
$currentPassword = 'password';
134+
135+
$query = <<<QUERY
136+
mutation {
137+
updateCustomer(
138+
input: {
139+
is_subscribed: false
140+
}
141+
) {
142+
customer {
143+
is_subscribed
144+
}
145+
}
146+
}
147+
QUERY;
148+
$response = $this->graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
149+
$this->assertFalse($response['updateCustomer']['customer']['is_subscribed']);
150+
}
151+
125152
/**
126153
* @param string $email
127154
* @param string $password
155+
*
128156
* @return array
157+
* @throws AuthenticationException
129158
*/
130159
private function getCustomerAuthHeaders(string $email, string $password): array
131160
{

0 commit comments

Comments
 (0)