trypost/tests/Unit/Models/PostTest.php
Paulo Castellano 56b8c92e72 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 00:20:43 -03:00

185 lines
5.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\Post\Status as PostStatus;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\SocialAccount;
use App\Models\User;
use App\Models\Workspace;
beforeEach(function () {
$this->user = User::factory()->create();
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
});
test('post belongs to workspace', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
expect($post->workspace->id)->toBe($this->workspace->id);
});
test('post belongs to user', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
expect($post->user->id)->toBe($this->user->id);
});
test('post has many post platforms', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$socialAccount = SocialAccount::factory()->linkedin()->create([
'workspace_id' => $this->workspace->id,
]);
$postPlatform = PostPlatform::factory()->create([
'post_id' => $post->id,
'social_account_id' => $socialAccount->id,
]);
expect($post->postPlatforms)->toHaveCount(1);
expect($post->postPlatforms->first()->id)->toBe($postPlatform->id);
});
test('post can be marked as publishing', function () {
$post = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$post->markAsPublishing();
expect($post->fresh()->status)->toBe(PostStatus::Publishing);
});
test('post can be marked as published', function () {
$post = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$post->markAsPublished();
expect($post->fresh()->status)->toBe(PostStatus::Published);
expect($post->fresh()->published_at)->not->toBeNull();
});
test('post can be marked as partially published', function () {
$post = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$post->markAsPartiallyPublished();
expect($post->fresh()->status)->toBe(PostStatus::PartiallyPublished);
expect($post->fresh()->published_at)->not->toBeNull();
});
test('post can be marked as failed', function () {
$post = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$post->markAsFailed();
expect($post->fresh()->status)->toBe(PostStatus::Failed);
});
test('post scope scheduled returns only scheduled posts', function () {
Post::factory()->draft()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$scheduled = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$posts = Post::scheduled()->get();
expect($posts)->toHaveCount(1);
expect($posts->first()->id)->toBe($scheduled->id);
});
test('post scope due returns scheduled posts that are due', function () {
Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'scheduled_at' => now()->addHour(),
]);
$due = Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'scheduled_at' => now()->subMinute(),
]);
$posts = Post::due()->get();
expect($posts)->toHaveCount(1);
expect($posts->first()->id)->toBe($due->id);
});
test('post scope draft returns only draft posts', function () {
$draft = Post::factory()->draft()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
Post::factory()->scheduled()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$posts = Post::draft()->get();
expect($posts)->toHaveCount(1);
expect($posts->first()->id)->toBe($draft->id);
});
test('post scope published returns only published posts', function () {
Post::factory()->draft()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$published = Post::factory()->published()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$posts = Post::published()->get();
expect($posts)->toHaveCount(1);
expect($posts->first()->id)->toBe($published->id);
});
test('post scope failed returns only failed posts', function () {
Post::factory()->draft()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$failed = Post::factory()->failed()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
]);
$posts = Post::failed()->get();
expect($posts)->toHaveCount(1);
expect($posts->first()->id)->toBe($failed->id);
});