"""Tag 领域实体单测."""

import pytest

from packages.domain.tag import Tag


class TestTagCreate:
    def test_create_normal(self):
        tag = Tag.create(user_id="user1", name="  美食  ")
        assert tag.id
        assert tag.user_id == "user1"
        assert tag.name == "美食"  # 自动 strip
        assert tag.created_at is not None

    def test_create_empty_name_raises(self):
        with pytest.raises(ValueError, match="标签名称不能为空"):
            Tag.create(user_id="user1", name="")

    def test_create_whitespace_name_raises(self):
        with pytest.raises(ValueError, match="标签名称不能为空"):
            Tag.create(user_id="user1", name="   ")

    def test_create_generates_unique_ids(self):
        tag1 = Tag.create(user_id="u1", name="tag1")
        tag2 = Tag.create(user_id="u1", name="tag2")
        assert tag1.id != tag2.id
