feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
|
|
|
|
use App\Mcp\Servers\TryPostServer;
|
|
|
|
|
use App\Mcp\Tools\Label\CreateLabelTool;
|
|
|
|
|
use App\Mcp\Tools\Label\DeleteLabelTool;
|
|
|
|
|
use App\Mcp\Tools\Label\ListLabelsTool;
|
|
|
|
|
use App\Mcp\Tools\Label\UpdateLabelTool;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use App\Models\WorkspaceLabel;
|
2026-05-04 00:34:20 +00:00
|
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = User::factory()->create();
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('list labels returns wrapped labels array with LabelResource shape', function () {
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
WorkspaceLabel::factory()->count(2)->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(ListLabelsTool::class, []);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->has('labels', 2, function (AssertableJson $label) {
|
|
|
|
|
$label->hasAll(['id', 'name', 'color', 'created_at', 'updated_at'])
|
|
|
|
|
->missing('workspace_id');
|
|
|
|
|
});
|
|
|
|
|
});
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('list labels only returns own workspace labels', function () {
|
|
|
|
|
WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(ListLabelsTool::class, []);
|
|
|
|
|
|
|
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->has('labels', 1)->etc();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create label returns LabelResource shape', function () {
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreateLabelTool::class, [
|
|
|
|
|
'name' => 'Important',
|
|
|
|
|
'color' => '#FF0000',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->where('name', 'Important')
|
|
|
|
|
->where('color', '#FF0000')
|
|
|
|
|
->missing('workspace_id')
|
|
|
|
|
->etc();
|
|
|
|
|
});
|
|
|
|
|
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
expect($this->workspace->labels()->count())->toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create label validates required fields', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreateLabelTool::class, []);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create label validates color format', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreateLabelTool::class, [
|
|
|
|
|
'name' => 'Test',
|
|
|
|
|
'color' => 'not-a-color',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('update label returns updated LabelResource', function () {
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdateLabelTool::class, [
|
|
|
|
|
'label_id' => $label->id,
|
|
|
|
|
'name' => 'Updated',
|
|
|
|
|
'color' => '#00FF00',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->where('name', 'Updated')
|
|
|
|
|
->where('color', '#00FF00')
|
|
|
|
|
->etc();
|
|
|
|
|
});
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot update label from another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdateLabelTool::class, [
|
|
|
|
|
'label_id' => $label->id,
|
|
|
|
|
'name' => 'Hacked',
|
|
|
|
|
'color' => '#000000',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors(['Label not found.']);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('delete label removes from db', function () {
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(DeleteLabelTool::class, ['label_id' => $label->id]);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(['deleted' => true]);
|
|
|
|
|
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
expect(WorkspaceLabel::find($label->id))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot delete label from another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(DeleteLabelTool::class, ['label_id' => $label->id]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors(['Label not found.']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update label validates required fields', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdateLabelTool::class, []);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('delete label validates label_id required', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(DeleteLabelTool::class, []);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|