Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Actions/Media/ListWorkspaceAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function query(Workspace $workspace, ?string $search = null, ?stri
->where('mediable_type', Relation::getMorphAlias(Workspace::class))
->where('mediable_id', $workspace->id)
->where('collection', 'assets')
->when(filled($search), fn (Builder $query) => $query->where('original_filename', 'ilike', '%'.trim($search).'%'))
->when(filled($search), fn (Builder $query) => $query->whereLike('original_filename', '%'.trim($search).'%'))
->when(filled($type), fn (Builder $query) => $query->where('type', $type))
->latest()
->orderByDesc('id');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/App/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function search(Request $request): AnonymousResourceCollection
$type = $request->input('type');

$assets = $workspace->getMedia('assets')
->when($term !== '', fn ($query) => $query->where('original_filename', 'ilike', '%'.$term.'%'))
->when($term !== '', fn ($query) => $query->whereLike('original_filename', '%'.$term.'%'))
->when(in_array($type, ['image', 'video'], true), fn ($query) => $query->where('type', $type))
->latest()
->paginate(config('app.pagination.default'));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/App/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function index(Request $request, ?string $status = null): Response|Redire
}

if ($search = $request->input('search')) {
$query->where('content', 'ilike', "%{$search}%");
$query->whereLike('content', "%{$search}%");
}

$labelIds = $request->collect('labels')
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/App/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function searchMembers(Request $request): AnonymousResourceCollection

$members = $workspace->members()
->where('users.id', '!=', $request->user()->id)
->when($term !== '', fn ($query) => $query->where('users.name', 'ilike', '%'.$term.'%'))
->when($term !== '', fn ($query) => $query->whereLike('users.name', '%'.$term.'%'))
->orderBy('users.name')
->limit(50)
->get(['users.id', 'users.name', 'users.email']);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/App/WorkspaceLabelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function index(Request $request): Response|RedirectResponse
$this->authorize('createPost', $workspace);

$labels = $workspace->labels()
->when($request->input('search'), fn ($query, $search) => $query->where('name', 'ilike', "%{$search}%"))
->when($request->input('search'), fn ($query, $search) => $query->whereLike('name', "%{$search}%"))
->latest()
->paginate(config('app.pagination.default'));

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/App/WorkspaceSignatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function index(Request $request): Response|RedirectResponse
$this->authorize('createPost', $workspace);

$signatures = $workspace->signatures()
->when($request->input('search'), fn ($query, $search) => $query->where('name', 'ilike', "%{$search}%"))
->when($request->input('search'), fn ($query, $search) => $query->whereLike('name', "%{$search}%"))
->latest()
->paginate(config('app.pagination.default'));

Expand Down
2 changes: 1 addition & 1 deletion app/Mcp/Tools/Post/ListPostsTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function handle(Request $request): ResponseFactory
};

if ($search = data_get($validated, 'search')) {
$query->where('content', 'ilike', '%'.$search.'%');
$query->whereLike('content', '%'.$search.'%');
}

$posts = $query->latest('scheduled_at')
Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/Api/AssetApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
->assertJsonPath('data.0.original_filename', 'campaign-hero.jpg');
});

test('filters assets by filename search case-insensitively', function () {
Media::factory()->assets()->create([
'mediable_type' => (new Workspace)->getMorphClass(),
'mediable_id' => $this->workspace->id,
'original_filename' => 'CAMPAIGN-Hero.jpg',
]);
Media::factory()->assets()->create([
'mediable_type' => (new Workspace)->getMorphClass(),
'mediable_id' => $this->workspace->id,
'original_filename' => 'office-shot.jpg',
]);

$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])
->getJson(route('api.assets.index', ['search' => 'campaign-hero']))
->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.original_filename', 'CAMPAIGN-Hero.jpg');
});

test('paginates assets with the application page size', function () {
$perPage = (int) config('app.pagination.default');

Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/AssetControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
$response->assertJsonPath('data.0.id', $matching->id);
});

test('assets search matches filenames case-insensitively', function () {
$matching = $this->workspace->addMedia(UploadedFile::fake()->image('VACATION-Beach.jpg'), 'assets');
$this->workspace->addMedia(UploadedFile::fake()->image('office-shot.jpg'), 'assets');

$response = $this->actingAs($this->user)
->getJson(route('app.assets.search', ['search' => 'vacation']));

$response->assertOk();
$response->assertJsonCount(1, 'data');
$response->assertJsonPath('data.0.id', $matching->id);
});

test('assets search filters by type', function () {
$this->workspace->addMedia(UploadedFile::fake()->image('photo.jpg'), 'assets');
$this->workspace->addMedia(UploadedFile::fake()->create('clip.mp4', 100, 'video/mp4'), 'assets');
Expand Down
44 changes: 44 additions & 0 deletions tests/Feature/Mcp/PostToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@
});
});

test('list posts filters by content search', function () {
$matching = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'content' => 'Hello marketing world',
]);
Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'content' => 'Something else entirely',
]);

$response = TryPostServer::actingAs($this->user)
->tool(ListPostsTool::class, ['search' => 'marketing']);

$response->assertOk()
->assertStructuredContent(function (AssertableJson $json) use ($matching) {
$json->has('posts', 1, function (AssertableJson $post) use ($matching) {
$post->where('id', $matching->id)->etc();
})->etc();
});
});

test('list posts search is case insensitive', function () {
Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'content' => 'MARKETING CAMPAIGN',
]);
Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'content' => 'Something else entirely',
]);

$response = TryPostServer::actingAs($this->user)
->tool(ListPostsTool::class, ['search' => 'marketing']);

$response->assertOk()
->assertStructuredContent(function (AssertableJson $json) {
$json->has('posts', 1)->etc();
});
});

test('get post returns PostResource shape', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/WorkspaceLabelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@
);
});

test('labels index search is case insensitive', function () {
WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id, 'name' => 'IMPORTANT']);
WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id, 'name' => 'Urgent']);

$response = $this->actingAs($this->user)->get(route('app.labels.index', ['search' => 'important']));

$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('labels.data', 1)
->where('filters.search', 'important')
);
});

test('labels index returns all when no search query', function () {
WorkspaceLabel::factory()->count(3)->create(['workspace_id' => $this->workspace->id]);

Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/WorkspaceSignatureControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@
);
});

test('signatures index search is case insensitive', function () {
WorkspaceSignature::factory()->create(['workspace_id' => $this->workspace->id, 'name' => 'MARKETING']);
WorkspaceSignature::factory()->create(['workspace_id' => $this->workspace->id, 'name' => 'Travel']);

$response = $this->actingAs($this->user)->get(route('app.signatures.index', ['search' => 'marketing']));

$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('signatures.data', 1)
->where('filters.search', 'marketing')
);
});

test('signatures index returns all when no search query', function () {
WorkspaceSignature::factory()->count(3)->create(['workspace_id' => $this->workspace->id]);

Expand Down