from dishka import FromDishka

from tests.web_api.helpers import is_success_response
from tests.web_api.ioc import DatabaseClearer, inject
from tests.web_api.test_api_gateway import TestApiGateway


@inject
async def test_add_key_skill(
    client: FromDishka[TestApiGateway],
    database_clearer: FromDishka[DatabaseClearer],
) -> None:
    await database_clearer.clear()

    response = await client.add_key_skill(key_skills=["Python", "Django", "REST APIs"])
    assert is_success_response(response)


@inject
async def test_search_key_skills(
    client: FromDishka[TestApiGateway],
    database_clearer: FromDishka[DatabaseClearer],
) -> None:
    await database_clearer.clear()

    await client.add_key_skill(key_skills=["Python", "Django", "Python3.12", "REST APIs"])
    response = await client.search_key_skills("p")
    assert is_success_response(response)
    assert {name["name"] == "Python" for name in response.json()}
