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\SocialAccount\Platform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2026-05-03 21:38:17 +00:00
|
|
|
$result = createApiTestToken();
|
|
|
|
|
$this->user = $result['user'];
|
|
|
|
|
$this->workspace = $result['workspace'];
|
|
|
|
|
$this->plainToken = $result['plain_token'];
|
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
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('lists social accounts', function () {
|
|
|
|
|
SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::X,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->getJson(route('api.social-accounts.index'), [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonCount(2);
|
|
|
|
|
$response->assertJsonStructure([
|
|
|
|
|
'*' => ['id', 'platform', 'display_name', 'username', 'is_active', 'status'],
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not expose tokens in social accounts list', function () {
|
|
|
|
|
SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->getJson(route('api.social-accounts.index'), [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonMissing(['access_token']);
|
|
|
|
|
$response->assertJsonMissing(['refresh_token']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('toggles social account from active to inactive', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->putJson(route('api.social-accounts.toggle', $account), [], [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonPath('is_active', false);
|
|
|
|
|
expect($account->fresh()->is_active)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('toggles social account from inactive to active', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => false,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->putJson(route('api.social-accounts.toggle', $account), [], [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonPath('is_active', true);
|
|
|
|
|
expect($account->fresh()->is_active)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot toggle social account from another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->putJson(route('api.social-accounts.toggle', $account), [], [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('requires authentication to list social accounts', function () {
|
|
|
|
|
$response = $this->getJson(route('api.social-accounts.index'));
|
|
|
|
|
|
|
|
|
|
$response->assertUnauthorized();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('requires authentication to toggle social account', function () {
|
|
|
|
|
$account = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->putJson(route('api.social-accounts.toggle', $account));
|
|
|
|
|
|
|
|
|
|
$response->assertUnauthorized();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns empty list when no social accounts', function () {
|
|
|
|
|
$response = $this->getJson(route('api.social-accounts.index'), [
|
|
|
|
|
'Authorization' => "Bearer {$this->plainToken}",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonCount(0);
|
|
|
|
|
});
|