18
18
use Magento \Customer \Model \CustomerAuthUpdate ;
19
19
use Magento \Customer \Model \CustomerRegistry ;
20
20
use Magento \Customer \Test \Fixture \Customer ;
21
+ use Magento \Framework \Exception \LocalizedException ;
21
22
use Magento \Framework \ObjectManagerInterface ;
22
23
use Magento \Integration \Api \CustomerTokenServiceInterface ;
23
24
use Magento \Quote \Test \Fixture \AddProductToCart ;
@@ -76,6 +77,11 @@ protected function setUp(): void
76
77
$ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
77
78
}
78
79
80
+ /**
81
+ * Test graphql customer orders
82
+ *
83
+ * @throws LocalizedException
84
+ */
79
85
#[
80
86
Config(Data::XML_PATH_PRICE_SCOPE , Data::PRICE_SCOPE_WEBSITE ),
81
87
DataFixture(WebsiteFixture::class, as: 'website2 ' ),
@@ -146,7 +152,7 @@ public function testGetCustomerOrders()
146
152
$ this ->getCustomerHeaders ($ customerToken , $ store2 ->getCode ())
147
153
);
148
154
149
- $ this ->assertNotNull ( $ response ['customer ' ]['orders ' ]);
155
+ $ this ->assertEquals ( 2 , count ( $ response ['customer ' ]['orders ' ][ ' items ' ]) );
150
156
151
157
$ response = $ this ->graphQlQuery (
152
158
$ query ,
@@ -155,7 +161,27 @@ public function testGetCustomerOrders()
155
161
$ this ->getCustomerHeaders ($ customerToken , $ store3 ->getCode ())
156
162
);
157
163
158
- $ this ->assertNotNull ($ response ['customer ' ]['orders ' ]);
164
+ $ this ->assertEquals (2 , count ($ response ['customer ' ]['orders ' ]['items ' ]));
165
+
166
+ $ query = $ this ->getCustomerOrdersQuery ('WEBSITE ' );
167
+ $ response = $ this ->graphQlQuery (
168
+ $ query ,
169
+ [],
170
+ '' ,
171
+ $ this ->getCustomerHeaders ($ customerToken , $ store2 ->getCode ())
172
+ );
173
+
174
+ $ this ->assertEquals (2 , count ($ response ['customer ' ]['orders ' ]['items ' ]));
175
+
176
+ $ query = $ this ->getCustomerOrdersQuery ('GLOBAL ' );
177
+ $ response = $ this ->graphQlQuery (
178
+ $ query ,
179
+ [],
180
+ '' ,
181
+ $ this ->getCustomerHeaders ($ customerToken , null )
182
+ );
183
+
184
+ $ this ->assertEquals (2 , count ($ response ['customer ' ]['orders ' ]['items ' ]));
159
185
160
186
$ query = $ this ->getCustomerOrdersQuery ();
161
187
$ response = $ this ->graphQlQuery (
@@ -165,10 +191,12 @@ public function testGetCustomerOrders()
165
191
$ this ->getCustomerHeaders ($ customerToken , null )
166
192
);
167
193
168
- $ this ->assertNotNull ( $ response ['customer ' ]['orders ' ]);
194
+ $ this ->assertEquals ( 0 , count ( $ response ['customer ' ]['orders ' ][ ' items ' ]) );
169
195
}
170
196
171
197
/**
198
+ * Generate graphql query headers for customer orders
199
+ *
172
200
* @param string $token
173
201
* @param string|null $storeCode
174
202
*
@@ -180,6 +208,8 @@ private function getCustomerHeaders(string $token, ?string $storeCode): array
180
208
}
181
209
182
210
/**
211
+ * Generate graphql query body for customer orders
212
+ *
183
213
* @param string|null $scope
184
214
*
185
215
* @return array|string
@@ -211,6 +241,8 @@ private function getCustomerOrdersQuery(?string $scope = null): array|string
211
241
}
212
242
213
243
/**
244
+ * Get customer login token
245
+ *
214
246
* @param string $email
215
247
* @param string $password
216
248
* @return string
0 commit comments