from starlette_proxy_router.parser import EndpointArgs, Parser
from starlette_proxy_router.types import AuthType
from starlette_proxy_router.validate import MethodHTTP
from tests.constants import PATH_FILE_CONFIG


def test_parser() -> None:
    parser = Parser(PATH_FILE_CONFIG)
    args_endpoints = parser.parse_configs()
    assert len(args_endpoints) == 6
    assert args_endpoints[0] == EndpointArgs(
        path="/api/v1/proxy",
        target="/api/v1/target",
        method=MethodHTTP.GET,
        host="http://localhost:8000/",
        service_name="test_service_1",
        is_auth=True,
        timeout=None,
        auth_type=AuthType.QUERY_PARAMS,
        auth_fields=["user_id"],
    )
    assert args_endpoints[1] == EndpointArgs(
        path="/api/v1/proxy",
        target="/api/v1/target",
        method=MethodHTTP.PUT,
        host="http://localhost:8000/",
        service_name="test_service_1",
        is_auth=False,
        timeout=None,
        auth_type=AuthType.QUERY_PARAMS,
        auth_fields=["user_id"],
    )
    assert args_endpoints[4] == EndpointArgs(
        path="/api/v1/create-object",
        target="/api/v1/create-object-target",
        method=MethodHTTP.GET,
        host="http://localhost:8000/",
        service_name="test_service_2",
        is_auth=True,
        timeout=10,
        auth_type=AuthType.QUERY_PARAMS,
        auth_fields=["user_id"],
    )
    assert args_endpoints[5] == EndpointArgs(
        path="/",
        target="/",
        method=MethodHTTP.GET,
        host="http://localhost:8000/",
        service_name="test_service_2",
        is_auth=True,
        timeout=None,
        auth_type=AuthType.QUERY_PARAMS,
        auth_fields=["user_id"],
    )
