ForcePilot/backend/test/unit/channels/test_nostr_models.py

84 lines
2.5 KiB
Python
Raw Normal View History

from __future__ import annotations
import pytest
from pydantic import ValidationError
from yuxi.channels.adapters.nostr.models import NostrEvent, NostrProfile
class TestNostrEvent:
def test_minimal_event(self):
event = NostrEvent(
id="e1",
pubkey="pub1",
created_at=1000,
kind=1,
)
assert event.id == "e1"
assert event.tags == []
assert event.content == ""
assert event.sig is None
def test_full_event(self):
event = NostrEvent(
id="e2",
pubkey="pub2",
created_at=2000,
kind=4,
tags=[["p", "recipient"]],
content="encrypted",
sig="signature_data",
)
assert event.sig == "signature_data"
assert event.tags == [["p", "recipient"]]
def test_event_missing_required_fields(self):
with pytest.raises(ValidationError):
NostrEvent()
def test_event_invalid_types(self):
with pytest.raises(ValidationError):
NostrEvent(
id="e1",
pubkey="pub1",
created_at="not_an_int",
kind=1,
)
def test_event_defaults_applied(self):
event = NostrEvent(id="e3", pubkey="pub3", created_at=3000, kind=7)
assert event.tags == []
assert event.content == ""
class TestNostrProfile:
def test_empty_profile(self):
profile = NostrProfile()
assert profile.name == ""
assert profile.display_name == ""
assert profile.about == ""
assert profile.picture == ""
assert profile.banner == ""
assert profile.website == ""
assert profile.nip05 == ""
assert profile.lud16 == ""
def test_full_profile(self):
profile = NostrProfile(
name="Alice",
display_name="Alice Wonderland",
about="Just a nostr user",
picture="https://example.com/pic.jpg",
banner="https://example.com/banner.jpg",
website="https://alice.example.com",
nip05="alice@example.com",
lud16="alice@getalby.com",
)
assert profile.name == "Alice"
assert profile.lud16 == "alice@getalby.com"
def test_profile_partial_fields(self):
profile = NostrProfile(name="Bob", lud16="bob@wallet.com")
assert profile.name == "Bob"
assert profile.display_name == ""
assert profile.lud16 == "bob@wallet.com"