"""Tests para sign_metabase_embed_jwt."""

import jwt
import pytest

from sign_metabase_embed_jwt import sign_metabase_embed_jwt


def test_firma_y_decodifica_round_trip():
    secret = "test-secret-1234567890"
    result = sign_metabase_embed_jwt(
        secret=secret,
        resource_type="question",
        resource_id=8048,
        base_url="https://reports.autingo.es",
        params={"category": "shoes"},
    )
    decoded = jwt.decode(result["token"], secret, algorithms=["HS256"])
    assert decoded["resource"] == {"question": 8048}
    assert decoded["params"] == {"category": "shoes"}
    assert decoded["exp"] == result["exp"]


def test_resource_type_invalido_lanza_valueerror():
    with pytest.raises(ValueError):
        sign_metabase_embed_jwt(
            secret="s",
            resource_type="bogus",
            resource_id=1,
            base_url="https://reports.autingo.es",
        )


def test_embed_url_dashboard():
    result = sign_metabase_embed_jwt(
        secret="s",
        resource_type="dashboard",
        resource_id=42,
        base_url="https://reports.autingo.es",
    )
    assert "/embed/dashboard/" in result["embed_url"]
    assert result["embed_url"].endswith("#bordered=true&titled=true")
