diff --git a/src/Webhooks/Data/MessageFailedData.php b/src/Webhooks/Data/MessageFailedData.php index 163e60f..b908444 100644 --- a/src/Webhooks/Data/MessageFailedData.php +++ b/src/Webhooks/Data/MessageFailedData.php @@ -9,7 +9,7 @@ */ public function __construct( public string $messageId, - public string $recipient, + public ?string $recipient, public string $reason, public ServerResponse $response, public array $metadata, diff --git a/tests/Unit/Webhooks/WebhookEventTypeTest.php b/tests/Unit/Webhooks/WebhookEventTypeTest.php index ed156d5..3e67997 100644 --- a/tests/Unit/Webhooks/WebhookEventTypeTest.php +++ b/tests/Unit/Webhooks/WebhookEventTypeTest.php @@ -102,6 +102,29 @@ expect($event->data->subject)->toBe('Test Subject'); }); +it('creates a failed message event with an optional recipient', function (?string $recipient) { + $payload = [ + 'id' => 'test-id', + 'event' => 'message.failed', + 'timestamp' => '2024-01-01T00:00:00Z', + 'data' => [ + 'message_id' => 'msg-123', + 'recipient' => $recipient, + 'reason' => 'Expired', + 'response' => ['status_code' => 500], + 'metadata' => [], + ], + ]; + + $event = WebhookEventType::MessageFailed->toEvent($payload); + + expect($event)->toBeInstanceOf(MessageFailed::class) + ->and($event->data->recipient)->toBe($recipient); +})->with([ + 'recipient present' => 'test@example.com', + 'recipient absent' => null, +]); + it('creates correct event class for WebhookTest', function () { $payload = [ 'id' => 'test-id',