2026-01-18 18:56:51 +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 18:56:51 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-01-18 18:56:51 +00:00
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = User::factory()->create();
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('threads connect redirects to oauth', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->withHeader('X-Inertia', 'true')
|
2026-03-29 22:24:28 +00:00
|
|
|
->get(route('app.social.threads.connect'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header
|
|
|
|
|
|
|
|
|
|
expect(session('social_connect_workspace'))->toBe($this->workspace->id);
|
|
|
|
|
expect(session('threads_oauth_state'))->not->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('threads oauth callback creates account', function () {
|
|
|
|
|
$state = bin2hex(random_bytes(16));
|
|
|
|
|
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
'threads_oauth_state' => $state,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://graph.threads.net/oauth/access_token' => Http::response([
|
|
|
|
|
'access_token' => 'short-lived-token',
|
|
|
|
|
'user_id' => '123456789',
|
|
|
|
|
], 200),
|
|
|
|
|
'https://graph.threads.net/access_token*' => Http::response([
|
|
|
|
|
'access_token' => 'long-lived-token',
|
|
|
|
|
'expires_in' => 5184000, // 60 days
|
|
|
|
|
], 200),
|
|
|
|
|
'https://graph.threads.net/v1.0/123456789*' => Http::response([
|
|
|
|
|
'id' => '123456789',
|
|
|
|
|
'username' => 'testuser',
|
|
|
|
|
'name' => 'Test User',
|
|
|
|
|
'threads_profile_picture_url' => null,
|
|
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [
|
2026-01-18 18:56:51 +00:00
|
|
|
'code' => 'test-auth-code',
|
|
|
|
|
'state' => $state,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewIs('auth.social-callback');
|
|
|
|
|
$response->assertViewHas('success', true);
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('social_accounts', [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::Threads->value,
|
|
|
|
|
'platform_user_id' => '123456789',
|
|
|
|
|
'username' => 'testuser',
|
|
|
|
|
'status' => Status::Connected->value,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('threads callback fails with invalid state', function () {
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
'threads_oauth_state' => 'correct-state',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [
|
2026-01-18 18:56:51 +00:00
|
|
|
'code' => 'test-auth-code',
|
|
|
|
|
'state' => 'wrong-state',
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', false);
|
|
|
|
|
$response->assertViewHas('message', 'Invalid state. Please try again.');
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseMissing('social_accounts', [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::Threads->value,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('threads callback fails with expired session', function () {
|
|
|
|
|
// No session data - simulating expired session
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [
|
2026-01-18 18:56:51 +00:00
|
|
|
'code' => 'test-auth-code',
|
|
|
|
|
'state' => 'test-state',
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', false);
|
|
|
|
|
$response->assertViewHas('message', 'Session expired. Please try again.');
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-14 22:48:35 +00:00
|
|
|
test('user can connect multiple threads accounts', function () {
|
2026-01-18 18:56:51 +00:00
|
|
|
SocialAccount::factory()->threads()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform_user_id' => '123456789',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$state = bin2hex(random_bytes(16));
|
|
|
|
|
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
'threads_oauth_state' => $state,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://graph.threads.net/oauth/access_token' => Http::response([
|
|
|
|
|
'access_token' => 'new-token',
|
|
|
|
|
'user_id' => '987654321',
|
|
|
|
|
], 200),
|
|
|
|
|
'https://graph.threads.net/access_token*' => Http::response([
|
|
|
|
|
'access_token' => 'long-lived-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
], 200),
|
|
|
|
|
'https://graph.threads.net/v1.0/987654321*' => Http::response([
|
|
|
|
|
'id' => '987654321',
|
|
|
|
|
'username' => 'anotheruser',
|
|
|
|
|
'name' => 'Another User',
|
|
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [
|
2026-01-18 18:56:51 +00:00
|
|
|
'code' => 'test-auth-code',
|
|
|
|
|
'state' => $state,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', true);
|
|
|
|
|
|
2026-04-14 22:48:35 +00:00
|
|
|
expect($this->workspace->socialAccounts()->where('platform', Platform::Threads)->count())->toBe(2);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('threads callback handles token exchange failure', function () {
|
|
|
|
|
$state = bin2hex(random_bytes(16));
|
|
|
|
|
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
'threads_oauth_state' => $state,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://graph.threads.net/oauth/access_token' => Http::response([
|
|
|
|
|
'error' => 'invalid_grant',
|
|
|
|
|
'error_description' => 'The authorization code has expired.',
|
|
|
|
|
], 400),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.threads.callback', [
|
2026-01-18 18:56:51 +00:00
|
|
|
'code' => 'expired-auth-code',
|
|
|
|
|
'state' => $state,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', false);
|
|
|
|
|
$response->assertViewHas('message', 'Error connecting account. Please try again.');
|
|
|
|
|
});
|