diff --git a/app/Services/Social/TikTokPublisher.php b/app/Services/Social/TikTokPublisher.php index 37bc6f06..09017ece 100644 --- a/app/Services/Social/TikTokPublisher.php +++ b/app/Services/Social/TikTokPublisher.php @@ -276,9 +276,6 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection, ?st '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 e178a702..e6953ad2 100644 --- a/tests/Unit/DataTransferObjects/MediaItemTest.php +++ b/tests/Unit/DataTransferObjects/MediaItemTest.php @@ -34,3 +34,43 @@ 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 cbed2ed5..54c7cae3 100644 --- a/tests/Unit/Services/Media/MediaOptimizerTest.php +++ b/tests/Unit/Services/Media/MediaOptimizerTest.php @@ -111,6 +111,22 @@ function createTestImage(int $width, int $height, string $format = 'image/jpeg') 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;