trypost/tests/Unit/Events/SubscriptionCreatedTest.php

32 lines
1 KiB
PHP
Raw Normal View History

2026-01-19 00:49:13 +00:00
<?php
declare(strict_types=1);
2026-01-19 00:49:13 +00:00
use App\Events\SubscriptionCreated;
use App\Models\Account;
2026-01-19 00:49:13 +00:00
use App\Models\User;
use Illuminate\Broadcasting\PrivateChannel;
test('event broadcasts on correct channel', function () {
$user = User::factory()->create();
$account = Account::factory()->create(['owner_id' => $user->id]);
$event = new SubscriptionCreated($account);
2026-01-19 00:49:13 +00:00
$channels = $event->broadcastOn();
expect($channels)->toHaveCount(1);
expect($channels[0])->toBeInstanceOf(PrivateChannel::class);
expect($channels[0]->name)->toBe('private-users.'.$user->id);
});
test('event broadcasts with correct data', function () {
$user = User::factory()->create();
$account = Account::factory()->create(['owner_id' => $user->id]);
$event = new SubscriptionCreated($account);
2026-01-19 00:49:13 +00:00
$data = $event->broadcastWith();
expect($data)->toHaveKey('status');
expect($data)->toHaveKey('message');
expect($data['status'])->toBe('success');
expect($data['message'])->toBe('Subscription created successfully');
});