neotalk/tests/use_cases/test_change_alias.py
Andros Fenollosa bfd8b510b6 Initial neotalk: P2P encrypted chat over UDP discovery + TCP streaming
Clean architecture (core use cases + infra gateways), X25519/AES-GCM E2E
encryption, tkinter GUI, and a pytest suite. 45 tests passing.
2026-08-21 09:16:07 +02:00

38 lines
1.2 KiB
Python

"""Tests for the change_alias use case."""
import pytest
from neotalk.core.entities.responses import ResponseTypes
from neotalk.core.use_cases.identity.change_alias import change_alias_use_case
def test_change_alias_trims_and_updates(identity):
# When setting a padded alias
response = change_alias_use_case(identity, " carol ")
# Then it is trimmed and stored, leaving other fields intact
assert response["type"] == ResponseTypes.SUCCESS
updated = response["data"]["identity"]
assert updated.alias == "carol"
assert updated.peer_id == identity.peer_id
@pytest.mark.parametrize(
"alias",
[pytest.param("", id="empty"), pytest.param(" ", id="whitespace")],
)
def test_change_alias_rejects_blank(identity, alias):
# When setting a blank alias
response = change_alias_use_case(identity, alias)
# Then it is a parameters error
assert response["type"] == ResponseTypes.PARAMETERS_ERROR
def test_change_alias_rejects_overly_long_alias(identity):
# When setting an alias beyond the limit
response = change_alias_use_case(identity, "x" * 33)
# Then it is a parameters error
assert response["type"] == ResponseTypes.PARAMETERS_ERROR
assert response["errors"][0]["field"] == "alias"