2026-01-18 23:33:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-07-24 14:19:01 +00:00
|
|
|
use App\Enums\Post\CreatedVia;
|
2026-01-18 23:33:45 +00:00
|
|
|
use App\Enums\Post\Status as PostStatus;
|
|
|
|
|
use App\Enums\PostPlatform\ContentType;
|
2026-05-02 15:22:42 +00:00
|
|
|
use App\Enums\PostPlatform\Status;
|
2026-01-18 23:33:45 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
fix(facebook): empty-message rejection + state consistency + no re-publish on terminal
Production incident: a customer's Facebook Page post failed with 'The post
is empty. Please enter a message to share.' (error code 197) and ended up
with a contradictory DB state (status=published + error_message=set).
Three independent bugs were uncovered:
A. FacebookPublisher sends 'message'/'description' as null when the user
posts media without text. Graph API requires the key be omitted, not
null. Fixed in publishSingleImagePost, publishMultiImagePost,
publishVideoPost, publishReel.
B. markAsPublished/markAsFailed leak stale fields across transitions
(a published row could retain error_message from a prior failure,
vice-versa). Both transitions now explicitly clear the opposite
side's fields.
C. status='failed' was editable in the UI and the backend, so users
were re-clicking Publish, generating duplicate failure emails and
the contradictory state from bug B. The frontend isReadOnly check
and the UpdatePost backend guard now treat Published/PartiallyPublished/
Failed/Publishing as terminal. To retry, the user duplicates the post.
11 new tests guarantee these can't regress silently: FB payload shape
per content type, PostPlatform field-clearing on transitions, and the
terminal-status block at the controller level.
2026-05-15 16:01:49 +00:00
|
|
|
use App\Jobs\PublishPost;
|
2026-01-18 23:33:45 +00:00
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
2026-01-26 18:18:35 +00:00
|
|
|
use App\Models\WorkspaceLabel;
|
Defuse links in X posts to avoid the link-post fee (#308)
X bills a post containing a URL at a much higher rate than a plain post, and
its algorithm demotes link posts. The X version of a post now rewrites every
URL non-clickable (https://example.com/post becomes example(.)com/post):
scheme and www. dropped, every dot of the host replaced with (.).
Leaving a single dot intact would still leave a resolvable domain for X to
detect, so all of them are broken. A scheme or www. proves a token is a URL on
its own; a bare host only counts when its last label is a delegated TLD, which
is the one thing telling acme.com apart from Node.js. That check runs against
App\Support\LinkTlds, generated from the whole IANA root zone in every form a
TLD can appear in a post -- ASCII, punycode and the Unicode it decodes to --
because whatever X links is what X bills, so a hand-picked subset would leave
us paying for its gaps. If the regex engine bails out on pathological input the
original content is returned instead of crashing the publisher.
The transform lives in the Platform::X arm of ContentSanitizer, so it reaches
publishing and the app/API/MCP previews from one place and cannot touch any
other network. Off by default; opt in with X_DEFUSE_LINKS.
The editor counts characters and renders its preview client-side and cannot ask
the server on every keystroke, so the rewrite is mirrored in TypeScript. PHP
stays the source of truth: a parity test fails if the two TLD sets drift, and a
browser test drives the real editor so the mirror is covered rather than
assumed. Without it the composer promised text the network never receives.
Character limits now measure the text a reader will see: sanitized, then with
markup resolved away. Measuring the raw draft blocked saving posts that publish
fine and let through posts the network rejects, and counted the editor's HTML
toward the limit. Measuring the sanitized form alone would have counted
Telegram's escaped entities, rejecting messages Telegram accepts.
Empty content is handled once inside the sanitizer instead of by a guard
repeated at every call site.
2026-08-29 18:31:05 +00:00
|
|
|
use App\Support\LinkTlds;
|
|
|
|
|
use Illuminate\Support\Collection;
|
fix(facebook): empty-message rejection + state consistency + no re-publish on terminal
Production incident: a customer's Facebook Page post failed with 'The post
is empty. Please enter a message to share.' (error code 197) and ended up
with a contradictory DB state (status=published + error_message=set).
Three independent bugs were uncovered:
A. FacebookPublisher sends 'message'/'description' as null when the user
posts media without text. Graph API requires the key be omitted, not
null. Fixed in publishSingleImagePost, publishMultiImagePost,
publishVideoPost, publishReel.
B. markAsPublished/markAsFailed leak stale fields across transitions
(a published row could retain error_message from a prior failure,
vice-versa). Both transitions now explicitly clear the opposite
side's fields.
C. status='failed' was editable in the UI and the backend, so users
were re-clicking Publish, generating duplicate failure emails and
the contradictory state from bug B. The frontend isReadOnly check
and the UpdatePost backend guard now treat Published/PartiallyPublished/
Failed/Publishing as terminal. To retry, the user duplicates the post.
11 new tests guarantee these can't regress silently: FB payload shape
per content type, PostPlatform field-clearing on transitions, and the
terminal-status block at the controller level.
2026-05-15 16:01:49 +00:00
|
|
|
use Illuminate\Support\Facades\Bus;
|
2026-05-02 15:22:42 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
feat: PostPlatform enum, failure email, DB indexes, rate limiting, tests
Publishing improvements:
- Create PostPlatformStatus enum (Pending, Publishing, Published, Failed)
- Update PostPlatform model, jobs, factories to use enum
- Add PostPublishFailed email notification when post fails to publish
- Maizzle template + blade for failure email with platform details
- PublishPost job: add $tries=3, $backoff=30, failed() method
- Fix broadcast event to serialize enum status value
Security:
- Add rate limiting (throttle:6,1) on social connect endpoints
- Fix MediaController::reorder IDOR vulnerability
- Fix Connect.vue broken import (storeStep2 -> storeConnect)
- Fix UpdatePost data_get() consistency
Database:
- Add composite index on post_platforms (post_id, enabled)
- Add index on post_platforms (social_account_id)
Tests:
- Add 3 tests for profile photo upload/delete
- Add 2 tests for media reorder (including IDOR check)
- Fix publish tests for PostPlatformStatus enum
- Add Mail::fake() to publish tests
Cleanup:
- Remove unused AppHeader.vue and AppHeaderLayout.vue
- Remove dead BillingController methods
All 733 tests passing.
2026-03-30 19:11:38 +00:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2026-04-17 02:05:51 +00:00
|
|
|
$this->user = User::factory()->create([]);
|
2026-01-18 23:33:45 +00:00
|
|
|
$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]);
|
2026-01-18 23:33:45 +00:00
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$this->socialAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Index tests
|
|
|
|
|
test('posts index requires authentication', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->get(route('app.posts.index'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('posts index shows posts for current workspace', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Index', false)
|
|
|
|
|
->has('posts.data', 1)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
feat(posts): multi-select label filter on the posts list
Adds a combobox-style filter to the posts index toolbar so users can
narrow All / Scheduled / Posted / Drafts views by one or more labels.
- `PostController::index` accepts `?labels[]=<id>` and applies
`whereHas('labels', whereIn(...))` (OR semantics across selected labels).
Workspace labels are exposed to the page (sorted by name) and the
selected set comes back under `filters.labels`.
- New `LabelFilter.vue` component reuses the existing Popover + Command
pattern (matching `FontPicker` in the Brand settings page). Trigger
renders the selected `LabelBadge`s inline (mirroring how each post row
already displays its labels): 1-3 shown directly, 4+ shown as the
first three plus a "+N" overflow indicator. Clear button has a
tooltip and `cursor-pointer`, and stops `click`/`pointerdown`/
`mousedown` so it doesn't reopen the Popover.
- Existing search debounce is shared with the new label watcher via a
single `buildFilterUrl` helper. URL is updated with `preserveState +
replace` so the back stack stays clean.
- i18n in en / pt-BR / es: `filter_by_label`, `label_search_placeholder`,
`no_labels`, `clear_label_filter`.
Tests: 4 new index tests covering the labels prop exposure, single-label
filter, multi-label OR filter, and blank-id sanitization. Full suite:
1509 passed, 2 skipped, 0 failed.
2026-05-14 12:57:55 +00:00
|
|
|
test('posts index exposes workspace labels for filter dropdown', function () {
|
|
|
|
|
WorkspaceLabel::factory()->count(3)->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
WorkspaceLabel::factory()->create(); // belongs to a different workspace; must not leak.
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('labels', 3)
|
|
|
|
|
->where('filters.labels', [])
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('posts index filters posts by a single label id', function () {
|
|
|
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$taggedPost = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$taggedPost->labels()->attach($label);
|
|
|
|
|
|
|
|
|
|
Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.index', ['labels' => [$label->id]]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 1)
|
|
|
|
|
->where('posts.data.0.id', $taggedPost->id)
|
|
|
|
|
->where('filters.labels', [$label->id])
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('posts index filters posts by multiple labels (OR semantics)', function () {
|
|
|
|
|
$marketing = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$sales = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$unrelated = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$postWithMarketing = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$postWithMarketing->labels()->attach($marketing);
|
|
|
|
|
|
|
|
|
|
$postWithSales = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$postWithSales->labels()->attach($sales);
|
|
|
|
|
|
|
|
|
|
$postWithUnrelated = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$postWithUnrelated->labels()->attach($unrelated);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.index', ['labels' => [$marketing->id, $sales->id]]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 2)
|
|
|
|
|
->where('filters.labels', [$marketing->id, $sales->id])
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('posts index ignores blank label query params', function () {
|
|
|
|
|
Post::factory()->count(2)->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.index', ['labels' => ['']]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->has('posts.data', 2)
|
|
|
|
|
->where('filters.labels', [])
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 23:33:45 +00:00
|
|
|
test('posts index redirects to create workspace if no workspace', function () {
|
|
|
|
|
$this->user->update(['current_workspace_id' => null]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.index'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.workspaces.create'));
|
2026-01-18 23:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Calendar tests
|
|
|
|
|
test('calendar requires authentication', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->get(route('app.calendar'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('calendar shows posts for current week', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.calendar'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Calendar')
|
|
|
|
|
->has('workspace')
|
|
|
|
|
->has('posts')
|
|
|
|
|
->has('currentWeekStart')
|
|
|
|
|
->has('view')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('calendar supports month view', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.calendar', ['view' => 'month']));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->where('view', 'month')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-02 12:12:14 +00:00
|
|
|
test('calendar payload exposes post content for rendering', function () {
|
|
|
|
|
$scheduledAt = now('UTC')->startOfWeek()->addDays(2)->setTime(12, 0);
|
|
|
|
|
|
|
|
|
|
Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'content' => 'Caption visible in the calendar',
|
|
|
|
|
'status' => PostStatus::Scheduled,
|
|
|
|
|
'scheduled_at' => $scheduledAt,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$dateKey = $scheduledAt->format('Y-m-d');
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.calendar'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->where("posts.{$dateKey}.0.content", 'Caption visible in the calendar')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
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('calendar does not include unscheduled drafts', function () {
|
|
|
|
|
$scheduledAt = now('UTC')->startOfWeek()->addDays(2)->setTime(12, 0);
|
|
|
|
|
|
|
|
|
|
Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'content' => 'Unscheduled draft stays off the calendar',
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'content' => 'Scheduled post appears on the calendar',
|
|
|
|
|
'status' => PostStatus::Scheduled,
|
|
|
|
|
'scheduled_at' => $scheduledAt,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$dateKey = $scheduledAt->format('Y-m-d');
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.calendar'))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertInertia(fn ($page) => $page
|
|
|
|
|
->has("posts.{$dateKey}", 1)
|
|
|
|
|
->where("posts.{$dateKey}.0.content", 'Scheduled post appears on the calendar')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-03 12:36:50 +00:00
|
|
|
// Create tests
|
|
|
|
|
test('create requires authentication', function () {
|
|
|
|
|
$response = $this->get(route('app.posts.create'));
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create renders the wizard page', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.create'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Create', false)
|
|
|
|
|
->where('date', null)
|
|
|
|
|
->has('socialAccounts', 1)
|
|
|
|
|
->where('socialAccounts.0.id', $this->socialAccount->id)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create forwards date query param to the page', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.create', ['date' => '2026-06-01']));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Create', false)
|
|
|
|
|
->where('date', '2026-06-01')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create redirects to workspaces.create when user has no workspace', function () {
|
|
|
|
|
$newUser = User::factory()->create();
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($newUser)->get(route('app.posts.create'));
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('app.workspaces.create'));
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-22 01:08:18 +00:00
|
|
|
// Store tests
|
|
|
|
|
test('store post requires authentication', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->post(route('app.posts.store'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-22 01:08:18 +00:00
|
|
|
test('store post redirects to accounts if no social accounts connected', function () {
|
2026-01-18 23:33:45 +00:00
|
|
|
$this->socialAccount->delete();
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->post(route('app.posts.store'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.accounts'));
|
2026-01-18 23:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
2026-01-22 01:08:18 +00:00
|
|
|
test('store post creates draft and redirects to edit', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->post(route('app.posts.store'));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post = Post::where('workspace_id', $this->workspace->id)->first();
|
|
|
|
|
expect($post)->not->toBeNull();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Draft);
|
2026-07-24 14:19:01 +00:00
|
|
|
expect($post->created_via)->toBe(CreatedVia::Web);
|
2026-01-18 23:33:45 +00:00
|
|
|
expect($post->postPlatforms)->toHaveCount(1);
|
|
|
|
|
});
|
|
|
|
|
|
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('store post leaves scheduled_at null when no date is provided', function () {
|
2026-05-06 20:21:30 +00:00
|
|
|
$this->actingAs($this->user)->post(route('app.posts.store'))->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post = Post::where('workspace_id', $this->workspace->id)->first();
|
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
|
|
|
expect($post->scheduled_at)->toBeNull();
|
2026-05-06 20:21:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('store post schedules draft on the date param when provided', function () {
|
|
|
|
|
$this->actingAs($this->user)->post(route('app.posts.store'), [
|
|
|
|
|
'date' => '2026-06-15',
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post = Post::where('workspace_id', $this->workspace->id)->first();
|
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
|
|
|
expect($post->scheduled_at->utc()->format('Y-m-d H:i:s'))->toBe('2026-06-15 09:00:00');
|
2026-05-06 20:21:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('store post rejects invalid date format', function () {
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->post(route('app.posts.store'), ['date' => 'not-a-date'])
|
|
|
|
|
->assertSessionHasErrors(['date']);
|
|
|
|
|
|
|
|
|
|
expect(Post::where('workspace_id', $this->workspace->id)->count())->toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 23:33:45 +00:00
|
|
|
// Edit tests
|
|
|
|
|
test('edit post requires authentication', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->get(route('app.posts.edit', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('edit post shows edit page', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.edit', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Edit')
|
|
|
|
|
->has('post')
|
|
|
|
|
->has('socialAccounts')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
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('edit exposes null scheduled_at for an unscheduled draft', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.edit', $post))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Edit')
|
|
|
|
|
->where('post.scheduled_at', null)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 23:33:45 +00:00
|
|
|
test('edit post returns 404 for post from different workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.edit', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-02 15:22:42 +00:00
|
|
|
test('edit redirects to show for non-editable statuses', function () {
|
fix(facebook): empty-message rejection + state consistency + no re-publish on terminal
Production incident: a customer's Facebook Page post failed with 'The post
is empty. Please enter a message to share.' (error code 197) and ended up
with a contradictory DB state (status=published + error_message=set).
Three independent bugs were uncovered:
A. FacebookPublisher sends 'message'/'description' as null when the user
posts media without text. Graph API requires the key be omitted, not
null. Fixed in publishSingleImagePost, publishMultiImagePost,
publishVideoPost, publishReel.
B. markAsPublished/markAsFailed leak stale fields across transitions
(a published row could retain error_message from a prior failure,
vice-versa). Both transitions now explicitly clear the opposite
side's fields.
C. status='failed' was editable in the UI and the backend, so users
were re-clicking Publish, generating duplicate failure emails and
the contradictory state from bug B. The frontend isReadOnly check
and the UpdatePost backend guard now treat Published/PartiallyPublished/
Failed/Publishing as terminal. To retry, the user duplicates the post.
11 new tests guarantee these can't regress silently: FB payload shape
per content type, PostPlatform field-clearing on transitions, and the
terminal-status block at the controller level.
2026-05-15 16:01:49 +00:00
|
|
|
foreach ([PostStatus::Published, PostStatus::PartiallyPublished, PostStatus::Publishing, PostStatus::Failed] as $status) {
|
2026-05-02 15:22:42 +00:00
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => $status,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.edit', $post))
|
|
|
|
|
->assertRedirect(route('app.posts.show', $post));
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-01-18 23:33:45 +00:00
|
|
|
|
fix(facebook): empty-message rejection + state consistency + no re-publish on terminal
Production incident: a customer's Facebook Page post failed with 'The post
is empty. Please enter a message to share.' (error code 197) and ended up
with a contradictory DB state (status=published + error_message=set).
Three independent bugs were uncovered:
A. FacebookPublisher sends 'message'/'description' as null when the user
posts media without text. Graph API requires the key be omitted, not
null. Fixed in publishSingleImagePost, publishMultiImagePost,
publishVideoPost, publishReel.
B. markAsPublished/markAsFailed leak stale fields across transitions
(a published row could retain error_message from a prior failure,
vice-versa). Both transitions now explicitly clear the opposite
side's fields.
C. status='failed' was editable in the UI and the backend, so users
were re-clicking Publish, generating duplicate failure emails and
the contradictory state from bug B. The frontend isReadOnly check
and the UpdatePost backend guard now treat Published/PartiallyPublished/
Failed/Publishing as terminal. To retry, the user duplicates the post.
11 new tests guarantee these can't regress silently: FB payload shape
per content type, PostPlatform field-clearing on transitions, and the
terminal-status block at the controller level.
2026-05-15 16:01:49 +00:00
|
|
|
test('edit allows draft and scheduled posts', function () {
|
|
|
|
|
foreach ([PostStatus::Draft, PostStatus::Scheduled] as $status) {
|
2026-05-02 15:22:42 +00:00
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => $status,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.edit', $post))
|
|
|
|
|
->assertOk();
|
|
|
|
|
}
|
2026-01-18 23:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Update tests
|
|
|
|
|
test('update post requires authentication', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->put(route('app.posts.update', $post), []);
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post saves changes', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
2026-04-15 23:11:36 +00:00
|
|
|
'content' => 'Original content',
|
2026-01-18 23:33:45 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'status' => 'draft',
|
2026-04-15 23:11:36 +00:00
|
|
|
'content' => 'Updated content',
|
2026-01-18 23:33:45 +00:00
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->content)->toBe('Updated content');
|
2026-01-18 23:33:45 +00:00
|
|
|
$postPlatform->refresh();
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
expect($postPlatform->content_type)->toBe(ContentType::LinkedInPost);
|
2026-01-18 23:33:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post cannot update published posts', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Published,
|
|
|
|
|
]);
|
|
|
|
|
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'status' => 'draft',
|
2026-04-15 23:11:36 +00:00
|
|
|
'content' => 'Test content',
|
fix: overhaul social publishing — validation, uploads, token refresh
- Fix UpdatePostRequest missing content_type, synced, meta fields
(content_type was silently dropped, causing Instagram Reels to post as Feed)
- Create API FormRequests (StorePostRequest, UpdatePostRequest) replacing inline validation
- Fix syntax errors in all publishers ($media->isVideo() missing variable)
- Fix Instagram Feed with single video calling publishSingleImage instead of publishReel
- Fix TikTok hardcoded SELF_ONLY privacy — now queries creator_info API
- Refactor YouTubePublisher to use google/apiclient SDK with chunked resumable upload
- Fix all publishers using file_get_contents for large videos (memory overflow)
— X, LinkedIn, LinkedInPage, Pinterest, Bluesky, Mastodon now use temp file + stream
- Fix Media::isVideo/isImage to use mime_type instead of extension
- Fix Threads not saving refresh_token (was null, now saves access_token)
- Add Instagram token refresh to publisher and ConnectionVerifier
- Fix PublishToSocialPlatform job: tries 3→1 (prevents duplicate uploads),
timeout 60→600s, added failed() method for cleanup
- Increase Horizon worker timeout 60→630s, Redis retry_after 90→660s
- Increase upload limit 500MB→1GB
- Add mastodon to getDefaultContentType in Edit.vue
2026-03-31 22:25:19 +00:00
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
2026-01-18 23:33:45 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
});
|
|
|
|
|
|
fix(facebook): empty-message rejection + state consistency + no re-publish on terminal
Production incident: a customer's Facebook Page post failed with 'The post
is empty. Please enter a message to share.' (error code 197) and ended up
with a contradictory DB state (status=published + error_message=set).
Three independent bugs were uncovered:
A. FacebookPublisher sends 'message'/'description' as null when the user
posts media without text. Graph API requires the key be omitted, not
null. Fixed in publishSingleImagePost, publishMultiImagePost,
publishVideoPost, publishReel.
B. markAsPublished/markAsFailed leak stale fields across transitions
(a published row could retain error_message from a prior failure,
vice-versa). Both transitions now explicitly clear the opposite
side's fields.
C. status='failed' was editable in the UI and the backend, so users
were re-clicking Publish, generating duplicate failure emails and
the contradictory state from bug B. The frontend isReadOnly check
and the UpdatePost backend guard now treat Published/PartiallyPublished/
Failed/Publishing as terminal. To retry, the user duplicates the post.
11 new tests guarantee these can't regress silently: FB payload shape
per content type, PostPlatform field-clearing on transitions, and the
terminal-status block at the controller level.
2026-05-15 16:01:49 +00:00
|
|
|
test('cannot re-publish a failed post', function () {
|
|
|
|
|
Bus::fake();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Failed,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'publishing',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Failed);
|
|
|
|
|
Bus::assertNotDispatched(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot update a post in publishing state', function () {
|
|
|
|
|
Bus::fake();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Publishing,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Publishing);
|
|
|
|
|
Bus::assertNotDispatched(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot update a partially published post', function () {
|
|
|
|
|
Bus::fake();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::PartiallyPublished,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'publishing',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::PartiallyPublished);
|
|
|
|
|
Bus::assertNotDispatched(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot update a published post', function () {
|
|
|
|
|
Bus::fake();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Published,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'publishing',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Published);
|
|
|
|
|
Bus::assertNotDispatched(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-26 19:01:14 +00:00
|
|
|
test('publish now updates scheduled_at to current time', function () {
|
feat: PostPlatform enum, failure email, DB indexes, rate limiting, tests
Publishing improvements:
- Create PostPlatformStatus enum (Pending, Publishing, Published, Failed)
- Update PostPlatform model, jobs, factories to use enum
- Add PostPublishFailed email notification when post fails to publish
- Maizzle template + blade for failure email with platform details
- PublishPost job: add $tries=3, $backoff=30, failed() method
- Fix broadcast event to serialize enum status value
Security:
- Add rate limiting (throttle:6,1) on social connect endpoints
- Fix MediaController::reorder IDOR vulnerability
- Fix Connect.vue broken import (storeStep2 -> storeConnect)
- Fix UpdatePost data_get() consistency
Database:
- Add composite index on post_platforms (post_id, enabled)
- Add index on post_platforms (social_account_id)
Tests:
- Add 3 tests for profile photo upload/delete
- Add 2 tests for media reorder (including IDOR check)
- Fix publish tests for PostPlatformStatus enum
- Add Mail::fake() to publish tests
Cleanup:
- Remove unused AppHeader.vue and AppHeaderLayout.vue
- Remove dead BillingController methods
All 733 tests passing.
2026-03-30 19:11:38 +00:00
|
|
|
Mail::fake();
|
2026-01-26 19:01:14 +00:00
|
|
|
$this->freezeTime();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
2026-04-15 23:11:36 +00:00
|
|
|
'content' => 'Test content',
|
2026-01-26 19:01:14 +00:00
|
|
|
'scheduled_at' => now()->addDays(7),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-26 19:01:14 +00:00
|
|
|
'status' => 'publishing',
|
2026-04-15 23:11:36 +00:00
|
|
|
'content' => 'Test content',
|
2026-01-26 19:01:14 +00:00
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->scheduled_at->toDateTimeString())->toBe(now()->toDateTimeString());
|
|
|
|
|
});
|
|
|
|
|
|
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('publish now is allowed when the draft has no scheduled_at', function () {
|
|
|
|
|
Bus::fake();
|
|
|
|
|
$this->freezeTime();
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'publishing',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Publishing)
|
|
|
|
|
->and($post->scheduled_at->toDateTimeString())->toBe(now()->toDateTimeString());
|
|
|
|
|
Bus::assertDispatched(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update 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,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => $existingScheduledAt,
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$payload = [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->put(route('app.posts.update', $post), $payload)
|
|
|
|
|
->assertSessionHasErrors('scheduled_at');
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->put(route('app.posts.update', $post), [
|
|
|
|
|
...$payload,
|
|
|
|
|
'scheduled_at' => now()->subHour()->toIso8601String(),
|
|
|
|
|
])
|
|
|
|
|
->assertSessionHasErrors('scheduled_at');
|
|
|
|
|
|
|
|
|
|
expect($post->fresh()->status)->toBe(PostStatus::Draft);
|
|
|
|
|
})->with([
|
|
|
|
|
'missing schedule' => [null],
|
|
|
|
|
'past schedule' => [now()->subDay()->toDateTimeString()],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
test('update 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,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => $scheduledAt,
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Scheduled)
|
|
|
|
|
->and($post->scheduled_at->toDateTimeString())->toBe($scheduledAt->toDateTimeString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update 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,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => $scheduledAt->toIso8601String(),
|
|
|
|
|
'content' => 'Test content',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Scheduled)
|
|
|
|
|
->and($post->scheduled_at->toDateTimeString())->toBe($scheduledAt->toDateTimeString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update 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,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'scheduled_at' => null,
|
|
|
|
|
'content' => 'Original',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'content' => 'Still a draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->status)->toBe(PostStatus::Draft)
|
|
|
|
|
->and($post->scheduled_at)->toBeNull()
|
|
|
|
|
->and($post->content)->toBe('Still a draft');
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 23:33:45 +00:00
|
|
|
// Destroy tests
|
|
|
|
|
test('destroy post requires authentication', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->delete(route('app.posts.destroy', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-01 18:04:13 +00:00
|
|
|
test('destroy post deletes the post and redirects to posts index', function () {
|
2026-01-18 23:33:45 +00:00
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-22 01:08:18 +00:00
|
|
|
$response = $this->actingAs($this->user)
|
2026-03-29 22:24:28 +00:00
|
|
|
->delete(route('app.posts.destroy', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
2026-04-01 18:04:13 +00:00
|
|
|
$response->assertRedirect(route('app.posts.index'));
|
2026-01-18 23:33:45 +00:00
|
|
|
expect(Post::find($post->id))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-01 18:04:13 +00:00
|
|
|
test('destroy post with redirect param redirects to calendar', function () {
|
2026-01-26 17:00:37 +00:00
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
2026-04-01 18:04:13 +00:00
|
|
|
->delete(route('app.posts.destroy', $post).'?redirect=app.calendar');
|
2026-01-26 17:00:37 +00:00
|
|
|
|
2026-04-01 18:04:13 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-26 17:00:37 +00:00
|
|
|
expect(Post::find($post->id))->toBeNull();
|
2026-04-01 18:04:13 +00:00
|
|
|
});
|
2026-01-26 17:00:37 +00:00
|
|
|
|
|
|
|
|
test('destroy post with redirect param redirects to specified route', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
2026-03-29 22:24:28 +00:00
|
|
|
->delete(route('app.posts.destroy', $post).'?redirect=app.posts.index');
|
2026-01-26 17:00:37 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.posts.index'));
|
2026-01-26 17:00:37 +00:00
|
|
|
expect(Post::find($post->id))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 23:33:45 +00:00
|
|
|
test('destroy post returns 404 for post from different workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->delete(route('app.posts.destroy', $post));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertNotFound();
|
|
|
|
|
});
|
2026-01-26 18:18:35 +00:00
|
|
|
|
|
|
|
|
// Label tests
|
|
|
|
|
test('edit post includes workspace labels', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$label = WorkspaceLabel::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'name' => 'Marketing',
|
|
|
|
|
'color' => '#FF0000',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.edit', $post));
|
2026-01-26 18:18:35 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Edit')
|
|
|
|
|
->has('labels', 1)
|
|
|
|
|
->where('labels.0.name', 'Marketing')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post can attach labels', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$label = WorkspaceLabel::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-26 18:18:35 +00:00
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'label_ids' => [$label->id],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->labels)->toHaveCount(1);
|
|
|
|
|
expect($post->labels->first()->id)->toBe($label->id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post can detach labels', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$label = WorkspaceLabel::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post->labels()->attach($label);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-26 18:18:35 +00:00
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'label_ids' => [],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->labels)->toHaveCount(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post can sync multiple labels', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$label1 = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$label2 = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$label3 = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
// Attach initial label
|
|
|
|
|
$post->labels()->attach($label1);
|
|
|
|
|
|
|
|
|
|
// Update with different labels
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-26 18:18:35 +00:00
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'label_ids' => [$label2->id, $label3->id],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$post->refresh();
|
|
|
|
|
expect($post->labels)->toHaveCount(2);
|
|
|
|
|
expect($post->labels->pluck('id')->toArray())->toEqualCanonicalizing([$label2->id, $label3->id]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-02 15:22:42 +00:00
|
|
|
test('platform metrics returns unsupported when post not published', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$pp = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
'status' => Status::Pending,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->getJson(route('app.posts.platforms.metrics', ['post' => $post->id, 'postPlatform' => $pp->id]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJson(['unsupported' => true, 'reason' => 'not_published']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('platform metrics returns 404 for post in another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$otherPost = Post::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
$pp = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $otherPost->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->getJson(route('app.posts.platforms.metrics', ['post' => $otherPost->id, 'postPlatform' => $pp->id]))
|
|
|
|
|
->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('platform metrics returns 404 when post platform belongs to different post', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$otherPost = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$pp = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $otherPost->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->getJson(route('app.posts.platforms.metrics', ['post' => $post->id, 'postPlatform' => $pp->id]))
|
|
|
|
|
->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('platform metrics dispatches X analytics for X platform', function () {
|
|
|
|
|
$xAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::X,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$pp = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $xAccount->id,
|
|
|
|
|
'platform' => Platform::X,
|
|
|
|
|
'status' => Status::Published,
|
|
|
|
|
'platform_post_id' => '1234567890',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://api.x.com/2/tweets/1234567890*' => Http::response([
|
|
|
|
|
'data' => [
|
|
|
|
|
'public_metrics' => [
|
|
|
|
|
'impression_count' => 500,
|
|
|
|
|
'like_count' => 42,
|
|
|
|
|
'retweet_count' => 7,
|
|
|
|
|
'reply_count' => 3,
|
|
|
|
|
'quote_count' => 1,
|
|
|
|
|
'bookmark_count' => 4,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->getJson(route('app.posts.platforms.metrics', ['post' => $post->id, 'postPlatform' => $pp->id]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonFragment(['label' => 'Impressions', 'value' => 500]);
|
|
|
|
|
$response->assertJsonFragment(['label' => 'Likes', 'value' => 42]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('show page renders for non-editable posts', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Published,
|
|
|
|
|
'content' => 'Hello world',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
'enabled' => true,
|
|
|
|
|
'platform_url' => 'https://linkedin.com/posts/abc',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.posts.show', $post));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Show', false)
|
2026-05-04 01:11:58 +00:00
|
|
|
->has('post.platforms', 1)
|
2026-05-02 15:22:42 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('show page redirects editable posts to edit', function () {
|
2026-05-19 17:18:13 +00:00
|
|
|
foreach ([PostStatus::Draft, PostStatus::Scheduled] as $status) {
|
2026-05-02 15:22:42 +00:00
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => $status,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.show', $post))
|
|
|
|
|
->assertRedirect(route('app.posts.edit', $post));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-19 17:18:13 +00:00
|
|
|
test('failed posts render show without redirecting to edit', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Failed,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.show', $post))
|
|
|
|
|
->assertOk();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-02 15:22:42 +00:00
|
|
|
test('destroy blocks published posts', function () {
|
|
|
|
|
foreach ([PostStatus::Publishing, PostStatus::Published, PostStatus::PartiallyPublished] as $status) {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => $status,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->delete(route('app.posts.destroy', $post))
|
|
|
|
|
->assertRedirect();
|
|
|
|
|
|
|
|
|
|
expect(Post::find($post->id))->not->toBeNull();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('show page returns 404 for post in another workspace', function () {
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.show', $post))
|
|
|
|
|
->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post redirects to show page after publishing', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'content' => 'Test',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'publishing',
|
|
|
|
|
'content' => 'Test',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['id' => $postPlatform->id, 'content_type' => ContentType::LinkedInPost->value],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('app.posts.show', $post));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post rejects scheduling youtube short with image', function () {
|
|
|
|
|
$youtubeAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::YouTube,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'content' => 'Test',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $youtubeAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => now()->addDay()->toIso8601String(),
|
|
|
|
|
'media' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => 'media-1',
|
|
|
|
|
'path' => 'media/foo.jpg',
|
|
|
|
|
'url' => 'https://example.com/foo.jpg',
|
|
|
|
|
'type' => 'image',
|
|
|
|
|
'mime_type' => 'image/jpeg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::YouTubeShort->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors('platforms.0.content_type');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post rejects scheduling instagram reel with no media', function () {
|
|
|
|
|
$instagramAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::Instagram,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'content' => 'Test',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $instagramAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => now()->addDay()->toIso8601String(),
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::InstagramReel->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors('platforms.0.content_type');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post rejects invalid instagram aspect_ratio meta', function () {
|
|
|
|
|
$instagramAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::Instagram,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $instagramAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::InstagramFeed->value,
|
|
|
|
|
'meta' => ['aspect_ratio' => '2:1'],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors('platforms.0.meta.aspect_ratio');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update post accepts valid instagram aspect_ratio meta', function () {
|
|
|
|
|
$instagramAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::Instagram,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $instagramAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::InstagramFeed->value,
|
|
|
|
|
'meta' => ['aspect_ratio' => '4:5'],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionDoesntHaveErrors('platforms.0.meta.aspect_ratio');
|
|
|
|
|
$postPlatform->refresh();
|
|
|
|
|
expect(data_get($postPlatform->meta, 'aspect_ratio'))->toBe('4:5');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('scheduling without content_type per platform fails', function () {
|
|
|
|
|
$youtubeAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::YouTube,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
'content' => 'Test',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $youtubeAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'scheduled',
|
|
|
|
|
'scheduled_at' => now()->addDay()->toIso8601String(),
|
|
|
|
|
'platforms' => [
|
|
|
|
|
['id' => $postPlatform->id],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors('platforms.0.content_type');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('draft post does not enforce media-vs-content-type compatibility', function () {
|
|
|
|
|
$youtubeAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::YouTube,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $youtubeAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
|
|
|
|
'status' => 'draft',
|
|
|
|
|
'media' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => 'media-1',
|
|
|
|
|
'path' => 'media/foo.jpg',
|
|
|
|
|
'url' => 'https://example.com/foo.jpg',
|
|
|
|
|
'type' => 'image',
|
|
|
|
|
'mime_type' => 'image/jpeg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::YouTubeShort->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionDoesntHaveErrors('platforms.0.content_type');
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-26 18:18:35 +00:00
|
|
|
test('update post validates label_ids exist', function () {
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'status' => PostStatus::Draft,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->put(route('app.posts.update', $post), [
|
2026-01-26 18:18:35 +00:00
|
|
|
'status' => 'draft',
|
|
|
|
|
'platforms' => [
|
|
|
|
|
[
|
|
|
|
|
'id' => $postPlatform->id,
|
|
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'label_ids' => ['non-existent-uuid'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors('label_ids.0');
|
|
|
|
|
});
|
2026-03-31 03:40:18 +00:00
|
|
|
|
|
|
|
|
// Member authorization tests
|
|
|
|
|
test('member can view posts index', function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$member = User::factory()->create([
|
|
|
|
|
'account_id' => $this->workspace->account_id,
|
|
|
|
|
]);
|
2026-03-31 03:40:18 +00:00
|
|
|
$this->workspace->members()->attach($member->id, ['role' => Role::Member->value]);
|
|
|
|
|
$member->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($member)->get(route('app.posts.index'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('member can create post', function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$member = User::factory()->create([
|
|
|
|
|
'account_id' => $this->workspace->account_id,
|
|
|
|
|
]);
|
2026-03-31 03:40:18 +00:00
|
|
|
$this->workspace->members()->attach($member->id, ['role' => Role::Member->value]);
|
|
|
|
|
$member->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($member)->post(route('app.posts.store'));
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect();
|
|
|
|
|
});
|
Defuse links in X posts to avoid the link-post fee (#308)
X bills a post containing a URL at a much higher rate than a plain post, and
its algorithm demotes link posts. The X version of a post now rewrites every
URL non-clickable (https://example.com/post becomes example(.)com/post):
scheme and www. dropped, every dot of the host replaced with (.).
Leaving a single dot intact would still leave a resolvable domain for X to
detect, so all of them are broken. A scheme or www. proves a token is a URL on
its own; a bare host only counts when its last label is a delegated TLD, which
is the one thing telling acme.com apart from Node.js. That check runs against
App\Support\LinkTlds, generated from the whole IANA root zone in every form a
TLD can appear in a post -- ASCII, punycode and the Unicode it decodes to --
because whatever X links is what X bills, so a hand-picked subset would leave
us paying for its gaps. If the regex engine bails out on pathological input the
original content is returned instead of crashing the publisher.
The transform lives in the Platform::X arm of ContentSanitizer, so it reaches
publishing and the app/API/MCP previews from one place and cannot touch any
other network. Off by default; opt in with X_DEFUSE_LINKS.
The editor counts characters and renders its preview client-side and cannot ask
the server on every keystroke, so the rewrite is mirrored in TypeScript. PHP
stays the source of truth: a parity test fails if the two TLD sets drift, and a
browser test drives the real editor so the mirror is covered rather than
assumed. Without it the composer promised text the network never receives.
Character limits now measure the text a reader will see: sanitized, then with
markup resolved away. Measuring the raw draft blocked saving posts that publish
fine and let through posts the network rejects, and counted the editor's HTML
toward the limit. Measuring the sanitized form alone would have counted
Telegram's escaped entities, rejecting messages Telegram accepts.
Empty content is handled once inside the sanitizer instead of by a guard
repeated at every call site.
2026-08-29 18:31:05 +00:00
|
|
|
|
|
|
|
|
test('the editor receives the tld list only while x link defusing is on', function (bool $enabled, bool $expectsList) {
|
|
|
|
|
config()->set('trypost.platforms.x.defuse_links', $enabled);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.posts.edit', $post))
|
|
|
|
|
->assertOk()
|
|
|
|
|
->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('posts/Edit')
|
|
|
|
|
->where('xLinkTlds', fn (Collection $tlds): bool => $expectsList
|
|
|
|
|
? $tlds->contains('com') && $tlds->count() === count(LinkTlds::all())
|
|
|
|
|
: $tlds->isEmpty())
|
|
|
|
|
);
|
|
|
|
|
})->with([
|
|
|
|
|
'enabled' => [true, true],
|
|
|
|
|
'disabled' => [false, false],
|
|
|
|
|
]);
|