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
Organizers unable to message attendees awaiting payment (#520)
Dave Earley28b0ce1ab46a
diff --git a/backend/app/Services/Application/Handlers/Message/SendMessageHandler.php b/backend/app/Services/Application/Handlers/Message/SendMessageHandler.phpindex 1158357cb..da3179a49 100644--- a/backend/app/Services/Application/Handlers/Message/SendMessageHandler.php+++ b/backend/app/Services/Application/Handlers/Message/SendMessageHandler.php@@ -4,7 +4,6 @@ namespace HiEvents\Services\Application\Handlers\Message;use Carbon\Carbon;use HiEvents\DomainObjects\MessageDomainObject;-use HiEvents\DomainObjects\Status\AttendeeStatus;use HiEvents\DomainObjects\Status\MessageStatus;use HiEvents\Exceptions\AccountNotVerifiedException;use HiEvents\Jobs\Event\SendMessagesJob;@@ -98,7 +97,6 @@ class SendMessageHandlervalues: $messageData->attendee_ids,additionalWhere: ['event_id' => $messageData->event_id,- 'status' => AttendeeStatus::ACTIVE->name,],columns: ['id']);diff --git a/backend/tests/Unit/Services/Application/Handlers/Message/SendMessageHandlerTest.php b/backend/tests/Unit/Services/Application/Handlers/Message/SendMessageHandlerTest.phpnew file mode 100644index 000000000..6205ec9b5--- /dev/null+++ b/backend/tests/Unit/Services/Application/Handlers/Message/SendMessageHandlerTest.php@@ -0,0 +1,174 @@+<?php++namespace Tests\Unit\Services\Application\Handlers\Message;++use Carbon\Carbon;+use HiEvents\DomainObjects\AccountDomainObject;+use HiEvents\DomainObjects\AttendeeDomainObject;+use HiEvents\DomainObjects\Enums\MessageTypeEnum;+use HiEvents\DomainObjects\MessageDomainObject;+use HiEvents\DomainObjects\OrderDomainObject;+use HiEvents\DomainObjects\ProductDomainObject;+use HiEvents\Exceptions\AccountNotVerifiedException;+use HiEvents\Jobs\Event\SendMessagesJob;+use HiEvents\Repository\Interfaces\AccountRepositoryInterface;+use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;+use HiEvents\Repository\Interfaces\MessageRepositoryInterface;+use HiEvents\Repository\Interfaces\OrderRepositoryInterface;+use HiEvents\Repository\Interfaces\ProductRepositoryInterface;+use HiEvents\Services\Application\Handlers\Message\DTO\SendMessageDTO;+use HiEvents\Services\Application\Handlers\Message\SendMessageHandler;+use HiEvents\Services\Infrastructure\HtmlPurifier\HtmlPurifierService;+use Illuminate\Config\Repository;+use Illuminate\Support\Facades\Bus;+use Mockery as m;+use Tests\TestCase;++class SendMessageHandlerTest extends TestCase+{+ private OrderRepositoryInterface $orderRepository;+ private AttendeeRepositoryInterface $attendeeRepository;+ private ProductRepositoryInterface $productRepository;+ private MessageRepositoryInterface $messageRepository;+ private AccountRepositoryInterface $accountRepository;+ private HtmlPurifierService $purifier;+ private Repository $config;++ private SendMessageHandler $handler;++ protected function setUp(): void+ {+ parent::setUp();++ $this->orderRepository = m::mock(OrderRepositoryInterface::class);+ $this->attendeeRepository = m::mock(AttendeeRepositoryInterface::class);+ $this->productRepository = m::mock(ProductRepositoryInterface::class);+ $this->messageRepository = m::mock(MessageRepositoryInterface::class);+ $this->accountRepository = m::mock(AccountRepositoryInterface::class);+ $this->purifier = m::mock(HtmlPurifierService::class);+ $this->config = m::mock(Repository::class);++ $this->handler = new SendMessageHandler(+ $this->orderRepository,+ $this->attendeeRepository,+ $this->productRepository,+ $this->messageRepository,+ $this->accountRepository,+ $this->purifier,+ $this->config+ );+ }++ public function testThrowsIfAccountNotVerified(): void+ {+ $dto = new SendMessageDTO(+ account_id: 1,+ event_id: 1,+ subject: 'Subject',+ message: 'Message',+ type: MessageTypeEnum::INDIVIDUAL_ATTENDEES,+ is_test: false,+ send_copy_to_current_user: false,+ sent_by_user_id: 1,+ order_statuses: [],+ order_id: null,+ attendee_ids: [],+ product_ids: []+ );++ $account = m::mock(AccountDomainObject::class);+ $account->shouldReceive('getAccountVerifiedAt')->andReturn(null);++ $this->accountRepository->shouldReceive('findById')->with(1)->andReturn($account);++ $this->expectException(AccountNotVerifiedException::class);++ $this->handler->handle($dto);+ }++ public function testThrowsIfSaasModeEnabledAndNotManuallyVerified(): void+ {+ $dto = new SendMessageDTO(+ account_id: 1,+ event_id: 1,+ subject: 'Subject',+ message: 'Message',+ type: MessageTypeEnum::INDIVIDUAL_ATTENDEES,+ is_test: false,+ send_copy_to_current_user: false,+ sent_by_user_id: 1,+ order_statuses: [],+ order_id: null,+ attendee_ids: [],+ product_ids: []+ );++ $account = m::mock(AccountDomainObject::class);+ $account->shouldReceive('getAccountVerifiedAt')->andReturn(Carbon::now());+ $account->shouldReceive('getIsManuallyVerified')->andReturn(false);++ $this->accountRepository->shouldReceive('findById')->with(1)->andReturn($account);+ $this->config->shouldReceive('get')->with('app.saas_mode_enabled')->andReturn(true);+ $this->config->shouldReceive('get')->with('app.platform_support_email')->andReturn('[email protected]');++ $this->expectException(AccountNotVerifiedException::class);++ $this->handler->handle($dto);+ }++ public function testHandleCreatesMessageAndDispatchesJob(): void+ {+ $dto = new SendMessageDTO(+ account_id: 1,+ event_id: 101,+ subject: 'Hello',+ message: '<p>Test</p>',+ type: MessageTypeEnum::INDIVIDUAL_ATTENDEES,+ is_test: false,+ send_copy_to_current_user: false,+ sent_by_user_id: 99,+ order_statuses: [],+ order_id: 5,+ attendee_ids: [10],+ product_ids: [20],+ );++ $account = m::mock(AccountDomainObject::class);+ $account->shouldReceive('getAccountVerifiedAt')->andReturn(Carbon::now());+ $account->shouldReceive('getIsManuallyVerified')->andReturn(true);++ $this->accountRepository->shouldReceive('findById')->with(1)->andReturn($account);+ $this->config->shouldReceive('get')->with('app.saas_mode_enabled')->andReturn(false);++ $this->purifier->shouldReceive('purify')->with('<p>Test</p>')->andReturn('<p>Test</p>');++ $attendee = new AttendeeDomainObject();+ $attendee->setId(10);++ $product = new ProductDomainObject();+ $product->setId(20);++ $order = new OrderDomainObject();+ $order->setId(5);++ $this->attendeeRepository->shouldReceive('findWhereIn')->andReturn(collect([$attendee]));+ $this->productRepository->shouldReceive('findWhereIn')->andReturn(collect([$product]));+ $this->orderRepository->shouldReceive('findFirstWhere')->andReturn($order);++ $message = m::mock(MessageDomainObject::class);+ $message->shouldReceive('getId')->andReturn(1);+ $message->shouldReceive('getOrderId')->andReturn(5);+ $message->shouldReceive('getAttendeeIds')->andReturn([10]);+ $message->shouldReceive('getProductIds')->andReturn([20]);++ $this->messageRepository->shouldReceive('create')->andReturn($message);++ Bus::fake();++ $result = $this->handler->handle($dto);++ $this->assertSame($message, $result);++ Bus::assertDispatched(SendMessagesJob::class);+ }+}