Adds a private workspace channel (WorkspaceChannel, authorised by
membership) so list views can subscribe once and receive events for
every post in the workspace, instead of opening N per-post channels.
New events:
- PostCreated (broadcast on workspace.{id})
- PostDeleted (broadcast on workspace.{id}; carries primitive ids so
it fires after \$post->delete())
- PostPlatformStatusUpdated now broadcasts on both post.{id} and
workspace.{id} so focused views and lists share the same trigger.
All broadcast events migrated to the namespaced 'entity.action'
convention from Laravel's broadcasting docs and switched from
ShouldBroadcastNow to ShouldBroadcast on a dedicated 'broadcasts'
queue (added to the supervisor-1 list in config/horizon.php) to keep
HTTP responses fast:
PostCreated -> post.created
PostDeleted -> post.deleted
PostPlatformStatusUpdated -> post.platform.status.updated
PostCommentCreated -> post.comment.created
NotificationCreated -> notification.created
PostCreationReady -> ai.creation.completed
Drops the SubscriptionCreated event — it was broadcast on
users.{owner_id} but had no listeners (frontend or backend) and the
billing/PostHog flow already handles plan-change tracking elsewhere.
PostPlatformStatusUpdated payload trimmed to {post_id} since every
consumer (Show, Edit, Index) does router.reload({ only: [...] }) and
ignored the rich shape.
29 lines
908 B
PHP
29 lines
908 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Events\PostDeleted;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Support\Str;
|
|
|
|
test('event broadcasts on the workspace channel only', function () {
|
|
$event = new PostDeleted(Str::uuid()->toString(), 'workspace-123');
|
|
$channels = $event->broadcastOn();
|
|
|
|
expect($channels)->toHaveCount(1);
|
|
expect($channels[0])->toBeInstanceOf(PrivateChannel::class);
|
|
expect($channels[0]->name)->toBe('private-workspace.workspace-123');
|
|
});
|
|
|
|
test('event broadcasts with the post id', function () {
|
|
$postId = (string) Str::uuid();
|
|
$event = new PostDeleted($postId, 'workspace-123');
|
|
|
|
expect($event->broadcastWith())->toBe(['post_id' => $postId]);
|
|
});
|
|
|
|
test('event broadcasts as a stable name', function () {
|
|
$event = new PostDeleted(Str::uuid()->toString(), 'workspace-123');
|
|
|
|
expect($event->broadcastAs())->toBe('post.deleted');
|
|
});
|