7
7
8
8
namespace Magento \GraphQl \Customer ;
9
9
10
+ use Exception ;
11
+ use Magento \Framework \Exception \AuthenticationException ;
10
12
use Magento \Integration \Api \CustomerTokenServiceInterface ;
11
13
use Magento \Newsletter \Model \SubscriberFactory ;
12
14
use Magento \TestFramework \Helper \Bootstrap ;
@@ -55,7 +57,7 @@ public function testGetSubscriptionStatusTest()
55
57
}
56
58
57
59
/**
58
- * @expectedException \ Exception
60
+ * @expectedException Exception
59
61
* @expectedExceptionMessage The current customer isn't authorized.
60
62
*/
61
63
public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest ()
@@ -101,7 +103,7 @@ public function testChangeSubscriptionStatusTest()
101
103
}
102
104
103
105
/**
104
- * @expectedException \ Exception
106
+ * @expectedException Exception
105
107
* @expectedExceptionMessage The current customer isn't authorized.
106
108
*/
107
109
public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest ()
@@ -122,10 +124,37 @@ public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest()
122
124
$ this ->graphQlMutation ($ query );
123
125
}
124
126
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
+
125
152
/**
126
153
* @param string $email
127
154
* @param string $password
155
+ *
128
156
* @return array
157
+ * @throws AuthenticationException
129
158
*/
130
159
private function getCustomerAuthHeaders (string $ email , string $ password ): array
131
160
{
0 commit comments