2026-01-19 00:49:13 +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-19 00:49:13 +00:00
|
|
|
use App\Enums\PostPlatform\ContentType;
|
|
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Exceptions\TokenExpiredException;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use App\Services\Social\YouTubePublisher;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->workspace = Workspace::factory()->create();
|
|
|
|
|
$this->socialAccount = SocialAccount::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::YouTube,
|
|
|
|
|
'platform_user_id' => 'youtube-channel-123',
|
|
|
|
|
'access_token' => 'test-token',
|
|
|
|
|
'token_expires_at' => now()->addDays(30),
|
|
|
|
|
]);
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post = Post::factory()->create(['workspace_id' => $this->workspace->id, 'content' => 'Test YouTube Short description']);
|
2026-01-19 00:49:13 +00:00
|
|
|
$this->postPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $this->post->id,
|
|
|
|
|
'social_account_id' => $this->socialAccount->id,
|
|
|
|
|
'content_type' => ContentType::YouTubeShort,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher throws exception when no media', function () {
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
2026-03-29 22:24:28 +00:00
|
|
|
->toThrow(Exception::class, 'YouTube Shorts requires a video to publish.');
|
2026-01-19 00:49:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher throws exception for non video media', function () {
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post->update([
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => 'test-img', 'path' => 'medias/test.jpg', 'url' => 'https://example.com/medias/test.jpg', 'mime_type' => 'image/jpeg', 'original_filename' => 'test.jpg'],
|
|
|
|
|
]]);
|
2026-01-19 00:49:13 +00:00
|
|
|
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
2026-03-29 22:24:28 +00:00
|
|
|
->toThrow(Exception::class, 'YouTube Shorts only supports video content.');
|
2026-01-19 00:49:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher throws exception when no refresh token for expired token', function () {
|
|
|
|
|
$this->socialAccount->update([
|
|
|
|
|
'token_expires_at' => now()->subHour(),
|
|
|
|
|
'refresh_token' => null,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post->update([
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => 'test-vid', 'path' => 'medias/test.mp4', 'url' => 'https://example.com/medias/test.mp4', 'mime_type' => 'video/mp4', 'original_filename' => 'test.mp4'],
|
|
|
|
|
]]);
|
2026-01-19 00:49:13 +00:00
|
|
|
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
|
|
|
|
->toThrow(TokenExpiredException::class, 'No refresh token available');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher throws token expired exception on 401', function () {
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post->update([
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => 'test-vid', 'path' => 'medias/test.mp4', 'url' => 'https://example.com/medias/test.mp4', 'mime_type' => 'video/mp4', 'original_filename' => 'test.mp4'],
|
|
|
|
|
]]);
|
2026-01-19 00:49:13 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'*' => Http::response([
|
|
|
|
|
'error' => 'invalid_token',
|
|
|
|
|
'error_description' => 'Token has expired',
|
|
|
|
|
], 401),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
// The error happens before the API call because of file_get_contents
|
|
|
|
|
// So we test the token expired scenario through refreshToken
|
|
|
|
|
$this->socialAccount->update([
|
|
|
|
|
'token_expires_at' => now()->subHour(),
|
|
|
|
|
'refresh_token' => 'refresh-token',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
|
|
|
|
->toThrow(TokenExpiredException::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher throws token expired exception on invalid grant', function () {
|
|
|
|
|
$this->socialAccount->update([
|
|
|
|
|
'token_expires_at' => now()->subHour(),
|
|
|
|
|
'refresh_token' => 'invalid-refresh-token',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post->update([
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => 'test-vid', 'path' => 'medias/test.mp4', 'url' => 'https://example.com/medias/test.mp4', 'mime_type' => 'video/mp4', 'original_filename' => 'test.mp4'],
|
|
|
|
|
]]);
|
2026-01-19 00:49:13 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://oauth2.googleapis.com/token' => Http::response([
|
|
|
|
|
'error' => 'invalid_grant',
|
|
|
|
|
'error_description' => 'Token has been revoked',
|
|
|
|
|
], 400),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
|
|
|
|
->toThrow(TokenExpiredException::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('youtube publisher handles auth error reason', function () {
|
|
|
|
|
$this->socialAccount->update([
|
|
|
|
|
'token_expires_at' => now()->subHour(),
|
|
|
|
|
'refresh_token' => 'refresh-token',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 23:11:36 +00:00
|
|
|
$this->post->update([
|
|
|
|
|
'media' => [
|
|
|
|
|
['id' => 'test-vid', 'path' => 'medias/test.mp4', 'url' => 'https://example.com/medias/test.mp4', 'mime_type' => 'video/mp4', 'original_filename' => 'test.mp4'],
|
|
|
|
|
]]);
|
2026-01-19 00:49:13 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://oauth2.googleapis.com/token' => Http::response([
|
|
|
|
|
'error' => [
|
|
|
|
|
'code' => 401,
|
|
|
|
|
'message' => 'Request had invalid authentication credentials',
|
|
|
|
|
'errors' => [
|
|
|
|
|
['reason' => 'authError'],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
], 401),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$publisher = new YouTubePublisher;
|
|
|
|
|
|
|
|
|
|
expect(fn () => $publisher->publish($this->postPlatform))
|
|
|
|
|
->toThrow(TokenExpiredException::class);
|
|
|
|
|
});
|