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

57 lines
1.8 KiB
Python
Raw Normal View History

from __future__ import annotations
import pytest
from yuxi.channels.adapters.nostr.target import normalize_target, looks_like_id, hint
class TestNormalizeTarget:
def test_empty_string(self):
assert normalize_target("") == ""
def test_valid_hex_pubkey(self):
hex_key = "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"
assert normalize_target(hex_key) == hex_key
def test_nostr_prefix(self):
hex_key = "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"
assert normalize_target(f"nostr:{hex_key}") == hex_key
def test_whitespace(self):
hex_key = "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"
assert normalize_target(f" {hex_key} ") == hex_key
def test_invalid_input(self):
assert normalize_target("not_a_valid_pubkey") == ""
def test_random_string(self):
assert normalize_target("hello world") == ""
class TestLooksLikeId:
def test_valid_hex(self):
hex_key = "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"
assert looks_like_id(hex_key) is True
def test_nostr_prefix_hex(self):
hex_key = "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"
assert looks_like_id(f"nostr:{hex_key}") is True
def test_npub_looks_like_id(self):
assert looks_like_id("npub1") is False
def test_nprofile_looks_like_id(self):
assert looks_like_id("nprofile1abcdefghij") is True
def test_empty_string(self):
assert looks_like_id("") is False
def test_random_string(self):
assert looks_like_id("hello") is False
class TestHint:
def test_hint_returns_string(self):
result = hint()
assert isinstance(result, str)
assert "npub" in result or "hex" in result or "nprofile" in result