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-01-18 23:33:45 +00:00
|
|
|
use App\Enums\User\Setup;
|
|
|
|
|
use App\Models\Media;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
Storage::fake('local');
|
|
|
|
|
$this->user = User::factory()->create(['setup' => Setup::Completed]);
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$this->socialAccount = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
|
$this->post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
|
|
|
|
$this->postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Store tests
|
|
|
|
|
test('store media requires authentication', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->post(route('app.medias.store'), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'model' => 'postPlatform',
|
|
|
|
|
'model_id' => $this->postPlatform->id,
|
|
|
|
|
'media' => UploadedFile::fake()->image('test.jpg'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('store media uploads file', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.store'), [
|
2026-01-22 01:14:35 +00:00
|
|
|
'model' => 'postPlatform',
|
2026-01-18 23:33:45 +00:00
|
|
|
'model_id' => $this->postPlatform->id,
|
|
|
|
|
'media' => UploadedFile::fake()->image('test.jpg'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonStructure(['id', 'url', 'type', 'original_filename']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('store media validates required fields', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.store'), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'model' => '',
|
|
|
|
|
'model_id' => '',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertSessionHasErrors(['model', 'model_id', 'media']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Destroy tests
|
|
|
|
|
test('destroy media requires authentication', function () {
|
|
|
|
|
$media = Media::factory()->create([
|
|
|
|
|
'mediable_id' => $this->postPlatform->id,
|
|
|
|
|
'mediable_type' => 'postPlatform',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('destroy media deletes the media', function () {
|
|
|
|
|
$media = Media::factory()->create([
|
|
|
|
|
'mediable_id' => $this->postPlatform->id,
|
|
|
|
|
'mediable_type' => 'postPlatform',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJson(['success' => true]);
|
|
|
|
|
expect(Media::find($media->id))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('destroy media returns 403 for mismatched model', function () {
|
|
|
|
|
$otherPostPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$media = Media::factory()->create([
|
|
|
|
|
'mediable_id' => $otherPostPlatform->id,
|
|
|
|
|
'mediable_type' => 'postPlatform',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
2026-01-18 23:33:45 +00:00
|
|
|
|
|
|
|
|
$response->assertForbidden();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Duplicate tests
|
|
|
|
|
test('duplicate media requires authentication', function () {
|
|
|
|
|
$media = Media::factory()->create([
|
|
|
|
|
'mediable_id' => $this->postPlatform->id,
|
|
|
|
|
'mediable_type' => 'postPlatform',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->post(route('app.medias.duplicate', $media), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'targets' => [],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('duplicate media creates copies', function () {
|
|
|
|
|
$media = Media::factory()->create([
|
|
|
|
|
'mediable_id' => $this->postPlatform->id,
|
|
|
|
|
'mediable_type' => 'postPlatform',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$otherPostPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.duplicate', $media), [
|
2026-01-18 23:33:45 +00:00
|
|
|
'targets' => [
|
|
|
|
|
[
|
|
|
|
|
'model' => 'postPlatform',
|
|
|
|
|
'model_id' => $otherPostPlatform->id,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertJsonCount(1);
|
|
|
|
|
|
|
|
|
|
expect(Media::where('mediable_id', $otherPostPlatform->id)->count())->toBe(1);
|
|
|
|
|
});
|
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
|
|
|
|
|
|
|
|
// Reorder tests
|
|
|
|
|
test('reorder media updates order', function () {
|
|
|
|
|
$media1 = $this->postPlatform->addMedia(UploadedFile::fake()->image('img1.jpg'), 'media');
|
|
|
|
|
$media2 = $this->postPlatform->addMedia(UploadedFile::fake()->image('img2.jpg'), 'media');
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), [
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => $media1->id, 'order' => 1],
|
|
|
|
|
['id' => $media2->id, 'order' => 0],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
|
|
|
|
|
expect($media1->refresh()->order)->toBe(1);
|
|
|
|
|
expect($media2->refresh()->order)->toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('reorder media rejects media from other workspace', function () {
|
|
|
|
|
$otherUser = User::factory()->create(['setup' => Setup::Completed]);
|
|
|
|
|
$otherWorkspace = Workspace::factory()->create(['user_id' => $otherUser->id]);
|
|
|
|
|
$otherUser->update(['current_workspace_id' => $otherWorkspace->id]);
|
|
|
|
|
|
|
|
|
|
$otherPost = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
'user_id' => $otherUser->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$otherAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $otherWorkspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$otherPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $otherPost->id,
|
|
|
|
|
'social_account_id' => $otherAccount->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$otherMedia = $otherPlatform->addMedia(UploadedFile::fake()->image('img.jpg'), 'media');
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), [
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => $otherMedia->id, 'order' => 0],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertForbidden();
|
|
|
|
|
});
|
feat: social account toggle action, API, MCP + full test coverage
- Extract ToggleSocialAccount action from SocialController
- Add API endpoints: GET /social-accounts, PUT /social-accounts/{id}/toggle
- Add MCP tools: ListSocialAccountsTool, ToggleSocialAccountTool
- Fix all MCP tools: findOrFail → find + Response::error for graceful errors
- Fix MCP tools using $request->validated() without validate() call
- Fix return types to Response|ResponseFactory for error paths
- Add SocialAccountResource is_active/status fields (no tokens exposed)
- Add 43 MCP tests covering all 18 tools (CRUD, validation, cross-workspace)
- Add API response structure tests for posts, hashtags, labels, workspace
- Add API validation tests for post create/update, api-key expiry, label color
- Add API cross-workspace delete tests for hashtags and labels
- Add app validation tests for hashtag/label update, invite fields, password
- Add auth required tests for notifications, profile delete, api-keys index
- Add media reorder validation tests
2026-03-31 04:42:39 +00:00
|
|
|
|
|
|
|
|
test('reorder media validates required fields', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), []);
|
|
|
|
|
|
|
|
|
|
$response->assertUnprocessable();
|
|
|
|
|
$response->assertJsonValidationErrors(['media']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('reorder media validates media items have id and order', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)->postJson(route('app.medias.reorder'), [
|
|
|
|
|
'media' => [
|
|
|
|
|
['invalid' => 'data'],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertUnprocessable();
|
|
|
|
|
});
|