['admin', 'other-admin']]); }); it('keeps bulletin board text unchanged and preserves the guild when scheduling', function (string $body): void { $user = User::factory()->create(['handle' => 'admin']); $guild = Guild::factory()->create(['handle' => 'rust']); $payload = ['body' => $body, 'guild_handle' => 'rust']; $preview = $this->actingAs($user)->postJson(route('commit-preview.store'), $payload)->assertOk(); $this->post(route('commit.store'), $payload)->assertSessionHasNoErrors()->assertInertiaFlash('committed.guild_handle', 'rust'); expect($user->commits()->sole())->body->toBe($body)->guild_id->toBe($guild->id); expect($guild->commits()->sole()->guild->id)->toBe($guild->id); $preview->assertJsonPath('segments', $user->commits()->sole()->toArray()['body_segments']); $this->post(route('scheduled-commit.store'), [...$payload, 'scheduled_at' => now()->addHour()->toIso8601String()])->assertSessionHasNoErrors(); $scheduled = ScheduledCommit::query()->sole(); expect($scheduled)->body->toBe($body)->guild_id->toBe($guild->id); resolve(UpdateScheduledCommitSubmittedAt::class)->handle($scheduled->id, early: true); expect($scheduled->fresh()->commit)->body->toBe($body)->guild_id->toBe($guild->id); })->with([ 'full budget' => [str_repeat('x', 4000)], 'already present' => ['Learning #RUST!'], 'only inside code or a link' => ['`#rust` https://example.com/#rust'], ]); it('keeps board posts on their guild counts them but leaves them off profile and general logs', function (): void { $author = User::factory()->create(['handle' => 'admin']); $viewer = User::factory()->create(['handle' => 'other-admin']); $guild = Guild::factory()->create(['handle' => 'rust']); Guild::factory()->create(['handle' => 'jobs']); $regular = Commit::factory()->for($author)->create(['body' => 'Learning #rust']); $this->actingAs($author)->post(route('commit.store'), ['body' => 'A board post with #jobs', 'guild_handle' => 'rust'])->assertSessionHasNoErrors(); $board = $author->commits()->whereNotNull('guild_id')->sole(); $author->forceFill(['pinned_commit_id' => $board->id])->save(); $this->get(route('guild.show', 'rust'))->assertInertia(fn ($page) => $page->has('commits', 2)->where('commits.0.id', $board->id)); $this->get(route('guild.show', 'jobs'))->assertInertia(fn ($page) => $page->has('commits', 0)); $this->get(route('user.show', $author))->assertInertia(fn ($page) => $page ->where('user.commits_count', 2)->where('pinnedCommit', null)->has('commits.data', 1)->where('commits.data.0.id', $regular->id)); $this->get(route('log.show', 'following'))->assertInertia(fn ($page) => $page->has('commits.data', 1)); $viewer->following()->attach($author); $this->actingAs($viewer)->get(route('log.show', 'following'))->assertInertia(fn ($page) => $page->has('commits.data', 1)); $this->put(route('guild-membership.update', $guild), ['joined' => true])->assertRedirect(); $this->get(route('log.show', 'following'))->assertInertia(fn ($page) => $page ->has('commits.data', 2)->where('commits.data.0.id', $board->id)->where('commits.data.0.joined_guild', 'rust')); foreach (['latest', 'trending'] as $log) { $this->get(route('log.show', $log))->assertInertia(fn ($page) => $page->has('commits.data', 1)->where('commits.data.0.id', $regular->id)); } $this->put(route('guild-mute.update', $guild), ['muted' => true])->assertRedirect(); $this->get(route('log.show', 'following'))->assertInertia(fn ($page) => $page->has('commits.data', 0)); $this->get(route('commit.show', [$author, $board]))->assertOk(); }); it('does not let bulletin board context bypass validation', function (string $route, array $payload, bool $admin, string $field): void { Guild::factory()->create(['handle' => 'rust']); $this->actingAs(User::factory()->create(['handle' => $admin ? 'admin' : 'member'])) ->postJson(route($route), ['body' => 'Hello', 'guild_handle' => 'rust', 'scheduled_at' => now()->addHour()->toIso8601String(), ...$payload]) ->assertUnprocessable()->assertJsonValidationErrors($field); $this->assertDatabaseCount('commits', 0); $this->assertDatabaseCount('scheduled_commits', 0); })->with(['commit.store', 'commit-preview.store', 'scheduled-commit.store'])->with([ 'over budget' => [['body' => str_repeat('x', 4001)], true, 'body'], 'empty text' => [['body' => ''], true, 'body'], 'missing guild' => [['guild_handle' => 'missing'], true, 'guild_handle'], 'invalid context' => [['guild_handle' => ['rust']], true, 'guild_handle'], 'not available' => [[], false, 'guild_handle'], ]); it('creates a public guild and gives only its creator moderation controls', function (): void { $admin = User::factory()->create(['handle' => 'admin']); Event::fake([UsersUpdated::class]); $this->actingAs($admin)->post(route('guild.store'), [ 'handle' => ' JoBs ', 'name' => 'Jo bs', 'description' => 'Hiring and freelance work.', 'emoji' => '💼', 'user_id' => User::factory()->create()->id, ])->assertRedirectToRoute('guild.show', 'jobs'); $guild = Guild::query()->sole(); expect($guild->handle)->toBe('jobs')->and($guild->user_id)->toBe($admin->id); $this->assertDatabaseHas('guild_preferences', ['guild_id' => $guild->id, 'user_id' => $admin->id, 'joined_at' => now()]); Event::assertDispatched(UsersUpdated::class, fn (UsersUpdated $event): bool => $event->update === UserUpdate::Guilds && in_array($admin->id, $event->userIds, true)); $this->get(route('guild.show', 'jobs'))->assertOk()->assertInertia(fn ($page) => $page ->component('guild/show')->where('canModerate', true)->where('guild.name', 'Jo bs') ->where('guild.icon_url', null)->missing('guild.user_id')->missing('guild.icon_path')->missing('guilds')); $this->actingAs(User::factory()->create(['handle' => 'other-admin'])) ->get(route('guild.show', 'jobs'))->assertOk()->assertInertia(fn ($page) => $page->where('canModerate', false)); }); it('hides guild data and every guild endpoint from ordinary members', function (): void { $user = User::factory()->create(); $guild = Guild::factory()->create(['user_id' => $user->id]); $this->actingAs($user)->get('/search?q=%23jobs')->assertOk()->assertInertia(fn ($page) => $page->where('guildsEnabled', false)->missing('guilds')); $this->get(route('guild.show', $guild->handle))->assertNotFound(); $this->get(route('guild-icon.show', $guild->handle))->assertNotFound(); $this->post(route('guild.store'), [])->assertNotFound(); $this->put(route('guild.update', $guild->handle), [])->assertNotFound(); $this->assertDatabaseCount('guilds', 1); }); it('creates a guild from its display name without an existing hashtag', function (string $name, string $handle): void { $admin = User::factory()->create(['handle' => 'admin']); $this->actingAs($admin)->post(route('guild.store'), [ 'name' => $name, 'description' => 'A new public group.', 'emoji' => '💻', ])->assertRedirectToRoute('guild.show', $handle); $this->assertDatabaseHas('guilds', ['handle' => $handle, 'name' => $name, 'user_id' => $admin->id]); $this->get(route('guild.show', $handle))->assertInertia(fn ($page) => $page->has('commits', 0)); $this->postJson(route('guild.store'), [ 'name' => $name, 'description' => 'Another group.', 'emoji' => '💻', ])->assertUnprocessable()->assertJsonValidationErrors('handle'); $this->assertDatabaseCount('guilds', 1); })->with([ ['Laravel 4ever', 'laravel4ever'], ['/dev/null', 'devnull'], ['☕ CAFÉ_Dev 2!', 'café_dev2'], [str_repeat('a', 60), str_repeat('a', 60)], ]); it('rejects names that cannot produce a hashtag without an explicit handle', function (mixed $name): void { $this->actingAs(User::factory()->create(['handle' => 'admin']))->postJson(route('guild.store'), [ 'name' => $name, 'description' => 'A public group.', 'emoji' => '💻', ])->assertUnprocessable()->assertJsonValidationErrors('handle'); $this->assertDatabaseCount('guilds', 0); })->with([null, [['invalid']], '!!!', '123 Developers']); it('requires sign in and exposes no guild data to guests', function (): void { $guild = Guild::factory()->create(); $this->get('/')->assertInertia(fn ($page) => $page->where('guildsEnabled', false)->missing('guilds')); $this->get(route('guild.show', $guild->handle))->assertRedirectToRoute('home'); $this->getJson(route('guild-icon.show', $guild->handle))->assertUnauthorized(); $this->postJson(route('guild.store'), [])->assertUnauthorized(); $this->putJson(route('guild.update', $guild->handle), [])->assertUnauthorized(); }); it('switches off the entire preview even for its admin creator', function (): void { $admin = User::factory()->create(['handle' => 'admin']); $guild = Guild::factory()->create(['user_id' => $admin->id]); $this->actingAs($admin)->put(route('feature.update', Feature::Guilds), ['enabled' => false])->assertRedirect(); $this->actingAs($admin)->get('/search?q=%23jobs')->assertInertia(fn ($page) => $page->where('guildsEnabled', false)->missing('guilds')); $this->get(route('guild.show', $guild->handle))->assertNotFound(); $this->get(route('guild-icon.show', $guild->handle))->assertNotFound(); $this->post(route('guild.store'), [])->assertNotFound(); $this->put(route('guild.update', $guild->handle), [])->assertNotFound(); }); it('rejects invalid guild details without creating a guild', function (array $payload, string $field): void { $this->actingAs(User::factory()->create(['handle' => 'admin']))->postJson(route('guild.store'), [ 'handle' => 'jobs', 'name' => 'Jobs', 'description' => 'Hiring.', 'emoji' => '💼', ...$payload, ])->assertUnprocessable()->assertJsonValidationErrors($field); $this->assertDatabaseCount('guilds', 0); })->with([ 'missing handle' => [['handle' => null], 'handle'], 'hashtag prefix' => [['handle' => '#jobs'], 'handle'], 'path' => [['handle' => '../jobs'], 'handle'], 'leading number' => [['handle' => '123jobs'], 'handle'], 'long handle' => [['handle' => str_repeat('a', 61)], 'handle'], 'empty name' => [['name' => ''], 'name'], 'long name' => [['name' => str_repeat('a', 61)], 'name'], 'unrelated name' => [['name' => 'Job Board'], 'name'], 'punctuation does not hide extra words' => [['name' => 'Job-s Board'], 'name'], 'numbers remain significant' => [['name' => 'Jobs 2!'], 'name'], 'accents remain significant' => [['name' => 'Jóbs!'], 'name'], 'underscores remain significant' => [['handle' => 'jobs_dev', 'name' => 'Jobs/Dev'], 'name'], 'empty description' => [['description' => ''], 'description'], 'long description' => [['description' => str_repeat('a', 501)], 'description'], 'not an emoji' => [['emoji' => '