Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
ISSUE 218 - Prevent cancelling order with cancelled attendee causing negative capacity
Dave Earley8c3a7f0cc094
diff --git a/backend/app/Services/Domain/Order/OrderCancelService.php b/backend/app/Services/Domain/Order/OrderCancelService.phpindex 204cf29a0..b9e1125d8 100644--- a/backend/app/Services/Domain/Order/OrderCancelService.php+++ b/backend/app/Services/Domain/Order/OrderCancelService.php@@ -70,9 +70,11 @@ readonly class OrderCancelService{$attendees = $this->attendeeRepository->findWhere(['order_id' => $order->getId(),+ 'status' => AttendeeStatus::ACTIVE->name,]);- $ticketIdCountMap = $attendees->map(fn(AttendeeDomainObject $attendee) => $attendee->getTicketPriceId())->countBy();+ $ticketIdCountMap = $attendees+ ->map(fn(AttendeeDomainObject $attendee) => $attendee->getTicketPriceId())->countBy();foreach ($ticketIdCountMap as $ticketPriceId => $count) {$this->ticketQuantityService->decreaseQuantitySold($ticketPriceId, $count);diff --git a/backend/tests/Unit/Services/Domain/Order/OrderCancelServiceTest.php b/backend/tests/Unit/Services/Domain/Order/OrderCancelServiceTest.phpindex b64d1f5f6..76a5c1af4 100644--- a/backend/tests/Unit/Services/Domain/Order/OrderCancelServiceTest.php+++ b/backend/tests/Unit/Services/Domain/Order/OrderCancelServiceTest.php@@ -6,6 +6,7 @@ use HiEvents\DomainObjects\AttendeeDomainObject;use HiEvents\DomainObjects\EventDomainObject;use HiEvents\DomainObjects\EventSettingDomainObject;use HiEvents\DomainObjects\OrderDomainObject;+use HiEvents\DomainObjects\Status\AttendeeStatus;use HiEvents\Mail\Order\OrderCancelled;use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;use HiEvents\Repository\Interfaces\EventRepositoryInterface;@@ -63,7 +64,15 @@ class OrderCancelServiceTest extends TestCasem::mock(AttendeeDomainObject::class)->shouldReceive('getTicketPriceId')->andReturn(2)->mock(),]);- $this->attendeeRepository->shouldReceive('findWhere')->once()->andReturn($attendees);+ $this->attendeeRepository+ ->shouldReceive('findWhere')+ ->once()+ ->with([+ 'order_id' => $order->getId(),+ 'status' => AttendeeStatus::ACTIVE->name,+ ])+ ->andReturn($attendees);+$this->attendeeRepository->shouldReceive('updateWhere')->once();$this->ticketQuantityService->shouldReceive('decreaseQuantitySold')->twice();