Skip to content

Commit f527b50

Browse files
author
Anna Bukatar
committed
MC-42813: Feature request: Cart qty update should be reverted back if the requested qty is not available
1 parent 4e73ff3 commit f527b50

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/UpdateItemQtyTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,25 @@ public function testExecute($requestQuantity, $expectedResponse)
8787
$this->dispatch('checkout/cart/updateItemQty');
8888
$response = $this->getResponse()->getBody();
8989

90-
$this->assertEquals($this->json->unserialize($response), $expectedResponse);
90+
$this->assertEquals($this->getErrorMessage($response), $this->getErrorMessage($expectedResponse));
91+
}
92+
93+
/**
94+
* @param $response
95+
* @return string
96+
*/
97+
protected function getErrorMessage($response)
98+
{
99+
$error = '';
100+
try {
101+
$data = is_array($response) ? $response : $this->json->unserialize($response);
102+
$error = $this->json->unserialize($data['error_message'])[0]['error'];
103+
} catch (\Exception $e) {
104+
if (!empty($data['error_message'])) {
105+
$error = $data['error_message'];
106+
}
107+
}
108+
return $error;
91109
}
92110

93111
/**
@@ -115,7 +133,7 @@ public function requestDataProvider(): array
115133
'request' => ['qty' => 230],
116134
'response' => [
117135
'success' => false,
118-
'error_message' => 'The requested qty is not available']
136+
'error_message' => '[{"error":"The requested qty is not available","itemId":3}]']
119137
],
120138
];
121139
}

0 commit comments

Comments
 (0)