|
11 | 11 | use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
|
12 | 12 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
13 | 13 | use Magento\TestFramework\Helper\Bootstrap;
|
| 14 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
14 | 15 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
15 | 16 |
|
16 | 17 | /**
|
@@ -147,13 +148,56 @@ public function testRemoveItemFromAnotherCustomerCart()
|
147 | 148 | 'test_quote',
|
148 | 149 | 'simple_product'
|
149 | 150 | );
|
| 151 | + $query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId); |
150 | 152 |
|
151 |
| - $this->expectExceptionMessage( |
152 |
| - "The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\"" |
153 |
| - ); |
| 153 | + try { |
| 154 | + $this->graphQlMutation( |
| 155 | + $query, |
| 156 | + [], |
| 157 | + '', |
| 158 | + $this->getHeaderMap('customer2@search.example.com') |
| 159 | + ); |
| 160 | + $this->fail('ResponseContainsErrorsException was not thrown'); |
| 161 | + } catch (ResponseContainsErrorsException $e) { |
| 162 | + $this->assertStringContainsString( |
| 163 | + "The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\"", |
| 164 | + $e->getMessage() |
| 165 | + ); |
| 166 | + $cartQuery = $this->getCartQuery($anotherCustomerQuoteMaskedId); |
| 167 | + $cart = $this->graphQlQuery( |
| 168 | + $cartQuery, |
| 169 | + [], |
| 170 | + '', |
| 171 | + $this->getHeaderMap('customer@search.example.com') |
| 172 | + ); |
| 173 | + $this->assertTrue(count($cart['cart']['items']) > 0, 'The cart is empty'); |
| 174 | + $this->assertTrue( |
| 175 | + $cart['cart']['items'][0]['product']['sku'] === 'simple_product', |
| 176 | + 'The cart doesn\'t contain product' |
| 177 | + ); |
| 178 | + } |
| 179 | + } |
154 | 180 |
|
155 |
| - $query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId); |
156 |
| - $this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com')); |
| 181 | + /** |
| 182 | + * @param string $maskedQuoteId |
| 183 | + * @return string |
| 184 | + */ |
| 185 | + private function getCartQuery(string $maskedQuoteId): string |
| 186 | + { |
| 187 | + return <<<QUERY |
| 188 | +{ |
| 189 | + cart(cart_id: "{$maskedQuoteId}") { |
| 190 | + id |
| 191 | + items { |
| 192 | + id |
| 193 | + quantity |
| 194 | + product { |
| 195 | + sku |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | +} |
| 200 | +QUERY; |
157 | 201 | }
|
158 | 202 |
|
159 | 203 | /**
|
|
0 commit comments