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 ;
@@ -50,12 +52,12 @@ public function testGetSubscriptionStatusTest()
50
52
}
51
53
}
52
54
QUERY ;
53
- $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword ));
55
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ($ currentEmail , $ currentPassword ));
54
56
$ this ->assertFalse ($ response ['customer ' ]['is_subscribed ' ]);
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 ()
@@ -73,7 +75,7 @@ public function testGetSubscriptionStatusIfUserIsNotAuthorizedTest()
73
75
/**
74
76
* @magentoApiDataFixture Magento/Customer/_files/customer.php
75
77
*/
76
- public function testChangeSubscriptionStatusTest ()
78
+ public function testSubscribeCustomer ()
77
79
{
78
80
$ currentEmail = 'customer@example.com ' ;
79
81
$ currentPassword = 'password ' ;
@@ -95,13 +97,13 @@ public function testChangeSubscriptionStatusTest()
95
97
$ query ,
96
98
[],
97
99
'' ,
98
- $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword )
100
+ $ this ->getHeaderMap ($ currentEmail , $ currentPassword )
99
101
);
100
102
$ this ->assertTrue ($ response ['updateCustomer ' ]['customer ' ]['is_subscribed ' ]);
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,12 +124,39 @@ 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 ->getHeaderMap ($ 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
- private function getCustomerAuthHeaders (string $ email , string $ password ): array
159
+ private function getHeaderMap (string $ email , string $ password ): array
131
160
{
132
161
$ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ($ email , $ password );
133
162
return ['Authorization ' => 'Bearer ' . $ customerToken ];
0 commit comments