Files
orion/app/modules/loyalty/tests/unit/test_schemas.py
Samir Boulahtit 3df75e2e78
Some checks failed
CI / ruff (push) Successful in 11s
CI / dependency-scanning (push) Successful in 28s
CI / docs (push) Has been skipped
CI / pytest (push) Failing after 46m26s
CI / validate (push) Successful in 23s
CI / deploy (push) Has been skipped
test: add loyalty module tests for today's bug fixes
Covers card lookup route ordering, func.replace normalization, customer
name in transactions, self-enrollment creation, and earn points endpoint.
54 tests total (was 1).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 23:28:22 +01:00

76 lines
2.2 KiB
Python

"""Unit tests for loyalty schemas."""
from datetime import UTC, datetime
import pytest
from app.modules.loyalty.schemas.card import (
CardEnrollRequest,
TransactionResponse,
)
@pytest.mark.unit
@pytest.mark.loyalty
class TestCardEnrollRequest:
"""Tests for enrollment request schema validation."""
def test_valid_with_email(self):
"""Email-only enrollment is valid."""
req = CardEnrollRequest(email="test@example.com")
assert req.email == "test@example.com"
assert req.customer_id is None
def test_valid_with_customer_id(self):
"""Customer ID enrollment is valid."""
req = CardEnrollRequest(customer_id=42)
assert req.customer_id == 42
assert req.email is None
def test_self_enrollment_fields(self):
"""Self-enrollment accepts name, phone, birthday."""
req = CardEnrollRequest(
email="self@example.com",
customer_name="Jane Doe",
customer_phone="+352123456",
customer_birthday="1990-01-15",
)
assert req.customer_name == "Jane Doe"
assert req.customer_phone == "+352123456"
assert req.customer_birthday == "1990-01-15"
@pytest.mark.unit
@pytest.mark.loyalty
class TestTransactionResponse:
"""Tests for transaction response schema."""
def test_customer_name_field_defaults_none(self):
"""customer_name field exists and defaults to None."""
now = datetime.now(UTC)
tx = TransactionResponse(
id=1,
card_id=1,
transaction_type="points_earned",
stamps_delta=0,
points_delta=50,
transaction_at=now,
created_at=now,
)
assert tx.customer_name is None
def test_customer_name_can_be_set(self):
"""customer_name can be explicitly set."""
now = datetime.now(UTC)
tx = TransactionResponse(
id=1,
card_id=1,
transaction_type="card_created",
stamps_delta=0,
points_delta=0,
customer_name="John Doe",
transaction_at=now,
created_at=now,
)
assert tx.customer_name == "John Doe"