diff --git a/tests/Feature/Services/Social/TikTokPublisherTest.php b/tests/Feature/Services/Social/TikTokPublisherTest.php index 16d448d6..067b3f05 100644 --- a/tests/Feature/Services/Social/TikTokPublisherTest.php +++ b/tests/Feature/Services/Social/TikTokPublisherTest.php @@ -715,8 +715,8 @@ ]); $mockOptimizer = Mockery::mock(MediaOptimizer::class); - $mockOptimizer->shouldReceive('maxWidthForPlatform')->andReturn(1080); - $mockOptimizer->shouldReceive('optimizeImage')->andReturnUsing(function (string $tempFile) { + $mockOptimizer->shouldReceive('maxWidthForPlatform')->with(Platform::TikTok)->andReturn(1080); + $mockOptimizer->shouldReceive('optimizeImage')->with(Mockery::type('string'), Platform::TikTok)->andReturnUsing(function (string $tempFile) { $optimized = tempnam(sys_get_temp_dir(), 'tt_opt_'); copy($tempFile, $optimized); @@ -811,8 +811,8 @@ ]); $mockOptimizer = Mockery::mock(MediaOptimizer::class); - $mockOptimizer->shouldReceive('maxWidthForPlatform')->andReturn(1080); - $mockOptimizer->shouldReceive('optimizeImage')->andReturnUsing(function (string $tempFile) { + $mockOptimizer->shouldReceive('maxWidthForPlatform')->with(Platform::TikTok)->andReturn(1080); + $mockOptimizer->shouldReceive('optimizeImage')->with(Mockery::type('string'), Platform::TikTok)->andReturnUsing(function (string $tempFile) { $optimized = tempnam(sys_get_temp_dir(), 'tt_opt_'); copy($tempFile, $optimized); @@ -845,3 +845,37 @@ expect(Storage::allFiles('social-tiktok-photos'))->toBeEmpty(); }); + +test('tiktok publisher fails clearly when an oversized photo cannot be downloaded for resizing', function () { + Storage::fake(); + + $this->postPlatform->update(['meta' => ['privacy_level' => 'SELF_ONLY']]); + $this->post->update([ + 'media' => [ + [ + 'id' => 'test-media-oversized', + 'path' => 'media/2026-01/big.jpg', + 'url' => 'https://example.com/media/2026-01/big.jpg', + 'mime_type' => 'image/jpeg', + 'original_filename' => 'big.jpg', + 'meta' => ['width' => 1254, 'height' => 1254], + ], + ], + ]); + + // optimizeImage is intentionally not stubbed: it must never be reached when the + // download fails, and the strict mock would throw if it were called. + $mockOptimizer = Mockery::mock(MediaOptimizer::class); + $mockOptimizer->shouldReceive('maxWidthForPlatform')->with(Platform::TikTok)->andReturn(1080); + app()->instance(MediaOptimizer::class, $mockOptimizer); + + Http::fake([ + '*' => Http::response('not found', 500), + ]); + + expect(fn () => $this->publisher->publish($this->postPlatform)) + ->toThrow(TikTokPublishException::class, 'Failed to download image for TikTok resizing'); + + // Nothing should be left hosted when resizing never completes. + expect(Storage::allFiles('social-tiktok-photos'))->toBeEmpty(); +});