feat(notification): implement email notifications for user registration and purchase events

This commit is contained in:
2026-07-22 09:54:19 -03:00
parent 7e1ffbf417
commit 528772fc96
19 changed files with 450 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ use App\Domains\Attachable\Models\Attachment;
use App\Domains\Auth\Models\User;
use App\Domains\Catalog\Enums\CatalogItemType;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Notification\Events\TicketsAvailable;
use App\Domains\Purchase\Models\Purchase;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Exceptions\TicketGenerationException;
@@ -14,6 +15,8 @@ use App\Domains\Ticket\Services\TicketGeneratorService;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Str;
use Tests\TestCase;
@@ -32,6 +35,7 @@ class TicketGeneratorServiceTest extends TestCase
parent::setUp();
Carbon::setTestNow('2026-07-21 10:00:00');
Queue::fake();
$this->service = app(TicketGeneratorService::class);
$this->tenant = $this->createTenant();
$this->user = User::factory()->create();
@@ -128,6 +132,7 @@ class TicketGeneratorServiceTest extends TestCase
public function test_marking_a_purchase_as_paid_generates_its_tickets_once(): void
{
Event::fake([TicketsAvailable::class]);
$item = $this->createTicketableItem('paid-ticket');
$purchase = $this->createPurchase($item, 2);
$purchase->setRelation('items', new EloquentCollection);
@@ -136,10 +141,12 @@ class TicketGeneratorServiceTest extends TestCase
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
$this->assertDatabaseCount('tickets', 2);
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
$purchase->markAsPaid();
$this->assertDatabaseCount('tickets', 2);
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
}
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
@@ -157,6 +164,7 @@ class TicketGeneratorServiceTest extends TestCase
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
{
Event::fake([TicketsAvailable::class]);
$item = $this->createTicketableItem('regular-product');
$item->update(['has_tickets' => false]);
$purchase = $this->createPurchase($item->fresh(), 1);
@@ -165,6 +173,7 @@ class TicketGeneratorServiceTest extends TestCase
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
$this->assertDatabaseCount('tickets', 0);
Event::assertNotDispatched(TicketsAvailable::class);
}
public function test_paid_status_is_rolled_back_when_ticket_generation_fails(): void