File size: 4,360 Bytes
1501522 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | <?php
namespace Tests\Feature;
use App\Services\FreepikAssetRemixService;
use App\Services\FreepikImageService;
use App\Services\FreepikVideoService;
use App\Services\MotionVideoService;
use App\Services\OpenAiImageService;
use App\Services\PollinationsImageService;
use App\Services\PosterImageService;
use App\Services\SocialMediaStudioService;
use App\Services\StoryImageNormalizerService;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
class SocialMediaStudioServiceTest extends TestCase
{
use MockeryPHPUnitIntegration;
public function test_remix_from_asset_returns_normalized_image_payload(): void
{
$freepikRemix = Mockery::mock(FreepikAssetRemixService::class);
$storyNormalizer = Mockery::mock(StoryImageNormalizerService::class);
$freepikRemix->shouldReceive('remixImage')
->once()
->with([
'type' => 'image',
'url' => '/storage/social_assets/images/source.jpg',
'thumbnail_url' => '/storage/social_assets/images/source.jpg',
], 'Ubah jadi visual premium', 'restyle')
->andReturn([
'provider' => 'freepik-seedream-v45-edit',
'urls' => ['https://cdn.example.com/remix-image.jpg'],
]);
$storyNormalizer->shouldReceive('normalizeMany')
->once()
->with(['https://cdn.example.com/remix-image.jpg'])
->andReturn([[
'url' => '/storage/images/remix.jpg',
'thumbnail_url' => '/storage/images/remix-thumb.jpg',
'width' => 1080,
'height' => 1920,
]]);
$service = new SocialMediaStudioService(
Mockery::mock(FreepikImageService::class),
Mockery::mock(FreepikVideoService::class),
$freepikRemix,
Mockery::mock(OpenAiImageService::class),
Mockery::mock(PollinationsImageService::class),
Mockery::mock(PosterImageService::class),
$storyNormalizer,
Mockery::mock(MotionVideoService::class),
);
$result = $service->remixFromAsset([
'type' => 'image',
'url' => '/storage/social_assets/images/source.jpg',
'thumbnail_url' => '/storage/social_assets/images/source.jpg',
], 'Ubah jadi visual premium', 'restyle', 'image');
$this->assertSame('/storage/images/remix.jpg', $result['url']);
$this->assertSame('freepik-seedream-v45-edit', $result['provider']);
$this->assertSame('9:16', $result['aspect']);
}
public function test_remix_from_asset_returns_video_payload_for_story_output(): void
{
$freepikRemix = Mockery::mock(FreepikAssetRemixService::class);
$freepikRemix->shouldReceive('remixVideo')
->once()
->with([
'type' => 'video',
'url' => '/storage/social_assets/videos/source.mp4',
'thumbnail_url' => '/storage/social_assets/images/source-thumb.jpg',
], 'Bikin jadi video promo vertikal', 'mockup')
->andReturn([
'url' => '/storage/videos/remix.mp4',
'provider' => 'freepik-runway-i2v',
'duration_seconds' => 5,
]);
$service = new SocialMediaStudioService(
Mockery::mock(FreepikImageService::class),
Mockery::mock(FreepikVideoService::class),
$freepikRemix,
Mockery::mock(OpenAiImageService::class),
Mockery::mock(PollinationsImageService::class),
Mockery::mock(PosterImageService::class),
Mockery::mock(StoryImageNormalizerService::class),
Mockery::mock(MotionVideoService::class),
);
$result = $service->remixFromAsset([
'type' => 'video',
'url' => '/storage/social_assets/videos/source.mp4',
'thumbnail_url' => '/storage/social_assets/images/source-thumb.jpg',
], 'Bikin jadi video promo vertikal', 'mockup', 'video');
$this->assertSame('/storage/videos/remix.mp4', $result['url']);
$this->assertSame('freepik-runway-i2v', $result['provider']);
$this->assertSame('/storage/social_assets/images/source-thumb.jpg', $result['source_image_url']);
}
}
|