Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

test(tiktok): cover MediaItem dimensions and platform max-width helpers

Paulo Castellano13e4d88b712b
diff --git a/app/Services/Social/TikTokPublisher.php b/app/Services/Social/TikTokPublisher.php
index 37bc6f068..09017ece2 100644
--- a/app/Services/Social/TikTokPublisher.php
+++ b/app/Services/Social/TikTokPublisher.php
@@ -276,9 +276,6 @@ class TikTokPublisher
'url' => $this->buildTikTokUrl($postPlatform->socialAccount, $postId),
];
} finally {
- // TikTok pulls the images during the synchronous status poll above,
- // so by the time we reach here the fetch is finished and the
- // temporary derivatives can be safely removed.
if ($derivatives !== []) {
Storage::delete($derivatives);
}
diff --git a/tests/Unit/DataTransferObjects/MediaItemTest.php b/tests/Unit/DataTransferObjects/MediaItemTest.php
index e178a7028..e6953ad22 100644
--- a/tests/Unit/DataTransferObjects/MediaItemTest.php
+++ b/tests/Unit/DataTransferObjects/MediaItemTest.php
@@ -34,3 +34,43 @@ test('media item falls back to the extension when no mime is present', function
expect($item->isImage())->toBeTrue();
});
+
+test('fromArray reads pixel dimensions from the meta block', function () {
+ $item = MediaItem::fromArray([
+ 'path' => 'photo.jpg',
+ 'url' => 'https://x/photo.jpg',
+ 'meta' => ['width' => 1254, 'height' => 836],
+ ]);
+
+ expect($item->width())->toBe(1254)
+ ->and($item->height())->toBe(836);
+});
+
+test('width and height are null when no meta is present', function () {
+ $item = MediaItem::fromArray(['path' => 'photo.jpg', 'url' => 'https://x/photo.jpg']);
+
+ expect($item->width())->toBeNull()
+ ->and($item->height())->toBeNull();
+});
+
+test('width and height ignore non-numeric meta values', function () {
+ $item = MediaItem::fromArray([
+ 'path' => 'photo.jpg',
+ 'url' => 'https://x/photo.jpg',
+ 'meta' => ['width' => 'wide', 'height' => null],
+ ]);
+
+ expect($item->width())->toBeNull()
+ ->and($item->height())->toBeNull();
+});
+
+test('numeric string dimensions are coerced to integers', function () {
+ $item = MediaItem::fromArray([
+ 'path' => 'photo.jpg',
+ 'url' => 'https://x/photo.jpg',
+ 'meta' => ['width' => '1080', 'height' => '1920'],
+ ]);
+
+ expect($item->width())->toBe(1080)
+ ->and($item->height())->toBe(1920);
+});
diff --git a/tests/Unit/Services/Media/MediaOptimizerTest.php b/tests/Unit/Services/Media/MediaOptimizerTest.php
index cbed2ed5f..54c7cae3b 100644
--- a/tests/Unit/Services/Media/MediaOptimizerTest.php
+++ b/tests/Unit/Services/Media/MediaOptimizerTest.php
@@ -111,6 +111,22 @@ it('resizes for pinterest max 1000', function () use (&$tempFiles) {
expect($optimized->width())->toBeLessThanOrEqual(1000);
});
+it('exposes the configured max width per platform', function () {
+ $optimizer = new MediaOptimizer;
+
+ expect($optimizer->maxWidthForPlatform(Platform::TikTok))->toBe(1080)
+ ->and($optimizer->maxWidthForPlatform(Platform::Instagram))->toBe(1440)
+ ->and($optimizer->maxWidthForPlatform(Platform::Pinterest))->toBe(1000);
+});
+
+it('reports a max width for every platform', function () {
+ $optimizer = new MediaOptimizer;
+
+ foreach (Platform::cases() as $platform) {
+ expect($optimizer->maxWidthForPlatform($platform))->toBeInt()->toBeGreaterThan(0);
+ }
+});
+
it('handles all platforms without error', function () use (&$tempFiles) {
$source = createTestImage(1000, 800);
$tempFiles[] = $source;