test(tiktok): cover download-failure path and assert TikTok-specific optimization
Adds a test for the resize download-failure branch, and tightens the resize mocks to assert optimization is requested for Platform::TikTok specifically.
This commit is contained in:
parent
13e4d88b71
commit
0829814d8b
1 changed files with 38 additions and 4 deletions
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue