1818use Magento \Customer \Model \CustomerAuthUpdate ;
1919use Magento \Customer \Model \CustomerRegistry ;
2020use Magento \Customer \Test \Fixture \Customer ;
21+ use Magento \Framework \Exception \LocalizedException ;
2122use Magento \Framework \ObjectManagerInterface ;
2223use Magento \Integration \Api \CustomerTokenServiceInterface ;
2324use Magento \Quote \Test \Fixture \AddProductToCart ;
@@ -76,6 +77,11 @@ protected function setUp(): void
7677 $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
7778 }
7879
80+ /**
81+ * Test graphql customer orders
82+ *
83+ * @throws LocalizedException
84+ */
7985 #[
8086 Config(Data::XML_PATH_PRICE_SCOPE , Data::PRICE_SCOPE_WEBSITE ),
8187 DataFixture(WebsiteFixture::class, as: 'website2 ' ),
@@ -146,7 +152,7 @@ public function testGetCustomerOrders()
146152 $ this ->getCustomerHeaders ($ customerToken , $ store2 ->getCode ())
147153 );
148154
149- $ this ->assertNotNull ( $ response ['customer ' ]['orders ' ]);
155+ $ this ->assertEquals ( 2 , count ( $ response ['customer ' ]['orders ' ][ ' items ' ]) );
150156
151157 $ response = $ this ->graphQlQuery (
152158 $ query ,
@@ -155,7 +161,27 @@ public function testGetCustomerOrders()
155161 $ this ->getCustomerHeaders ($ customerToken , $ store3 ->getCode ())
156162 );
157163
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 ' ]));
159185
160186 $ query = $ this ->getCustomerOrdersQuery ();
161187 $ response = $ this ->graphQlQuery (
@@ -165,10 +191,12 @@ public function testGetCustomerOrders()
165191 $ this ->getCustomerHeaders ($ customerToken , null )
166192 );
167193
168- $ this ->assertNotNull ( $ response ['customer ' ]['orders ' ]);
194+ $ this ->assertEquals ( 0 , count ( $ response ['customer ' ]['orders ' ][ ' items ' ]) );
169195 }
170196
171197 /**
198+ * Generate graphql query headers for customer orders
199+ *
172200 * @param string $token
173201 * @param string|null $storeCode
174202 *
@@ -180,6 +208,8 @@ private function getCustomerHeaders(string $token, ?string $storeCode): array
180208 }
181209
182210 /**
211+ * Generate graphql query body for customer orders
212+ *
183213 * @param string|null $scope
184214 *
185215 * @return array|string
@@ -211,6 +241,8 @@ private function getCustomerOrdersQuery(?string $scope = null): array|string
211241 }
212242
213243 /**
244+ * Get customer login token
245+ *
214246 * @param string $email
215247 * @param string $password
216248 * @return string
0 commit comments