from starlette_proxy_router.compile import RouteCompilier, _build_target_url


def test_build_target_url() -> None:
    target_url = _build_target_url("http://localhost:8000/", "/api/v1/test", {})
    assert target_url == "http://localhost:8000/api/v1/test"
    target_url = _build_target_url(
        "http://localhost:8000/", target="/api/v1/test/{user_id}", path_params={"user_id": "1"}
    )
    assert target_url == "http://localhost:8000/api/v1/test/1"


def test_build_func_name() -> None:
    compilier = RouteCompilier()
    func_name = compilier._build_func_name("/api/v1/test")
    assert func_name == "api_v1_test"

    func_name = compilier._build_func_name("/")
    assert func_name == "homepage"

    func_name = compilier._build_func_name("/api/v1/{user_id}/test")
    assert func_name == "api_v1_test"
