<?php

namespace Tests\Feature\Notification;

use App\Domains\Notification\Listeners\SendPurchaseConfirmedEmail;
use App\Domains\Notification\Services\NotificationMailService;
use App\Domains\Purchase\Events\PurchasePaid;
use Mockery;
use Tests\TestCase;

class QueuedNotificationListenerTest extends TestCase
{
    public function test_purchase_confirmed_email_delegates_with_the_purchase_id(): void
    {
        $mailService = Mockery::mock(NotificationMailService::class);
        $mailService->shouldReceive('sendPurchaseConfirmed')
            ->once()
            ->with(123);
        $this->app->instance(NotificationMailService::class, $mailService);

        (new SendPurchaseConfirmedEmail)->handle(new PurchasePaid(123));
    }

    public function test_purchase_paid_event_only_serializes_the_purchase_id(): void
    {
        $purchasePaid = unserialize(serialize(new PurchasePaid(123)));

        $this->assertSame(123, $purchasePaid->purchaseId);
    }
}
