2026-03-31 03:40:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\User\Setup;
|
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = User::factory()->create(['setup' => Setup::Completed]);
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->user->workspaces()->attach($this->workspace->id, ['role' => Role::Member->value]);
|
2026-03-31 03:40:18 +00:00
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
test('search returns matching posts by content', function () {
|
2026-03-31 03:40:18 +00:00
|
|
|
$account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$matchingPost = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id, 'content' => 'Hello marketing world']);
|
2026-03-31 03:40:18 +00:00
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $matchingPost->id,
|
|
|
|
|
'social_account_id' => $account->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$nonMatchingPost = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id, 'content' => 'Something else entirely']);
|
2026-03-31 03:40:18 +00:00
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $nonMatchingPost->id,
|
|
|
|
|
'social_account_id' => $account->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index', ['search' => 'marketing']));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 1)
|
|
|
|
|
->where('filters.search', 'marketing')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('search with no matches returns empty', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$post = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id, 'content' => 'Hello world']);
|
2026-03-31 03:40:18 +00:00
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $account->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index', ['search' => 'nonexistent']));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 0)
|
|
|
|
|
->where('filters.search', 'nonexistent')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('empty search returns all posts', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
Post::factory()->count(3)->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id])->each(function ($post) use ($account) {
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $account->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 3)
|
|
|
|
|
->where('filters.search', '')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('search is case insensitive', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$post = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id, 'content' => 'MARKETING CAMPAIGN']);
|
2026-03-31 03:40:18 +00:00
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $account->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index', ['search' => 'marketing']));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 1)
|
|
|
|
|
);
|
|
|
|
|
});
|