77
88namespace Magento \GraphQl \Customer ;
99
10+ use Exception ;
11+ use Magento \Framework \Exception \AuthenticationException ;
1012use Magento \Integration \Api \CustomerTokenServiceInterface ;
1113use Magento \Newsletter \Model \SubscriberFactory ;
1214use Magento \TestFramework \Helper \Bootstrap ;
@@ -50,12 +52,12 @@ public function testGetSubscriptionStatusTest()
5052 }
5153}
5254QUERY ;
53- $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword ));
55+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ($ currentEmail , $ currentPassword ));
5456 $ this ->assertFalse ($ response ['customer ' ]['is_subscribed ' ]);
5557 }
5658
5759 /**
58- * @expectedException \ Exception
60+ * @expectedException Exception
5961 * @expectedExceptionMessage The current customer isn't authorized.
6062 */
6163 public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest ()
@@ -73,7 +75,7 @@ public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest()
7375 /**
7476 * @magentoApiDataFixture Magento/Customer/_files/customer.php
7577 */
76- public function testChangeSubscriptionStatusTest ()
78+ public function testSubscribeCustomer ()
7779 {
7880 $ currentEmail = 'customer@example.com ' ;
7981 $ currentPassword = 'password ' ;
@@ -95,13 +97,13 @@ public function testChangeSubscriptionStatusTest()
9597 $ query ,
9698 [],
9799 '' ,
98- $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword )
100+ $ this ->getHeaderMap ($ currentEmail , $ currentPassword )
99101 );
100102 $ this ->assertTrue ($ response ['updateCustomer ' ]['customer ' ]['is_subscribed ' ]);
101103 }
102104
103105 /**
104- * @expectedException \ Exception
106+ * @expectedException Exception
105107 * @expectedExceptionMessage The current customer isn't authorized.
106108 */
107109 public function testChangeSubscriptionStatuIfUserIsNotAuthorizedTest ()
@@ -122,12 +124,39 @@ 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 ->getHeaderMap ($ 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 */
130- private function getCustomerAuthHeaders (string $ email , string $ password ): array
159+ private function getHeaderMap (string $ email , string $ password ): array
131160 {
132161 $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ($ email , $ password );
133162 return ['Authorization ' => 'Bearer ' . $ customerToken ];
0 commit comments