# pyright: reportCallIssue=false

from __future__ import annotations

from behave import then, when

from worklib import admin_data


@when("get access token")  # pyright: ignore[reportGeneralTypeIssues]
def step_get_access_token(context) -> None:
    if not getattr(context, "access_token", None):
        token = admin_data.get_access_token_from_env()
        context.access_token = token
        admin_data.get_or_create_user("tester").access_token = token


@then("access token is valid")  # pyright: ignore[reportGeneralTypeIssues]
def step_token_is_valid(context) -> None:
    token = getattr(context, "access_token", None)
    assert isinstance(token, str) and token.strip(), f"access_token пустой/не строка: {token}"

