package openai

import (
	"net/http/httptest"
	"testing"
)

func TestPrepareAvoidsDuplicatedV1BasePath(t *testing.T) {
	adapter, err := New("https://example.com/proxy/v1", "secret")
	if err != nil {
		t.Fatal(err)
	}
	request := httptest.NewRequest("POST", "https://example.com/proxy/v1/v1/chat/completions", nil)
	adapter.Prepare(request)
	if request.URL.Path != "/proxy/v1/chat/completions" {
		t.Fatalf("unexpected path %q", request.URL.Path)
	}
	if request.Header.Get("Authorization") != "Bearer secret" {
		t.Fatal("upstream credential was not applied")
	}
}
