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);
|
|
|
|
|
|
2026-07-24 14:19:01 +00:00
|
|
|
use App\Enums\Post\CreatedVia;
|
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
|
|
|
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;
|
2026-06-04 20:08:57 +00:00
|
|
|
use App\Mcp\Tools\Post\UpdatePostTool;
|
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
|
|
|
use App\Models\Post;
|
2026-06-04 20:08:57 +00:00
|
|
|
use App\Models\PostPlatform;
|
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
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
2026-05-04 16:31:44 +00:00
|
|
|
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]);
|
|
|
|
|
|
|
|
|
|
$this->socialAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('list posts returns wrapped posts array with PostResource 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
|
|
|
Post::factory()->count(3)->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(ListPostsTool::class, []);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->has('posts', 3, function (AssertableJson $post) {
|
|
|
|
|
$post->hasAll(['id', 'content', 'media', 'status', 'scheduled_at', 'published_at', 'platforms', 'labels', 'created_at', 'updated_at'])
|
|
|
|
|
->missing('user_id')
|
|
|
|
|
->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 posts only returns own workspace posts', 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
|
|
|
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, []);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->has('posts', 1)->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
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('get post returns PostResource 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
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
2026-05-04 00:34:20 +00:00
|
|
|
'content' => 'Hello world',
|
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(GetPostTool::class, ['post_id' => $post->id]);
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) use ($post) {
|
|
|
|
|
$json->where('id', $post->id)
|
|
|
|
|
->where('content', 'Hello world')
|
|
|
|
|
->missing('user_id')
|
|
|
|
|
->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
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('get post 404 from another workspace', 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
|
|
|
$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.']);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('create post with content and date', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'content' => 'My new post',
|
feat: complete create + publish post flow via MCP and REST API
Lets ChatGPT (MCP) and external clients (REST API) drive the full lifecycle of
a post — create with platform selection, attach media from URLs, schedule or
publish immediately, and fetch engagement metrics — without touching the web UI.
MCP tools added: UpdatePostTool, PublishPostTool, AttachMediaFromUrlTool,
ListContentTypesTool, GetPostMetricsTool, PreviewPostTool. CreatePostTool now
accepts platforms[] + scheduled_at + label_ids; ListPostsTool gains
status/search/limit filters.
REST endpoints added: POST /api/posts/{post}/media, GET /api/posts/{post}/metrics,
GET /api/posts/{post}/preview, GET /api/content-types.
Also fixes a silent CreatePost::execute bug — the action validated platforms[]
but ignored it, so REST callers never saw their selection persisted. Adds cross
validation rules (ContentTypeMatchesPlatform / ContentTypeMatchesPostPlatform)
so a LinkedIn account can't be saddled with x_post, and rejects inactive social
accounts during validation instead of failing silently downstream.
Shared services (PostMetricsFetcher, PostPreviewer, MediaAttacher) back both
MCP tools and REST controllers so behaviour stays aligned. New Resources
(PlatformContentTypesResource, PostMetricsResource, PostPreviewResource,
PostMediaAttachResource) keep controllers free of inline model mapping.
Suite: 1.332 passing, 0 failing — covers web (PostControllerTest), REST
(PostApiTest, PlatformApiTest, PostMediaApiTest), MCP (66 tool tests), and
the publish job (PublishToSocialPlatformTest).
Removes /docs from git tracking and TIKTOK_REVIEW_VIDEO_SCRIPT.md.
2026-05-04 11:12:28 +00:00
|
|
|
'scheduled_at' => '2099-12-31T15:30:00Z',
|
2026-05-04 00:34:20 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk()
|
|
|
|
|
->assertStructuredContent(function (AssertableJson $json) {
|
|
|
|
|
$json->where('content', 'My new post')
|
|
|
|
|
->where('status', 'draft')
|
feat: complete create + publish post flow via MCP and REST API
Lets ChatGPT (MCP) and external clients (REST API) drive the full lifecycle of
a post — create with platform selection, attach media from URLs, schedule or
publish immediately, and fetch engagement metrics — without touching the web UI.
MCP tools added: UpdatePostTool, PublishPostTool, AttachMediaFromUrlTool,
ListContentTypesTool, GetPostMetricsTool, PreviewPostTool. CreatePostTool now
accepts platforms[] + scheduled_at + label_ids; ListPostsTool gains
status/search/limit filters.
REST endpoints added: POST /api/posts/{post}/media, GET /api/posts/{post}/metrics,
GET /api/posts/{post}/preview, GET /api/content-types.
Also fixes a silent CreatePost::execute bug — the action validated platforms[]
but ignored it, so REST callers never saw their selection persisted. Adds cross
validation rules (ContentTypeMatchesPlatform / ContentTypeMatchesPostPlatform)
so a LinkedIn account can't be saddled with x_post, and rejects inactive social
accounts during validation instead of failing silently downstream.
Shared services (PostMetricsFetcher, PostPreviewer, MediaAttacher) back both
MCP tools and REST controllers so behaviour stays aligned. New Resources
(PlatformContentTypesResource, PostMetricsResource, PostPreviewResource,
PostMediaAttachResource) keep controllers free of inline model mapping.
Suite: 1.332 passing, 0 failing — covers web (PostControllerTest), REST
(PostApiTest, PlatformApiTest, PostMediaApiTest), MCP (66 tool tests), and
the publish job (PublishToSocialPlatformTest).
Removes /docs from git tracking and TIKTOK_REVIEW_VIDEO_SCRIPT.md.
2026-05-04 11:12:28 +00:00
|
|
|
->where('scheduled_at', '2099-12-31 15:30:00')
|
2026-05-04 00:34:20 +00:00
|
|
|
->etc();
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-24 14:19:01 +00:00
|
|
|
$post = Post::where('workspace_id', $this->workspace->id)->first();
|
|
|
|
|
expect($post)->not->toBeNull();
|
|
|
|
|
expect($post->created_via)->toBe(CreatedVia::Mcp);
|
2026-05-04 00:34:20 +00:00
|
|
|
});
|
|
|
|
|
|
fix: keep post drafts unscheduled by default (#209)
* fix: keep post drafts unscheduled by default
* Align schedule validation and keep drafts unscheduled.
Require scheduled_at only when status is scheduled and the post has no
usable future schedule. Share that rule across web, API, and MCP, keep
create without a date as null, and preserve the legacy date → 09:00 UTC
fallback.
* Polish schedule validation typing and tests.
Type requiresExplicitSchedule status as ?string, reuse a local status
variable in request/tool validation, tighten the web reject assertion,
and collapse overlapping MCP unscheduled-create cases.
* Centralize status helper in post update validation.
Reuse the typed status() helper across FormRequests and the already-parsed
$status in UpdatePostTool so schedule checks stay consistent and less noisy.
* Share scheduled_at update rules across web, API, and MCP.
Centralize schedule validation in PostStatusRules, normalize status parsing
in one place, and align past-schedule coverage across entry points.
* Cover the full unscheduled-draft checklist in Pest.
Add feature coverage for null/past schedule rejection, explicit scheduling,
draft saves, publish-now without a schedule, calendar exclusion, and
09:00 UTC date defaults across web, API, and MCP.
* Remove normalizeStatus helper.
Keep the inline is_string check at the few call sites that read raw
request status before validation — no shared wrapper needed.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop is_string status guards from schedule validation.
Accept mixed status in PostStatusRules and rely on strict comparisons
with Rule::requiredIf / Rule::when — malformed input simply does not match.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Paulo Castellano <paulo@castellanos.llc>
2026-08-01 20:39:18 +00:00
|
|
|
test('create post creates unscheduled draft without a schedule', function (string $case) {
|
|
|
|
|
$payload = match ($case) {
|
|
|
|
|
'empty' => [],
|
|
|
|
|
'omitted' => [
|
|
|
|
|
'content' => 'Draft without schedule',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'null' => [
|
|
|
|
|
'content' => 'Draft without schedule',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],
|
|
|
|
|
],
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, $payload)
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json
|
|
|
|
|
->where('status', 'draft')
|
|
|
|
|
->where('scheduled_at', null)
|
|
|
|
|
->etc());
|
|
|
|
|
|
|
|
|
|
expect(Post::where('workspace_id', $this->workspace->id)
|
|
|
|
|
->latest('created_at')
|
|
|
|
|
->firstOrFail()
|
|
|
|
|
->scheduled_at)->toBeNull();
|
|
|
|
|
})->with([
|
|
|
|
|
'empty args' => ['empty'],
|
|
|
|
|
'omitted schedule' => ['omitted'],
|
|
|
|
|
'explicit null schedule' => ['null'],
|
|
|
|
|
]);
|
|
|
|
|
|
feat: complete create + publish post flow via MCP and REST API
Lets ChatGPT (MCP) and external clients (REST API) drive the full lifecycle of
a post — create with platform selection, attach media from URLs, schedule or
publish immediately, and fetch engagement metrics — without touching the web UI.
MCP tools added: UpdatePostTool, PublishPostTool, AttachMediaFromUrlTool,
ListContentTypesTool, GetPostMetricsTool, PreviewPostTool. CreatePostTool now
accepts platforms[] + scheduled_at + label_ids; ListPostsTool gains
status/search/limit filters.
REST endpoints added: POST /api/posts/{post}/media, GET /api/posts/{post}/metrics,
GET /api/posts/{post}/preview, GET /api/content-types.
Also fixes a silent CreatePost::execute bug — the action validated platforms[]
but ignored it, so REST callers never saw their selection persisted. Adds cross
validation rules (ContentTypeMatchesPlatform / ContentTypeMatchesPostPlatform)
so a LinkedIn account can't be saddled with x_post, and rejects inactive social
accounts during validation instead of failing silently downstream.
Shared services (PostMetricsFetcher, PostPreviewer, MediaAttacher) back both
MCP tools and REST controllers so behaviour stays aligned. New Resources
(PlatformContentTypesResource, PostMetricsResource, PostPreviewResource,
PostMediaAttachResource) keep controllers free of inline model mapping.
Suite: 1.332 passing, 0 failing — covers web (PostControllerTest), REST
(PostApiTest, PlatformApiTest, PostMediaApiTest), MCP (66 tool tests), and
the publish job (PublishToSocialPlatformTest).
Removes /docs from git tracking and TIKTOK_REVIEW_VIDEO_SCRIPT.md.
2026-05-04 11:12:28 +00:00
|
|
|
test('create post with platforms enables only those', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'content' => 'with platforms',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
|
|
|
|
|
$post = Post::where('workspace_id', $this->workspace->id)->first();
|
|
|
|
|
$enabled = $post->postPlatforms()->where('enabled', true)->get();
|
|
|
|
|
expect($enabled)->toHaveCount(1);
|
|
|
|
|
expect($enabled->first()->social_account_id)->toBe($this->socialAccount->id);
|
|
|
|
|
expect($enabled->first()->content_type->value)->toBe('linkedin_post');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create post rejects scheduled_at in the past', 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)
|
feat: complete create + publish post flow via MCP and REST API
Lets ChatGPT (MCP) and external clients (REST API) drive the full lifecycle of
a post — create with platform selection, attach media from URLs, schedule or
publish immediately, and fetch engagement metrics — without touching the web UI.
MCP tools added: UpdatePostTool, PublishPostTool, AttachMediaFromUrlTool,
ListContentTypesTool, GetPostMetricsTool, PreviewPostTool. CreatePostTool now
accepts platforms[] + scheduled_at + label_ids; ListPostsTool gains
status/search/limit filters.
REST endpoints added: POST /api/posts/{post}/media, GET /api/posts/{post}/metrics,
GET /api/posts/{post}/preview, GET /api/content-types.
Also fixes a silent CreatePost::execute bug — the action validated platforms[]
but ignored it, so REST callers never saw their selection persisted. Adds cross
validation rules (ContentTypeMatchesPlatform / ContentTypeMatchesPostPlatform)
so a LinkedIn account can't be saddled with x_post, and rejects inactive social
accounts during validation instead of failing silently downstream.
Shared services (PostMetricsFetcher, PostPreviewer, MediaAttacher) back both
MCP tools and REST controllers so behaviour stays aligned. New Resources
(PlatformContentTypesResource, PostMetricsResource, PostPreviewResource,
PostMediaAttachResource) keep controllers free of inline model mapping.
Suite: 1.332 passing, 0 failing — covers web (PostControllerTest), REST
(PostApiTest, PlatformApiTest, PostMediaApiTest), MCP (66 tool tests), and
the publish job (PublishToSocialPlatformTest).
Removes /docs from git tracking and TIKTOK_REVIEW_VIDEO_SCRIPT.md.
2026-05-04 11:12:28 +00:00
|
|
|
->tool(CreatePostTool::class, ['scheduled_at' => '2020-01-01T00:00:00Z']);
|
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
|
|
|
$response->assertHasErrors();
|
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 16:31:44 +00:00
|
|
|
test('create post rejects an inactive social account', function () {
|
|
|
|
|
$inactive = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
'is_active' => false,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $inactive->id, 'content_type' => 'linkedin_post'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create post rejects a content_type not in the enum', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'made_up_type'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-04 20:08:57 +00:00
|
|
|
test('create post rejects instagram_carousel — carousel is not a stored content_type', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'instagram_carousel'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post rejects instagram_carousel — carousel is not a stored content_type', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['id' => $platform->id, 'content_type' => 'instagram_carousel'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 16:31:44 +00:00
|
|
|
test('create post rejects a content_type that does not match the social account platform', function () {
|
|
|
|
|
// x_post on a LinkedIn account — ContentTypeMatchesPlatform should reject.
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'x_post'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create post rejects a label_id from another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$foreignLabel = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],
|
|
|
|
|
],
|
|
|
|
|
'label_ids' => [$foreignLabel->id],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('delete post 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
|
|
|
$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]);
|
|
|
|
|
|
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(Post::find($post->id))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-04 00:34:20 +00:00
|
|
|
test('delete post 404 from another workspace', 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
|
|
|
$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();
|
|
|
|
|
});
|
2026-06-10 18:36:47 +00:00
|
|
|
|
|
|
|
|
test('create post persists platform meta (aspect_ratio)', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post', 'meta' => ['aspect_ratio' => '4:5']],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
|
|
|
|
|
$platform = Post::where('workspace_id', $this->workspace->id)->first()
|
|
|
|
|
->postPlatforms()->where('social_account_id', $this->socialAccount->id)->first();
|
|
|
|
|
expect($platform->meta['aspect_ratio'])->toBe('4:5');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create post rejects an invalid aspect_ratio', function () {
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post', 'meta' => ['aspect_ratio' => '3:2']],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post rejects an invalid aspect_ratio', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['id' => $platform->id, 'meta' => ['aspect_ratio' => '3:2']],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertHasErrors();
|
|
|
|
|
});
|
2026-06-10 18:52:41 +00:00
|
|
|
|
|
|
|
|
test('create post returns the platform meta in the response (read-back)', function () {
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(CreatePostTool::class, [
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post', 'meta' => ['aspect_ratio' => '4:5']],
|
|
|
|
|
],
|
|
|
|
|
])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json->where('platforms.0.meta.aspect_ratio', '4:5')->etc());
|
|
|
|
|
});
|
|
|
|
|
|
fix: keep post drafts unscheduled by default (#209)
* fix: keep post drafts unscheduled by default
* Align schedule validation and keep drafts unscheduled.
Require scheduled_at only when status is scheduled and the post has no
usable future schedule. Share that rule across web, API, and MCP, keep
create without a date as null, and preserve the legacy date → 09:00 UTC
fallback.
* Polish schedule validation typing and tests.
Type requiresExplicitSchedule status as ?string, reuse a local status
variable in request/tool validation, tighten the web reject assertion,
and collapse overlapping MCP unscheduled-create cases.
* Centralize status helper in post update validation.
Reuse the typed status() helper across FormRequests and the already-parsed
$status in UpdatePostTool so schedule checks stay consistent and less noisy.
* Share scheduled_at update rules across web, API, and MCP.
Centralize schedule validation in PostStatusRules, normalize status parsing
in one place, and align past-schedule coverage across entry points.
* Cover the full unscheduled-draft checklist in Pest.
Add feature coverage for null/past schedule rejection, explicit scheduling,
draft saves, publish-now without a schedule, calendar exclusion, and
09:00 UTC date defaults across web, API, and MCP.
* Remove normalizeStatus helper.
Keep the inline is_string check at the few call sites that read raw
request status before validation — no shared wrapper needed.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Drop is_string status guards from schedule validation.
Accept mixed status in PostStatusRules and rely on strict comparisons
with Rule::requiredIf / Rule::when — malformed input simply does not match.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Paulo Castellano <paulo@castellanos.llc>
2026-08-01 20:39:18 +00:00
|
|
|
test('update post rejects scheduled status without a future scheduled_at', function (?string $existingScheduledAt) {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'scheduled_at' => $existingScheduledAt,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors();
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => now()->subHour()->toIso8601String(),
|
|
|
|
|
])
|
|
|
|
|
->assertHasErrors();
|
|
|
|
|
|
|
|
|
|
expect($post->fresh()->status->value)->toBe('draft');
|
|
|
|
|
})->with([
|
|
|
|
|
'missing schedule' => [null],
|
|
|
|
|
'past schedule' => [now()->subDay()->toDateTimeString()],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
test('update post accepts scheduled status reusing an existing future scheduled_at', function () {
|
|
|
|
|
$scheduledAt = now()->addDay()->startOfSecond();
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'scheduled_at' => $scheduledAt,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json
|
|
|
|
|
->where('status', 'scheduled')
|
|
|
|
|
->etc());
|
|
|
|
|
|
|
|
|
|
expect($post->fresh()->scheduled_at->toDateTimeString())->toBe($scheduledAt->toDateTimeString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post schedules an unscheduled draft with an explicit future scheduled_at', function () {
|
|
|
|
|
$scheduledAt = now()->addDay()->startOfSecond();
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => $scheduledAt->toIso8601String(),
|
|
|
|
|
])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json
|
|
|
|
|
->where('status', 'scheduled')
|
|
|
|
|
->etc());
|
|
|
|
|
|
|
|
|
|
expect($post->fresh()->scheduled_at->toDateTimeString())->toBe($scheduledAt->toDateTimeString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post keeps an unscheduled draft when saving as draft without scheduled_at', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
'content' => 'Original',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'content' => 'Still a draft',
|
|
|
|
|
])
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertStructuredContent(fn (AssertableJson $json) => $json
|
|
|
|
|
->where('status', 'draft')
|
|
|
|
|
->where('scheduled_at', null)
|
|
|
|
|
->etc());
|
|
|
|
|
|
|
|
|
|
expect($post->fresh()->scheduled_at)->toBeNull()
|
|
|
|
|
->and($post->fresh()->content)->toBe('Still a draft');
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-10 18:52:41 +00:00
|
|
|
test('update post accepts a valid aspect_ratio and persists it', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
TryPostServer::actingAs($this->user)
|
|
|
|
|
->tool(UpdatePostTool::class, [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['id' => $platform->id, 'meta' => ['aspect_ratio' => '16:9']],
|
|
|
|
|
],
|
|
|
|
|
])
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
expect($platform->fresh()->meta['aspect_ratio'])->toBe('16:9');
|
|
|
|
|
});
|