Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
feat: social account toggle action, API, MCP + full test coverage
Paulo Castellanoc020419db112
diff --git a/app/Actions/SocialAccount/ToggleSocialAccount.php b/app/Actions/SocialAccount/ToggleSocialAccount.phpnew file mode 100644index 000000000..510870513--- /dev/null+++ b/app/Actions/SocialAccount/ToggleSocialAccount.php@@ -0,0 +1,17 @@+<?php++declare(strict_types=1);++namespace App\Actions\SocialAccount;++use App\Models\SocialAccount;++class ToggleSocialAccount+{+ public static function execute(SocialAccount $account): SocialAccount+ {+ $account->update(['is_active' => ! $account->is_active]);++ return $account;+ }+}diff --git a/app/Http/Controllers/Api/SocialAccountController.php b/app/Http/Controllers/Api/SocialAccountController.phpnew file mode 100644index 000000000..cd01ee0c8--- /dev/null+++ b/app/Http/Controllers/Api/SocialAccountController.php@@ -0,0 +1,37 @@+<?php++declare(strict_types=1);++namespace App\Http\Controllers\Api;++use App\Actions\SocialAccount\ToggleSocialAccount;+use App\Http\Resources\Api\SocialAccountResource;+use App\Models\SocialAccount;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+use Illuminate\Http\Resources\Json\AnonymousResourceCollection;+use Symfony\Component\HttpFoundation\Response;++class SocialAccountController extends Controller+{+ public function index(Request $request): AnonymousResourceCollection+ {+ $accounts = $request->workspace->socialAccounts()->orderBy('platform')->get();++ return SocialAccountResource::collection($accounts);+ }++ public function toggle(Request $request, SocialAccount $account): SocialAccountResource|JsonResponse+ {+ if ($account->workspace_id !== $request->workspace->id) {+ return response()->json(+ ['message' => 'Account not found.'],+ Response::HTTP_NOT_FOUND,+ );+ }++ ToggleSocialAccount::execute($account);++ return new SocialAccountResource($account);+ }+}diff --git a/app/Http/Controllers/Auth/MastodonController.php b/app/Http/Controllers/Auth/MastodonController.phpindex fee03ab92..c0bbbce60 100644--- a/app/Http/Controllers/Auth/MastodonController.php+++ b/app/Http/Controllers/Auth/MastodonController.php@@ -191,13 +191,13 @@ class MastodonController extends SocialControllerreturn $this->popupCallback(false, 'Mastodon is already connected.', $this->platform->value);}- $avatarPath = isset($profile['avatar']) ? uploadFromUrl($profile['avatar']) : null;+ $avatarPath = data_get($profile, 'avatar') ? uploadFromUrl(data_get($profile, 'avatar')) : null;$accountData = ['platform' => $this->platform->value,- 'platform_user_id' => $profile['id'],- 'username' => $profile['acct'],- 'display_name' => $profile['display_name'] ?: $profile['username'],+ 'platform_user_id' => data_get($profile, 'id'),+ 'username' => data_get($profile, 'acct'),+ 'display_name' => data_get($profile, 'display_name') ?: data_get($profile, 'username'),'avatar_url' => $avatarPath,'access_token' => $accessToken,'refresh_token' => null, // Mastodon tokens don't expirediff --git a/app/Http/Controllers/Auth/SocialController.php b/app/Http/Controllers/Auth/SocialController.phpindex 404698769..3d7e6fea9 100644--- a/app/Http/Controllers/Auth/SocialController.php+++ b/app/Http/Controllers/Auth/SocialController.php@@ -4,6 +4,7 @@ declare(strict_types=1);namespace App\Http\Controllers\Auth;+use App\Actions\SocialAccount\ToggleSocialAccount;use App\Enums\SocialAccount\Platform as SocialPlatform;use App\Enums\SocialAccount\Status;use App\Http\Controllers\Controller;@@ -95,7 +96,7 @@ class SocialController extends Controllerabort(403);}- $account->update(['is_active' => ! $account->is_active]);+ ToggleSocialAccount::execute($account);$status = $account->is_active ? 'activated' : 'deactivated';session()->flash('flash.banner', __("accounts.flash.{$status}"));diff --git a/app/Http/Controllers/Auth/ThreadsController.php b/app/Http/Controllers/Auth/ThreadsController.phpindex fd35b8150..ec23a96dd 100644--- a/app/Http/Controllers/Auth/ThreadsController.php+++ b/app/Http/Controllers/Auth/ThreadsController.php@@ -153,14 +153,14 @@ class ThreadsController extends SocialController}$profile = $profileResponse->json();- $avatarPath = uploadFromUrl($profile['threads_profile_picture_url'] ?? null);+ $avatarPath = uploadFromUrl(data_get($profile, 'threads_profile_picture_url', null));if ($existingAccount) {// Reconnect existing account$existingAccount->update([- 'platform_user_id' => $profile['id'],- 'username' => $profile['username'],- 'display_name' => $profile['name'] ?? $profile['username'],+ 'platform_user_id' => data_get($profile, 'id'),+ 'username' => data_get($profile, 'username'),+ 'display_name' => data_get($profile, 'name', data_get($profile, 'username')),'avatar_url' => $avatarPath,'access_token' => $longLivedToken,'refresh_token' => null,@@ -177,9 +177,9 @@ class ThreadsController extends SocialController// Create new account$workspace->socialAccounts()->create(['platform' => $this->platform->value,- 'platform_user_id' => $profile['id'],- 'username' => $profile['username'],- 'display_name' => $profile['name'] ?? $profile['username'],+ 'platform_user_id' => data_get($profile, 'id'),+ 'username' => data_get($profile, 'username'),+ 'display_name' => data_get($profile, 'name', data_get($profile, 'username')),'avatar_url' => $avatarPath,'access_token' => $longLivedToken,'refresh_token' => null,diff --git a/app/Http/Controllers/Auth/YouTubeController.php b/app/Http/Controllers/Auth/YouTubeController.phpindex b6925a1ee..6ec81df4b 100644--- a/app/Http/Controllers/Auth/YouTubeController.php+++ b/app/Http/Controllers/Auth/YouTubeController.php@@ -187,7 +187,7 @@ class YouTubeController extends SocialController}// Fetch YouTube channels- $channels = $this->fetchChannels($oauthData['access_token']);+ $channels = $this->fetchChannels(data_get($oauthData, 'access_token'));if (empty($channels)) {$redirectRoute = $this->getRedirectRoute();@@ -226,15 +226,15 @@ class YouTubeController extends SocialController}try {- $channels = $this->fetchChannels($oauthData['access_token']);+ $channels = $this->fetchChannels(data_get($oauthData, 'access_token'));$selectedChannel = collect($channels)->firstWhere('id', $request->channel_id);if (! $selectedChannel) {return $this->popupCallback(false, 'Channel not found.', $this->platform->value);}- $avatarPath = uploadFromUrl($selectedChannel['thumbnail']);- $reconnectId = $oauthData['reconnect_id'] ?? null;+ $avatarPath = uploadFromUrl(data_get($selectedChannel, 'thumbnail'));+ $reconnectId = data_get($oauthData, 'reconnect_id', null);if ($reconnectId) {// Reconnect existing account@@ -242,17 +242,17 @@ class YouTubeController extends SocialControllerif ($existingAccount) {$existingAccount->update([- 'platform_user_id' => $selectedChannel['id'],- 'username' => ltrim($selectedChannel['custom_url'] ?? $selectedChannel['id'], '@'),- 'display_name' => $selectedChannel['title'],+ 'platform_user_id' => data_get($selectedChannel, 'id'),+ 'username' => ltrim(data_get($selectedChannel, 'custom_url', data_get($selectedChannel, 'id')), '@'),+ 'display_name' => data_get($selectedChannel, 'title'),'avatar_url' => $avatarPath,- 'access_token' => $oauthData['access_token'],- 'refresh_token' => $oauthData['refresh_token'],- 'token_expires_at' => $oauthData['expires_in'] ? now()->addSeconds($oauthData['expires_in']) : null,+ 'access_token' => data_get($oauthData, 'access_token'),+ 'refresh_token' => data_get($oauthData, 'refresh_token'),+ 'token_expires_at' => data_get($oauthData, 'expires_in') ? now()->addSeconds(data_get($oauthData, 'expires_in')) : null,'scopes' => $this->scopes,'meta' => [- 'channel_id' => $selectedChannel['id'],- 'google_user_id' => $oauthData['user_id'],+ 'channel_id' => data_get($selectedChannel, 'id'),+ 'google_user_id' => data_get($oauthData, 'user_id'),],]);$existingAccount->markAsConnected();@@ -266,18 +266,18 @@ class YouTubeController extends SocialController// Create new account$workspace->socialAccounts()->create(['platform' => $this->platform->value,- 'platform_user_id' => $selectedChannel['id'],- 'username' => ltrim($selectedChannel['custom_url'] ?? $selectedChannel['id'], '@'),- 'display_name' => $selectedChannel['title'],+ 'platform_user_id' => data_get($selectedChannel, 'id'),+ 'username' => ltrim(data_get($selectedChannel, 'custom_url', data_get($selectedChannel, 'id')), '@'),+ 'display_name' => data_get($selectedChannel, 'title'),'avatar_url' => $avatarPath,- 'access_token' => $oauthData['access_token'],- 'refresh_token' => $oauthData['refresh_token'],- 'token_expires_at' => $oauthData['expires_in'] ? now()->addSeconds($oauthData['expires_in']) : null,+ 'access_token' => data_get($oauthData, 'access_token'),+ 'refresh_token' => data_get($oauthData, 'refresh_token'),+ 'token_expires_at' => data_get($oauthData, 'expires_in') ? now()->addSeconds(data_get($oauthData, 'expires_in')) : null,'scopes' => $this->scopes,'status' => Status::Connected,'meta' => [- 'channel_id' => $selectedChannel['id'],- 'google_user_id' => $oauthData['user_id'],+ 'channel_id' => data_get($selectedChannel, 'id'),+ 'google_user_id' => data_get($oauthData, 'user_id'),],]);diff --git a/app/Http/Resources/Api/SocialAccountResource.php b/app/Http/Resources/Api/SocialAccountResource.phpindex 7cb7b547a..c3d32dcba 100644--- a/app/Http/Resources/Api/SocialAccountResource.php+++ b/app/Http/Resources/Api/SocialAccountResource.php@@ -19,6 +19,8 @@ class SocialAccountResource extends JsonResource'platform' => $this->platform,'display_name' => $this->display_name,'username' => $this->username,+ 'is_active' => $this->is_active,+ 'status' => $this->status,];}}diff --git a/app/Mcp/Servers/TryPostServer.php b/app/Mcp/Servers/TryPostServer.phpindex f0d2279c2..4e11b6bf1 100644--- a/app/Mcp/Servers/TryPostServer.php+++ b/app/Mcp/Servers/TryPostServer.php@@ -19,6 +19,8 @@ use App\Mcp\Tools\Post\CreatePostTool;use App\Mcp\Tools\Post\DeletePostTool;use App\Mcp\Tools\Post\GetPostTool;use App\Mcp\Tools\Post\ListPostsTool;+use App\Mcp\Tools\SocialAccount\ListSocialAccountsTool;+use App\Mcp\Tools\SocialAccount\ToggleSocialAccountTool;use App\Mcp\Tools\Workspace\GetWorkspaceTool;use Laravel\Mcp\Server;use Laravel\Mcp\Server\Attributes\Instructions;@@ -51,6 +53,10 @@ class TryPostServer extends ServerUpdateLabelTool::class,DeleteLabelTool::class,+ // Social Accounts+ ListSocialAccountsTool::class,+ ToggleSocialAccountTool::class,+// WorkspaceGetWorkspaceTool::class,diff --git a/app/Mcp/Tools/ApiKey/DeleteApiKeyTool.php b/app/Mcp/Tools/ApiKey/DeleteApiKeyTool.phpindex 58f4d062f..7b4ac1555 100644--- a/app/Mcp/Tools/ApiKey/DeleteApiKeyTool.php+++ b/app/Mcp/Tools/ApiKey/DeleteApiKeyTool.php@@ -16,10 +16,14 @@ use Laravel\Mcp\Server\Tool;#[Description('Delete an API key by ID.')]class DeleteApiKeyTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$apiToken = ApiToken::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($request->validated(), 'api_key_id'));+ ->find(data_get($request->validate(['api_key_id' => ['required', 'string']]), 'api_key_id'));++ if (! $apiToken) {+ return Response::error('API key not found.');+ }DeleteApiKey::execute($apiToken);diff --git a/app/Mcp/Tools/Hashtag/DeleteHashtagTool.php b/app/Mcp/Tools/Hashtag/DeleteHashtagTool.phpindex 5df1d979f..215f193f5 100644--- a/app/Mcp/Tools/Hashtag/DeleteHashtagTool.php+++ b/app/Mcp/Tools/Hashtag/DeleteHashtagTool.php@@ -16,10 +16,14 @@ use Laravel\Mcp\Server\Tool;#[Description('Delete a hashtag group by ID.')]class DeleteHashtagTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$hashtag = WorkspaceHashtag::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($request->validated(), 'hashtag_id'));+ ->find(data_get($request->validate(['hashtag_id' => ['required', 'string']]), 'hashtag_id'));++ if (! $hashtag) {+ return Response::error('Hashtag not found.');+ }DeleteHashtag::execute($hashtag);diff --git a/app/Mcp/Tools/Hashtag/UpdateHashtagTool.php b/app/Mcp/Tools/Hashtag/UpdateHashtagTool.phpindex 0bbc1aa20..d49ec1e28 100644--- a/app/Mcp/Tools/Hashtag/UpdateHashtagTool.php+++ b/app/Mcp/Tools/Hashtag/UpdateHashtagTool.php@@ -16,7 +16,7 @@ use Laravel\Mcp\Server\Tool;#[Description('Update a hashtag group name or hashtags.')]class UpdateHashtagTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$validated = $request->validate(['hashtag_id' => ['required', 'string'],@@ -25,7 +25,11 @@ class UpdateHashtagTool extends Tool]);$hashtag = WorkspaceHashtag::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($validated, 'hashtag_id'));+ ->find(data_get($validated, 'hashtag_id'));++ if (! $hashtag) {+ return Response::error('Hashtag not found.');+ }$hashtag = UpdateHashtag::execute($hashtag, $validated);diff --git a/app/Mcp/Tools/Label/DeleteLabelTool.php b/app/Mcp/Tools/Label/DeleteLabelTool.phpindex 29f425113..43ab32981 100644--- a/app/Mcp/Tools/Label/DeleteLabelTool.php+++ b/app/Mcp/Tools/Label/DeleteLabelTool.php@@ -16,10 +16,14 @@ use Laravel\Mcp\Server\Tool;#[Description('Delete a label by ID.')]class DeleteLabelTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$label = WorkspaceLabel::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($request->validated(), 'label_id'));+ ->find(data_get($request->validate(['label_id' => ['required', 'string']]), 'label_id'));++ if (! $label) {+ return Response::error('Label not found.');+ }DeleteLabel::execute($label);diff --git a/app/Mcp/Tools/Label/UpdateLabelTool.php b/app/Mcp/Tools/Label/UpdateLabelTool.phpindex f2be4ff47..589c613dd 100644--- a/app/Mcp/Tools/Label/UpdateLabelTool.php+++ b/app/Mcp/Tools/Label/UpdateLabelTool.php@@ -16,7 +16,7 @@ use Laravel\Mcp\Server\Tool;#[Description('Update a label name or color.')]class UpdateLabelTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$validated = $request->validate(['label_id' => ['required', 'string'],@@ -25,7 +25,11 @@ class UpdateLabelTool extends Tool]);$label = WorkspaceLabel::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($validated, 'label_id'));+ ->find(data_get($validated, 'label_id'));++ if (! $label) {+ return Response::error('Label not found.');+ }$label = UpdateLabel::execute($label, $validated);diff --git a/app/Mcp/Tools/Post/CreatePostTool.php b/app/Mcp/Tools/Post/CreatePostTool.phpindex 9261ae7a7..fbc00113b 100644--- a/app/Mcp/Tools/Post/CreatePostTool.php+++ b/app/Mcp/Tools/Post/CreatePostTool.php@@ -18,7 +18,8 @@ class CreatePostTool extends Toolpublic function handle(Request $request): ResponseFactory{$workspace = $request->user()->currentWorkspace;- $post = CreatePost::execute($workspace, $request->user(), $request->validated());+ $validated = $request->validate(['date' => ['nullable', 'string']]);+ $post = CreatePost::execute($workspace, $request->user(), $validated);$post->load(['postPlatforms.socialAccount']);return Response::structured($post->toArray());diff --git a/app/Mcp/Tools/Post/DeletePostTool.php b/app/Mcp/Tools/Post/DeletePostTool.phpindex 923b7e2aa..945321356 100644--- a/app/Mcp/Tools/Post/DeletePostTool.php+++ b/app/Mcp/Tools/Post/DeletePostTool.php@@ -16,10 +16,14 @@ use Laravel\Mcp\Server\Tool;#[Description('Delete a post by ID.')]class DeletePostTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$post = Post::where('workspace_id', $request->user()->current_workspace_id)- ->findOrFail(data_get($request->validated(), 'post_id'));+ ->find(data_get($request->validate(['post_id' => ['required', 'string']]), 'post_id'));++ if (! $post) {+ return Response::error('Post not found.');+ }DeletePost::execute($post);diff --git a/app/Mcp/Tools/Post/GetPostTool.php b/app/Mcp/Tools/Post/GetPostTool.phpindex 5868b04df..65b1fd26d 100644--- a/app/Mcp/Tools/Post/GetPostTool.php+++ b/app/Mcp/Tools/Post/GetPostTool.php@@ -17,11 +17,15 @@ use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;#[Description('Get a specific post by ID with all its platform content and labels.')]class GetPostTool extends Tool{- public function handle(Request $request): ResponseFactory+ public function handle(Request $request): Response|ResponseFactory{$post = Post::where('workspace_id', $request->user()->current_workspace_id)->with(['postPlatforms.socialAccount', 'postPlatforms.media', 'labels'])- ->findOrFail(data_get($request->validated(), 'post_id'));+ ->find(data_get($request->validate(['post_id' => ['required', 'string']]), 'post_id'));++ if (! $post) {+ return Response::error('Post not found.');+ }return Response::structured($post->toArray());}diff --git a/app/Mcp/Tools/SocialAccount/ListSocialAccountsTool.php b/app/Mcp/Tools/SocialAccount/ListSocialAccountsTool.phpnew file mode 100644index 000000000..04888de35--- /dev/null+++ b/app/Mcp/Tools/SocialAccount/ListSocialAccountsTool.php@@ -0,0 +1,35 @@+<?php++declare(strict_types=1);++namespace App\Mcp\Tools\SocialAccount;++use Laravel\Mcp\Request;+use Laravel\Mcp\Response;+use Laravel\Mcp\ResponseFactory;+use Laravel\Mcp\Server\Attributes\Description;+use Laravel\Mcp\Server\Tool;+use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;++#[IsReadOnly]+#[Description('List all connected social accounts for the current workspace.')]+class ListSocialAccountsTool extends Tool+{+ public function handle(Request $request): ResponseFactory+ {+ $accounts = $request->user()->currentWorkspace+ ->socialAccounts()+ ->orderBy('platform')+ ->get()+ ->map(fn ($account) => [+ 'id' => $account->id,+ 'platform' => $account->platform->value,+ 'display_name' => $account->display_name,+ 'username' => $account->username,+ 'is_active' => $account->is_active,+ 'status' => $account->status->value,+ ]);++ return Response::structured($accounts->toArray());+ }+}diff --git a/app/Mcp/Tools/SocialAccount/ToggleSocialAccountTool.php b/app/Mcp/Tools/SocialAccount/ToggleSocialAccountTool.phpnew file mode 100644index 000000000..02420bbd6--- /dev/null+++ b/app/Mcp/Tools/SocialAccount/ToggleSocialAccountTool.php@@ -0,0 +1,52 @@+<?php++declare(strict_types=1);++namespace App\Mcp\Tools\SocialAccount;++use App\Actions\SocialAccount\ToggleSocialAccount;+use App\Models\SocialAccount;+use Illuminate\Contracts\JsonSchema\JsonSchema;+use Laravel\Mcp\Request;+use Laravel\Mcp\Response;+use Laravel\Mcp\ResponseFactory;+use Laravel\Mcp\Server\Attributes\Description;+use Laravel\Mcp\Server\Tool;++#[Description('Toggle a social account active/inactive. Returns the updated account.')]+class ToggleSocialAccountTool extends Tool+{+ public function handle(Request $request): Response|ResponseFactory+ {+ $validated = $request->validate([+ 'account_id' => ['required', 'string', 'uuid'],+ ]);++ $workspace = $request->user()->currentWorkspace;+ $account = SocialAccount::where('workspace_id', $workspace->id)+ ->where('id', data_get($validated, 'account_id'))+ ->first();++ if (! $account) {+ return Response::error('Account not found.');+ }++ ToggleSocialAccount::execute($account);++ return Response::structured([+ 'id' => $account->id,+ 'platform' => $account->platform->value,+ 'display_name' => $account->display_name,+ 'username' => $account->username,+ 'is_active' => $account->is_active,+ 'status' => $account->status->value,+ ]);+ }++ public function schema(JsonSchema $schema): array+ {+ return [+ 'account_id' => $schema->string()->required()->description('The UUID of the social account to toggle.'),+ ];+ }+}diff --git a/app/Services/Social/PinterestPublisher.php b/app/Services/Social/PinterestPublisher.phpindex 8438075b5..59c3ab01c 100644--- a/app/Services/Social/PinterestPublisher.php+++ b/app/Services/Social/PinterestPublisher.php@@ -50,7 +50,7 @@ class PinterestPublisherthrow new \Exception('Pinterest requires at least one image');}- $boardId = $postPlatform->meta['board_id'] ?? $account->meta['default_board_id'] ?? null;+ $boardId = data_get($postPlatform->meta, 'board_id') ?? data_get($account->meta, 'default_board_id') ?? null;if (! $boardId) {throw new \Exception('Pinterest board_id is required');@@ -74,16 +74,16 @@ class PinterestPublisher$payload['description'] = $postPlatform->content;}- if (! empty($postPlatform->meta['title'])) {- $payload['title'] = substr($postPlatform->meta['title'], 0, 100);+ if (! empty(data_get($postPlatform->meta, 'title'))) {+ $payload['title'] = substr(data_get($postPlatform->meta, 'title'), 0, 100);}- if (! empty($postPlatform->meta['link'])) {- $payload['link'] = $postPlatform->meta['link'];+ if (! empty(data_get($postPlatform->meta, 'link'))) {+ $payload['link'] = data_get($postPlatform->meta, 'link');}- if (! empty($postPlatform->meta['alt_text'])) {- $payload['alt_text'] = substr($postPlatform->meta['alt_text'], 0, 500);+ if (! empty(data_get($postPlatform->meta, 'alt_text'))) {+ $payload['alt_text'] = substr(data_get($postPlatform->meta, 'alt_text'), 0, 500);}$response = Http::withToken($account->access_token)@@ -116,7 +116,7 @@ class PinterestPublisherthrow new \Exception('Pinterest requires a video');}- $boardId = $postPlatform->meta['board_id'] ?? $account->meta['default_board_id'] ?? null;+ $boardId = data_get($postPlatform->meta, 'board_id') ?? data_get($account->meta, 'default_board_id') ?? null;if (! $boardId) {throw new \Exception('Pinterest board_id is required');@@ -201,16 +201,16 @@ class PinterestPublisher$payload['description'] = $postPlatform->content;}- if (! empty($postPlatform->meta['title'])) {- $payload['title'] = substr($postPlatform->meta['title'], 0, 100);+ if (! empty(data_get($postPlatform->meta, 'title'))) {+ $payload['title'] = substr(data_get($postPlatform->meta, 'title'), 0, 100);}- if (! empty($postPlatform->meta['link'])) {- $payload['link'] = $postPlatform->meta['link'];+ if (! empty(data_get($postPlatform->meta, 'link'))) {+ $payload['link'] = data_get($postPlatform->meta, 'link');}- if (! empty($postPlatform->meta['cover_image_url'])) {- $payload['media_source']['cover_image_url'] = $postPlatform->meta['cover_image_url'];+ if (! empty(data_get($postPlatform->meta, 'cover_image_url'))) {+ $payload['media_source']['cover_image_url'] = data_get($postPlatform->meta, 'cover_image_url');}$response = Http::withToken($account->access_token)@@ -243,7 +243,7 @@ class PinterestPublisherthrow new \Exception('Pinterest carousel requires 2-5 images');}- $boardId = $postPlatform->meta['board_id'] ?? $account->meta['default_board_id'] ?? null;+ $boardId = data_get($postPlatform->meta, 'board_id') ?? data_get($account->meta, 'default_board_id') ?? null;if (! $boardId) {throw new \Exception('Pinterest board_id is required');@@ -271,12 +271,12 @@ class PinterestPublisher$payload['description'] = $postPlatform->content;}- if (! empty($postPlatform->meta['title'])) {- $payload['title'] = substr($postPlatform->meta['title'], 0, 100);+ if (! empty(data_get($postPlatform->meta, 'title'))) {+ $payload['title'] = substr(data_get($postPlatform->meta, 'title'), 0, 100);}- if (! empty($postPlatform->meta['link'])) {- $payload['link'] = $postPlatform->meta['link'];+ if (! empty(data_get($postPlatform->meta, 'link'))) {+ $payload['link'] = data_get($postPlatform->meta, 'link');}$response = Http::withToken($account->access_token)diff --git a/app/Services/Social/XPublisher.php b/app/Services/Social/XPublisher.phpindex 7fda58418..bab888d02 100644--- a/app/Services/Social/XPublisher.php+++ b/app/Services/Social/XPublisher.php@@ -73,7 +73,7 @@ class XPublisher];}- if (empty($data['text']) && empty($mediaIds)) {+ if (empty($data['text'] ?? null) && empty($mediaIds)) {throw new \Exception('X posts require either text or media. Please add content to your post.');}diff --git a/routes/api.php b/routes/api.phpindex cf63a43eb..4a6353f03 100644--- a/routes/api.php+++ b/routes/api.php@@ -6,6 +6,7 @@ use App\Http\Controllers\Api\ApiKeyController;use App\Http\Controllers\Api\HashtagController;use App\Http\Controllers\Api\LabelController;use App\Http\Controllers\Api\PostController;+use App\Http\Controllers\Api\SocialAccountController;use App\Http\Controllers\Api\WorkspaceController;use Illuminate\Support\Facades\Route;@@ -37,6 +38,10 @@ Route::group(Route::put('/labels/{label}', [LabelController::class, 'update'])->name('api.labels.update');Route::delete('/labels/{label}', [LabelController::class, 'destroy'])->name('api.labels.destroy');+ // Social Accounts+ Route::get('/social-accounts', [SocialAccountController::class, 'index'])->name('api.social-accounts.index');+ Route::put('/social-accounts/{account}/toggle', [SocialAccountController::class, 'toggle'])->name('api.social-accounts.toggle');+// API KeysRoute::get('/api-keys', [ApiKeyController::class, 'index'])->name('api.api-keys.index');Route::post('/api-keys', [ApiKeyController::class, 'store'])->name('api.api-keys.store');diff --git a/tests/Feature/Api/ApiKeyApiTest.php b/tests/Feature/Api/ApiKeyApiTest.phpindex b0d613591..9350559e3 100644--- a/tests/Feature/Api/ApiKeyApiTest.php+++ b/tests/Feature/Api/ApiKeyApiTest.php@@ -127,3 +127,26 @@ test('cannot delete api key from another workspace', function () {$response->assertNotFound();});++it('validates api key expires_at must be future date', function () {+ $result = createApiKeyApiToken();++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->postJson(route('api.api-keys.store'), [+ 'name' => 'Test Key',+ 'expires_at' => '2020-01-01',+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['expires_at']);+});++it('validates api key name max length', function () {+ $result = createApiKeyApiToken();++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->postJson(route('api.api-keys.store'), [+ 'name' => str_repeat('a', 256),+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['name']);+});diff --git a/tests/Feature/Api/HashtagApiTest.php b/tests/Feature/Api/HashtagApiTest.phpindex 59e9f88df..8498a4534 100644--- a/tests/Feature/Api/HashtagApiTest.php+++ b/tests/Feature/Api/HashtagApiTest.php@@ -149,3 +149,47 @@ test('cannot access hashtags from another workspace', function () {$response->assertNotFound();});++test('cannot update hashtag from another workspace', function () {+ $result = createHashtagApiToken();+ $otherWorkspace = Workspace::factory()->create();+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->putJson(route('api.hashtags.update', $hashtag), [+ 'name' => 'Hacked',+ 'hashtags' => '#hacked',+ ])+ ->assertNotFound();+});++test('update hashtag validation errors', function () {+ $result = createHashtagApiToken();+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => data_get($result, 'workspace')->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->putJson(route('api.hashtags.update', $hashtag), [])+ ->assertUnprocessable();+});++test('list hashtags returns correct structure', function () {+ $result = createHashtagApiToken();+ WorkspaceHashtag::factory()->create(['workspace_id' => data_get($result, 'workspace')->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->getJson(route('api.hashtags.index'))+ ->assertOk()+ ->assertJsonStructure([+ '*' => ['id', 'name', 'hashtags', 'created_at', 'updated_at'],+ ]);+});++test('cannot delete hashtag from another workspace', function () {+ $result = createHashtagApiToken();+ $otherWorkspace = Workspace::factory()->create();+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->deleteJson(route('api.hashtags.destroy', $hashtag))+ ->assertNotFound();+});diff --git a/tests/Feature/Api/LabelApiTest.php b/tests/Feature/Api/LabelApiTest.phpindex e6f74eb90..be41e1ef9 100644--- a/tests/Feature/Api/LabelApiTest.php+++ b/tests/Feature/Api/LabelApiTest.php@@ -170,3 +170,59 @@ test('cannot access labels from another workspace', function () {$response->assertNotFound();});++test('cannot update label from another workspace', function () {+ $result = createLabelApiToken();+ $otherWorkspace = Workspace::factory()->create();+ $label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->putJson(route('api.labels.update', $label), [+ 'name' => 'Hacked',+ 'color' => '#000000',+ ])+ ->assertNotFound();+});++test('update label validation errors', function () {+ $result = createLabelApiToken();+ $label = WorkspaceLabel::factory()->create(['workspace_id' => data_get($result, 'workspace')->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->putJson(route('api.labels.update', $label), [])+ ->assertUnprocessable();+});++test('update label validates color format', function () {+ $result = createLabelApiToken();+ $label = WorkspaceLabel::factory()->create(['workspace_id' => data_get($result, 'workspace')->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->putJson(route('api.labels.update', $label), [+ 'name' => 'Test',+ 'color' => 'invalid',+ ])+ ->assertUnprocessable();+});++test('list labels returns correct structure', function () {+ $result = createLabelApiToken();+ WorkspaceLabel::factory()->create(['workspace_id' => data_get($result, 'workspace')->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->getJson(route('api.labels.index'))+ ->assertOk()+ ->assertJsonStructure([+ '*' => ['id', 'name', 'color', 'created_at', 'updated_at'],+ ]);+});++test('cannot delete label from another workspace', function () {+ $result = createLabelApiToken();+ $otherWorkspace = Workspace::factory()->create();+ $label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->deleteJson(route('api.labels.destroy', $label))+ ->assertNotFound();+});diff --git a/tests/Feature/Api/PostApiTest.php b/tests/Feature/Api/PostApiTest.phpindex 4c52a7269..03e20b6a4 100644--- a/tests/Feature/Api/PostApiTest.php+++ b/tests/Feature/Api/PostApiTest.php@@ -7,6 +7,7 @@ use App\Enums\SocialAccount\Platform;use App\Enums\UserWorkspace\Role;use App\Models\ApiToken;use App\Models\Post;+use App\Models\PostPlatform;use App\Models\SocialAccount;use App\Models\User;use App\Models\Workspace;@@ -108,3 +109,155 @@ it('cannot delete post from another workspace', function () {->deleteJson(route('api.posts.destroy', $post))->assertNotFound();});++it('updates a post', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ 'status' => PostStatus::Draft,+ ]);++ $postPlatform = PostPlatform::factory()->linkedin()->create([+ 'post_id' => $post->id,+ 'social_account_id' => $this->socialAccount->id,+ 'enabled' => true,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [+ 'platforms' => [+ [+ 'id' => $postPlatform->id,+ 'content' => 'Updated content',+ ],+ ],+ ])+ ->assertOk();+});++it('cannot update post from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $post = Post::factory()->create([+ 'workspace_id' => $otherWorkspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [])+ ->assertNotFound();+});++it('cannot update published post', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ 'status' => PostStatus::Published,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [])+ ->assertUnprocessable();+});++it('validates post update fields', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [+ 'platforms' => [+ ['content' => 'missing id'],+ ],+ ])+ ->assertUnprocessable();+});++it('validates post creation requires platforms', function () {+ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->postJson(route('api.posts.store'), [])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['platforms']);+});++it('validates post creation platform fields', function () {+ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->postJson(route('api.posts.store'), [+ 'platforms' => [+ ['content' => 'missing social_account_id and content_type'],+ ],+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['platforms.0.social_account_id', 'platforms.0.content_type']);+});++it('validates post update invalid status', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [+ 'status' => 'invalid_status',+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['status']);+});++it('validates post update scheduled_at must be date', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [+ 'scheduled_at' => 'not-a-date',+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['scheduled_at']);+});++it('validates post update label_ids must be uuids', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->putJson(route('api.posts.update', $post), [+ 'label_ids' => ['not-a-uuid'],+ ])+ ->assertUnprocessable()+ ->assertJsonValidationErrors(['label_ids.0']);+});++it('list posts returns correct structure', function () {+ Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->getJson(route('api.posts.index'))+ ->assertOk()+ ->assertJsonStructure([+ 'data' => [+ '*' => ['id', 'status', 'synced', 'scheduled_at', 'published_at', 'created_at', 'updated_at'],+ ],+ ]);+});++it('show post returns correct structure', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])+ ->getJson(route('api.posts.show', $post))+ ->assertOk()+ ->assertJsonStructure(['id', 'status', 'synced', 'scheduled_at', 'published_at']);+});diff --git a/tests/Feature/Api/SocialAccountApiTest.php b/tests/Feature/Api/SocialAccountApiTest.phpnew file mode 100644index 000000000..4531dde64--- /dev/null+++ b/tests/Feature/Api/SocialAccountApiTest.php@@ -0,0 +1,133 @@+<?php++declare(strict_types=1);++use App\Enums\SocialAccount\Platform;+use App\Enums\UserWorkspace\Role;+use App\Models\ApiToken;+use App\Models\SocialAccount;+use App\Models\User;+use App\Models\Workspace;+use Illuminate\Support\Facades\Hash;+use Illuminate\Support\Str;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);++ $plainToken = 'tp_'.Str::random(48);+ $this->plainToken = $plainToken;+ $this->apiToken = ApiToken::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'token_lookup' => substr($plainToken, 3, 16),+ 'token_hash' => Hash::make($plainToken),+ ]);+});++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);+});diff --git a/tests/Feature/Api/WorkspaceApiTest.php b/tests/Feature/Api/WorkspaceApiTest.phpindex b4e7ef627..066982e82 100644--- a/tests/Feature/Api/WorkspaceApiTest.php+++ b/tests/Feature/Api/WorkspaceApiTest.php@@ -57,3 +57,12 @@ test('show workspace requires authentication', function () {$response->assertUnauthorized();});++test('workspace returns correct structure', function () {+ $result = createWorkspaceApiToken();++ $this->withHeaders(['Authorization' => 'Bearer '.data_get($result, 'plain_token')])+ ->getJson(route('api.workspace.show'))+ ->assertOk()+ ->assertJsonStructure(['id', 'name', 'timezone', 'created_at', 'updated_at']);+});diff --git a/tests/Feature/ApiKeyControllerTest.php b/tests/Feature/ApiKeyControllerTest.phpindex dab8ca786..1b436d0a2 100644--- a/tests/Feature/ApiKeyControllerTest.php+++ b/tests/Feature/ApiKeyControllerTest.php@@ -100,3 +100,7 @@ it('member cannot delete api key', function () {->delete(route('app.api-keys.destroy', $token))->assertForbidden();});++it('api keys page requires authentication', function () {+ $this->get(route('app.api-keys.index'))->assertRedirect(route('login'));+});diff --git a/tests/Feature/Mcp/ApiKeyToolTest.php b/tests/Feature/Mcp/ApiKeyToolTest.phpnew file mode 100644index 000000000..f3f6e852f--- /dev/null+++ b/tests/Feature/Mcp/ApiKeyToolTest.php@@ -0,0 +1,73 @@+<?php++declare(strict_types=1);++use App\Enums\UserWorkspace\Role;+use App\Mcp\Servers\TryPostServer;+use App\Mcp\Tools\ApiKey\CreateApiKeyTool;+use App\Mcp\Tools\ApiKey\DeleteApiKeyTool;+use App\Mcp\Tools\ApiKey\ListApiKeysTool;+use App\Models\ApiToken;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('can list api keys', function () {+ ApiToken::factory()->count(2)->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListApiKeysTool::class, []);++ $response->assertOk();+});++test('can create api key', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreateApiKeyTool::class, [+ 'name' => 'My Key',+ ]);++ $response->assertOk();+ $response->assertSee('My Key');+ expect($this->workspace->apiTokens()->count())->toBe(1);+});++test('create api key validates name required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreateApiKeyTool::class, []);++ $response->assertHasErrors();+});++test('can delete api key', function () {+ $token = ApiToken::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteApiKeyTool::class, ['api_key_id' => $token->id]);++ $response->assertOk();+ expect(ApiToken::find($token->id))->toBeNull();+});++test('cannot delete api key from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $token = ApiToken::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteApiKeyTool::class, ['api_key_id' => $token->id]);++ $response->assertHasErrors(['API key not found.']);+});++test('delete api key validates api_key_id required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteApiKeyTool::class, []);++ $response->assertHasErrors();+});diff --git a/tests/Feature/Mcp/HashtagToolTest.php b/tests/Feature/Mcp/HashtagToolTest.phpnew file mode 100644index 000000000..660237111--- /dev/null+++ b/tests/Feature/Mcp/HashtagToolTest.php@@ -0,0 +1,110 @@+<?php++declare(strict_types=1);++use App\Enums\UserWorkspace\Role;+use App\Mcp\Servers\TryPostServer;+use App\Mcp\Tools\Hashtag\CreateHashtagTool;+use App\Mcp\Tools\Hashtag\DeleteHashtagTool;+use App\Mcp\Tools\Hashtag\ListHashtagsTool;+use App\Mcp\Tools\Hashtag\UpdateHashtagTool;+use App\Models\User;+use App\Models\Workspace;+use App\Models\WorkspaceHashtag;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('can list hashtags', function () {+ WorkspaceHashtag::factory()->count(2)->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListHashtagsTool::class, []);++ $response->assertOk();+});++test('can create hashtag', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreateHashtagTool::class, [+ 'name' => 'Marketing',+ 'hashtags' => '#marketing #social',+ ]);++ $response->assertOk();+ $response->assertSee('Marketing');+ expect($this->workspace->hashtags()->count())->toBe(1);+});++test('create hashtag validates required fields', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreateHashtagTool::class, []);++ $response->assertHasErrors();+});++test('can update hashtag', function () {+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(UpdateHashtagTool::class, [+ 'hashtag_id' => $hashtag->id,+ 'name' => 'Updated',+ 'hashtags' => '#updated',+ ]);++ $response->assertOk();+ $response->assertSee('Updated');+});++test('cannot update hashtag from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(UpdateHashtagTool::class, [+ 'hashtag_id' => $hashtag->id,+ 'name' => 'Hacked',+ 'hashtags' => '#hacked',+ ]);++ $response->assertHasErrors(['Hashtag not found.']);+});++test('can delete hashtag', function () {+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteHashtagTool::class, ['hashtag_id' => $hashtag->id]);++ $response->assertOk();+ expect(WorkspaceHashtag::find($hashtag->id))->toBeNull();+});++test('cannot delete hashtag from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $otherWorkspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteHashtagTool::class, ['hashtag_id' => $hashtag->id]);++ $response->assertHasErrors(['Hashtag not found.']);+});++test('update hashtag validates required fields', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(UpdateHashtagTool::class, []);++ $response->assertHasErrors();+});++test('delete hashtag validates hashtag_id required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteHashtagTool::class, []);++ $response->assertHasErrors();+});diff --git a/tests/Feature/Mcp/LabelToolTest.php b/tests/Feature/Mcp/LabelToolTest.phpnew file mode 100644index 000000000..ca7f31a80--- /dev/null+++ b/tests/Feature/Mcp/LabelToolTest.php@@ -0,0 +1,120 @@+<?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;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('can list labels', function () {+ WorkspaceLabel::factory()->count(2)->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListLabelsTool::class, []);++ $response->assertOk();+});++test('can create label', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreateLabelTool::class, [+ 'name' => 'Important',+ 'color' => '#FF0000',+ ]);++ $response->assertOk();+ $response->assertSee('Important');+ 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();+});++test('can update label', function () {+ $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',+ ]);++ $response->assertOk();+ $response->assertSee('Updated');+});++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.']);+});++test('can delete label', function () {+ $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeleteLabelTool::class, ['label_id' => $label->id]);++ $response->assertOk();+ 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();+});diff --git a/tests/Feature/Mcp/PostToolTest.php b/tests/Feature/Mcp/PostToolTest.phpnew file mode 100644index 000000000..c2ad0638b--- /dev/null+++ b/tests/Feature/Mcp/PostToolTest.php@@ -0,0 +1,125 @@+<?php++declare(strict_types=1);++use App\Enums\SocialAccount\Platform;+use App\Enums\UserWorkspace\Role;+use App\Mcp\Servers\TryPostServer;+use App\Mcp\Tools\Post\CreatePostTool;+use App\Mcp\Tools\Post\DeletePostTool;+use App\Mcp\Tools\Post\GetPostTool;+use App\Mcp\Tools\Post\ListPostsTool;+use App\Models\Post;+use App\Models\SocialAccount;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);++ $this->socialAccount = SocialAccount::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'platform' => Platform::LinkedIn,+ ]);+});++test('can list posts', function () {+ Post::factory()->count(3)->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListPostsTool::class, []);++ $response->assertOk();+});++test('listing only returns own workspace posts', function () {+ Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id]);++ $otherWorkspace = Workspace::factory()->create();+ Post::factory()->create(['workspace_id' => $otherWorkspace->id, 'user_id' => $this->user->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListPostsTool::class, []);++ $response->assertOk();+});++test('can get a post by id', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(GetPostTool::class, ['post_id' => $post->id]);++ $response->assertOk();+});++test('cannot get post from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $post = Post::factory()->create(['workspace_id' => $otherWorkspace->id, 'user_id' => $this->user->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(GetPostTool::class, ['post_id' => $post->id]);++ $response->assertHasErrors(['Post not found.']);+});++test('can create a post', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreatePostTool::class, []);++ $response->assertOk();+ expect(Post::where('workspace_id', $this->workspace->id)->count())->toBe(1);+});++test('can create a post with date', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(CreatePostTool::class, ['date' => '2026-04-15']);++ $response->assertOk();+});++test('can delete a post', function () {+ $post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeletePostTool::class, ['post_id' => $post->id]);++ $response->assertOk();+ expect(Post::find($post->id))->toBeNull();+});++test('cannot delete post from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $post = Post::factory()->create(['workspace_id' => $otherWorkspace->id, 'user_id' => $this->user->id]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(DeletePostTool::class, ['post_id' => $post->id]);++ $response->assertHasErrors(['Post not found.']);+});++test('get post validates post_id required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(GetPostTool::class, []);++ $response->assertHasErrors();+});++test('delete post validates post_id required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(DeletePostTool::class, []);++ $response->assertHasErrors();+});diff --git a/tests/Feature/Mcp/SocialAccountToolTest.php b/tests/Feature/Mcp/SocialAccountToolTest.phpnew file mode 100644index 000000000..8d6994151--- /dev/null+++ b/tests/Feature/Mcp/SocialAccountToolTest.php@@ -0,0 +1,126 @@+<?php++declare(strict_types=1);++use App\Enums\SocialAccount\Platform;+use App\Enums\UserWorkspace\Role;+use App\Mcp\Servers\TryPostServer;+use App\Mcp\Tools\SocialAccount\ListSocialAccountsTool;+use App\Mcp\Tools\SocialAccount\ToggleSocialAccountTool;+use App\Models\SocialAccount;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++// ListSocialAccountsTool++test('can list 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 = TryPostServer::actingAs($this->user)+ ->tool(ListSocialAccountsTool::class, []);++ $response->assertOk();+});++test('listing only returns own workspace accounts', function () {+ SocialAccount::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'platform' => Platform::LinkedIn,+ ]);++ $otherWorkspace = Workspace::factory()->create();+ SocialAccount::factory()->create([+ 'workspace_id' => $otherWorkspace->id,+ 'platform' => Platform::X,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListSocialAccountsTool::class, []);++ $response->assertOk();+ $response->assertDontSee(Platform::X->value);+});++test('list does not expose tokens', function () {+ SocialAccount::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'platform' => Platform::LinkedIn,+ 'access_token' => 'secret-token-123',+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ListSocialAccountsTool::class, []);++ $response->assertOk();+ $response->assertDontSee('secret-token-123');+});++// ToggleSocialAccountTool++test('can toggle social account to inactive', function () {+ $account = SocialAccount::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'platform' => Platform::LinkedIn,+ 'is_active' => true,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ToggleSocialAccountTool::class, [+ 'account_id' => $account->id,+ ]);++ $response->assertOk();+ expect($account->fresh()->is_active)->toBeFalse();+});++test('can toggle social account to active', function () {+ $account = SocialAccount::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'platform' => Platform::LinkedIn,+ 'is_active' => false,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ToggleSocialAccountTool::class, [+ 'account_id' => $account->id,+ ]);++ $response->assertOk();+ expect($account->fresh()->is_active)->toBeTrue();+});++test('cannot toggle account from another workspace', function () {+ $otherWorkspace = Workspace::factory()->create();+ $account = SocialAccount::factory()->create([+ 'workspace_id' => $otherWorkspace->id,+ 'platform' => Platform::LinkedIn,+ ]);++ $response = TryPostServer::actingAs($this->user)+ ->tool(ToggleSocialAccountTool::class, [+ 'account_id' => $account->id,+ ]);++ $response->assertHasErrors();+});++test('toggle validates account_id is required', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(ToggleSocialAccountTool::class, []);++ $response->assertHasErrors();+});diff --git a/tests/Feature/Mcp/WorkspaceToolTest.php b/tests/Feature/Mcp/WorkspaceToolTest.phpnew file mode 100644index 000000000..e7d2582b4--- /dev/null+++ b/tests/Feature/Mcp/WorkspaceToolTest.php@@ -0,0 +1,24 @@+<?php++declare(strict_types=1);++use App\Enums\UserWorkspace\Role;+use App\Mcp\Servers\TryPostServer;+use App\Mcp\Tools\Workspace\GetWorkspaceTool;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Owner->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('can get workspace details', function () {+ $response = TryPostServer::actingAs($this->user)+ ->tool(GetWorkspaceTool::class, []);++ $response->assertOk();+ $response->assertSee($this->workspace->name);+});diff --git a/tests/Feature/MediaControllerTest.php b/tests/Feature/MediaControllerTest.phpindex 9a5eecffa..38e9d690b 100644--- a/tests/Feature/MediaControllerTest.php+++ b/tests/Feature/MediaControllerTest.php@@ -188,3 +188,20 @@ test('reorder media rejects media from other workspace', function () {$response->assertForbidden();});++test('reorder media validates required fields', function () {+ $response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), []);++ $response->assertUnprocessable();+ $response->assertJsonValidationErrors(['media']);+});++test('reorder media validates media items have id and order', function () {+ $response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), [+ 'media' => [+ ['invalid' => 'data'],+ ],+ ]);++ $response->assertUnprocessable();+});diff --git a/tests/Feature/NotificationControllerTest.php b/tests/Feature/NotificationControllerTest.phpindex 9ee6e1e54..22f85158e 100644--- a/tests/Feature/NotificationControllerTest.php+++ b/tests/Feature/NotificationControllerTest.php@@ -131,3 +131,20 @@ test('archive all notifications', function () {expect($active)->toBe(0);});++test('mark as read requires authentication', function () {+ $notification = Notification::factory()->create([+ 'user_id' => $this->user->id,+ 'workspace_id' => $this->workspace->id,+ ]);++ $this->putJson(route('app.notifications.read', $notification))->assertUnauthorized();+});++test('mark all as read requires authentication', function () {+ $this->postJson(route('app.notifications.read-all'))->assertUnauthorized();+});++test('archive all requires authentication', function () {+ $this->postJson(route('app.notifications.archive-all'))->assertUnauthorized();+});diff --git a/tests/Feature/Settings/NotificationPreferenceTest.php b/tests/Feature/Settings/NotificationPreferenceTest.phpindex 46f73d63a..135ff333b 100644--- a/tests/Feature/Settings/NotificationPreferenceTest.php+++ b/tests/Feature/Settings/NotificationPreferenceTest.php@@ -126,3 +126,13 @@ test('send notification respects email preferences', function () {// In-app notification should still be createdexpect(Notification::count())->toBe(1);});++test('notification preferences update requires authentication', function () {+ $response = $this->put(route('app.notifications.preferences.update'), [+ 'post_published' => true,+ 'post_failed' => true,+ 'account_disconnected' => true,+ ]);++ $response->assertRedirect(route('login'));+});diff --git a/tests/Feature/Settings/PasswordUpdateTest.php b/tests/Feature/Settings/PasswordUpdateTest.phpindex da4950a0d..2faf8f628 100644--- a/tests/Feature/Settings/PasswordUpdateTest.php+++ b/tests/Feature/Settings/PasswordUpdateTest.php@@ -50,3 +50,24 @@ test('correct password must be provided to update password', function () {->assertSessionHasErrors('current_password')->assertRedirect(route('app.user-password.edit'));});++test('password update requires authentication', function () {+ $response = $this->put(route('app.user-password.update'), []);++ $response->assertRedirect(route('login'));+});++test('password must be confirmed', function () {+ $user = User::factory()->create();++ $response = $this+ ->actingAs($user)+ ->from(route('app.user-password.edit'))+ ->put(route('app.user-password.update'), [+ 'current_password' => 'password',+ 'password' => 'new-password',+ 'password_confirmation' => 'wrong-confirmation',+ ]);++ $response->assertSessionHasErrors('password');+});diff --git a/tests/Feature/Settings/ProfileUpdateTest.php b/tests/Feature/Settings/ProfileUpdateTest.phpindex 17d80bdde..7ae57c540 100644--- a/tests/Feature/Settings/ProfileUpdateTest.php+++ b/tests/Feature/Settings/ProfileUpdateTest.php@@ -230,3 +230,23 @@ test('user can delete profile photo', function () {$user->refresh();expect($user->has_photo)->toBeFalse();});++test('user cannot upload photo exceeding max size', function () {+ $user = User::factory()->create();++ $response = $this+ ->actingAs($user)+ ->post(route('app.profile.upload-photo'), [+ 'photo' => UploadedFile::fake()->image('large.jpg')->size(6000),+ ]);++ $response->assertSessionHasErrors('photo');+});++test('delete account requires authentication', function () {+ $response = $this->delete(route('app.profile.destroy'), [+ 'password' => 'password',+ ]);++ $response->assertRedirect(route('login'));+});diff --git a/tests/Feature/WorkspaceHashtagControllerTest.php b/tests/Feature/WorkspaceHashtagControllerTest.phpindex 42a769743..7448d8951 100644--- a/tests/Feature/WorkspaceHashtagControllerTest.php+++ b/tests/Feature/WorkspaceHashtagControllerTest.php@@ -184,3 +184,11 @@ test('member can create hashtag', function () {$response->assertRedirect();expect($this->workspace->hashtags()->count())->toBe(1);});++test('update hashtag validates required fields', function () {+ $hashtag = WorkspaceHashtag::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = $this->actingAs($this->user)->put(route('app.hashtags.update', $hashtag), []);++ $response->assertSessionHasErrors(['name', 'hashtags']);+});diff --git a/tests/Feature/WorkspaceInviteControllerTest.php b/tests/Feature/WorkspaceInviteControllerTest.phpindex c14b946fc..bc2eb96d2 100644--- a/tests/Feature/WorkspaceInviteControllerTest.php+++ b/tests/Feature/WorkspaceInviteControllerTest.php@@ -228,3 +228,26 @@ test('update role requires authorization', function () {$response->assertForbidden();});++test('store invite validates email is required', function () {+ $response = $this->actingAs($this->user)->post(route('app.invites.store'), []);++ $response->assertSessionHasErrors('email');+});++test('store invite validates email format', function () {+ $response = $this->actingAs($this->user)->post(route('app.invites.store'), [+ 'email' => 'not-an-email',+ ]);++ $response->assertSessionHasErrors('email');+});++test('store invite validates role must be valid', function () {+ $response = $this->actingAs($this->user)->post(route('app.invites.store'), [+ 'email' => '[email protected]',+ 'role' => 'owner',+ ]);++ $response->assertSessionHasErrors('role');+});diff --git a/tests/Feature/WorkspaceLabelControllerTest.php b/tests/Feature/WorkspaceLabelControllerTest.phpindex bb885282a..2dcd78c68 100644--- a/tests/Feature/WorkspaceLabelControllerTest.php+++ b/tests/Feature/WorkspaceLabelControllerTest.php@@ -193,3 +193,22 @@ test('member can create label', function () {$response->assertRedirect();expect($this->workspace->labels()->count())->toBe(1);});++test('update label validates required fields', function () {+ $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = $this->actingAs($this->user)->put(route('app.labels.update', $label), []);++ $response->assertSessionHasErrors(['name', 'color']);+});++test('update label validates color format', function () {+ $label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);++ $response = $this->actingAs($this->user)->put(route('app.labels.update', $label), [+ 'name' => 'Test',+ 'color' => 'invalid',+ ]);++ $response->assertSessionHasErrors('color');+});