feat(ai-edits): add output storage backfill flow and coverage
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\Api\Event;
|
||||
|
||||
use App\Models\AiEditingSetting;
|
||||
use App\Models\AiEditOutput;
|
||||
use App\Models\AiEditRequest;
|
||||
use App\Models\AiStyle;
|
||||
use App\Models\AiUsageLedger;
|
||||
@@ -13,6 +14,7 @@ use App\Models\Package;
|
||||
use App\Models\Photo;
|
||||
use App\Services\EventJoinTokenService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventAiEditControllerTest extends TestCase
|
||||
@@ -802,6 +804,67 @@ class EventAiEditControllerTest extends TestCase
|
||||
->assertJsonPath('error.meta.allowed_style_keys.0', $allowed->key);
|
||||
}
|
||||
|
||||
public function test_guest_show_serializes_local_output_url_when_storage_path_is_present(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
$this->attachEntitledEventPackage($event);
|
||||
|
||||
$photo = Photo::factory()->for($event)->create([
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'status' => 'approved',
|
||||
]);
|
||||
|
||||
$style = AiStyle::query()->create([
|
||||
'key' => 'guest-output-url-style',
|
||||
'name' => 'Guest Output URL',
|
||||
'provider' => 'runware',
|
||||
'provider_model' => 'runware-default',
|
||||
'requires_source_image' => true,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$request = AiEditRequest::query()->create([
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'event_id' => $event->id,
|
||||
'photo_id' => $photo->id,
|
||||
'style_id' => $style->id,
|
||||
'provider' => 'runware',
|
||||
'provider_model' => 'runware-default',
|
||||
'status' => AiEditRequest::STATUS_SUCCEEDED,
|
||||
'safety_state' => 'passed',
|
||||
'prompt' => 'Create edit.',
|
||||
'idempotency_key' => 'guest-output-url-1',
|
||||
'queued_at' => now()->subMinute(),
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
|
||||
$storagePath = 'events/demo-event/ai-edits/output-1.jpg';
|
||||
AiEditOutput::query()->create([
|
||||
'request_id' => $request->id,
|
||||
'provider_asset_id' => 'guest-output-asset-1',
|
||||
'storage_disk' => 'public',
|
||||
'storage_path' => $storagePath,
|
||||
'provider_url' => 'https://provider.example/output.jpg',
|
||||
'mime_type' => 'image/jpeg',
|
||||
'is_primary' => true,
|
||||
'safety_state' => 'passed',
|
||||
'generated_at' => now(),
|
||||
]);
|
||||
|
||||
$token = app(EventJoinTokenService::class)
|
||||
->createToken($event, ['label' => 'guest-output-url'])
|
||||
->getAttribute('plain_token');
|
||||
|
||||
$response = $this->withHeaders(['X-Device-Id' => 'guest-device-output-url'])
|
||||
->getJson("/api/v1/events/{$token}/ai-edits/{$request->id}");
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.outputs.0.storage_path', $storagePath)
|
||||
->assertJsonPath('data.outputs.0.url', Storage::disk('public')->url($storagePath));
|
||||
}
|
||||
|
||||
private function attachEntitledEventPackage(Event $event): EventPackage
|
||||
{
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
|
||||
Reference in New Issue
Block a user