trypost/tests/Unit/Broadcasting/PostChannelTest.php
Paulo Castellano 74c6442728 refactor: code review fixes — policies, enums, data_get, tests
- Refactor WorkspacePolicy to use pivot role instead of workspace.user_id
- Add manageBilling policy (owner only) to BillingController
- Fix ApiKeyController authorization (view → manageTeam for store/destroy)
- Fix WorkspaceInviteController using workspace.user_id for owner checks
- Fix WorkspaceController settings is_owner using workspace.user_id
- Create PostAction enum for UpdatePost/PostController action strings
- Create ApiToken\Status enum
- Add User::SUBSCRIPTION_NAME constant, replace all hardcoded 'default'
- Convert wantsEmailFor to accept NotificationType enum
- Convert all $data[] to data_get() across publishers, controllers, jobs
- Fix SocialLoginController callback missing try/catch
- Fix SocialController::toggleActive missing workspace null check
- Fix UpdatePost NPE on meta merge when postPlatform not found
- Remove HTML5 required attributes from form inputs
- Convert function declarations to arrow functions in Vue components
- Replace hardcoded URLs with Wayfinder route helpers
- Replace new Date() with dayjs
- Add 16 new test files covering policies, authorization, publishing
2026-03-31 00:40:18 -03:00

34 lines
1 KiB
PHP

<?php
declare(strict_types=1);
use App\Broadcasting\PostChannel;
use App\Enums\UserWorkspace\Role;
use App\Models\Post;
use App\Models\User;
use App\Models\Workspace;
test('post channel allows workspace member to join', function () {
$user = User::factory()->create();
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
$workspace->members()->attach($user->id, ['role' => Role::Owner->value]);
$post = Post::factory()->create(['workspace_id' => $workspace->id]);
$channel = new PostChannel;
$result = $channel->join($user, $post);
expect($result)->toBeTrue();
});
test('post channel denies non-member from joining', function () {
$owner = User::factory()->create();
$workspace = Workspace::factory()->create(['user_id' => $owner->id]);
$post = Post::factory()->create(['workspace_id' => $workspace->id]);
$otherUser = User::factory()->create();
$channel = new PostChannel;
$result = $channel->join($otherUser, $post);
expect($result)->toBeFalse();
});