package controller import ( "testing" "github.com/QuantumNous/new-api/common" "github.com/QuantumNous/new-api/model" "github.com/stretchr/testify/require" ) func TestExtractGeminiVideoURLSupportsTopLevelAndNestedShapes(t *testing.T) { require.Equal(t, "https://video.example/top", extractGeminiVideoURLFromMap(map[string]any{"uri": "https://video.example/top"})) nested := map[string]any{ "response": map[string]any{ "generateVideoResponse": map[string]any{ "generatedSamples": []any{map[string]any{"video": map[string]any{"uri": "https://video.example/generated"}}}, }, }, } require.Equal(t, "https://video.example/generated", extractGeminiVideoURLFromMap(nested)) require.Equal(t, "", extractGeminiVideoURLFromMap(map[string]any{"response": map[string]any{}})) } func TestExtractGeminiVideoURLFromTaskDataRejectsInvalidJSON(t *testing.T) { task := &model.Task{Data: []byte("not-json")} require.Empty(t, extractGeminiVideoURLFromTaskData(task)) payload, err := common.Marshal(map[string]any{"response": map[string]any{"video": "https://video.example/nested"}}) require.NoError(t, err) task.Data = payload require.Equal(t, "https://video.example/nested", extractGeminiVideoURLFromTaskData(task)) } func TestEnsureAPIKeyAppendsOnlyWhenMissing(t *testing.T) { require.Equal(t, "https://video.example/file?key=abc", ensureAPIKey("https://video.example/file", "abc")) require.Equal(t, "https://video.example/file?alt=media&key=abc", ensureAPIKey("https://video.example/file?alt=media", "abc")) require.Equal(t, "https://video.example/file?key=existing", ensureAPIKey("https://video.example/file?key=existing", "abc")) require.Equal(t, "https://video.example/file", ensureAPIKey("https://video.example/file", "")) }