Re-check promo code validity during checkout (#1316)

* Re-check promo code validity during checkout

* Add tools mock to the failing test

* Properly resolve issue with the tests
This commit is contained in:
Belle Aerni authored and GitHub committed 2023-06-12 06:30:45 +02:00
1 parent b65a75fcf7
commit a02b1b32fe
2 files changed
+11 -2

No files matched your search

+8
View File
@@ -424,6 +424,14 @@ class Service implements InjectionAwareInterface
if (!$this->isClientAbleToUsePromo($client, $promo)) {
throw new \Box_Exception('You have already used this promo code. Please remove promo code and checkout again.', null, 9874);
}
if (!$promo instanceof \Model_Promo) {
throw new \Box_Exception('Promo code is expired or does not exist');
}
if (!$this->isPromoAvailableForClientGroup($promo)) {
throw new \Box_Exception('Promo can not be applied to your account');
}
}
$this->di['events_manager']->fire(
+3 -2
View File
@@ -654,13 +654,15 @@ class ServiceTest extends \BBTestCase
$order->loadBean(new \DummyBean());
$serviceMock = $this->getMockBuilder('\Box\Mod\Cart\Service')
->setMethods(array('createFromCart', 'isClientAbleToUsePromo', 'rm'))->getMock();
->setMethods(array('createFromCart', 'isClientAbleToUsePromo', 'rm', 'isPromoAvailableForClientGroup'))->getMock();
$serviceMock->expects($this->atLeastOnce())->method('createFromCart')
->will($this->returnValue(array($order, rand(1, 100), array(rand(1, 100)))));
$serviceMock->expects($this->atLeastOnce())->method('isClientAbleToUsePromo')
->will($this->returnValue(true));
$serviceMock->expects($this->atLeastOnce())->method('rm')
->will($this->returnValue(true));
$serviceMock->expects($this->atLeastOnce())->method('isPromoAvailableForClientGroup')
->will($this->returnValue(true));
$eventMock = $this->getMockBuilder('\Box_EventManager')->getMock();
$eventMock->expects($this->atLeastOnce())->method('fire');
@@ -671,7 +673,6 @@ class ServiceTest extends \BBTestCase
->method('getClientAddress')
->will($this->returnValue('1.1.1.1'));
$invoice = new \Model_Invoice();
$invoice->loadBean(new \DummyBean());
$invoice->hash = sha1('str');