snipe/tests/platforms/test_ebay_normaliser.py
pyr0ball eb05be0612
Some checks are pending
CI / API — lint + test (pull_request) Waiting to run
CI / Web — typecheck + test + build (pull_request) Waiting to run
feat: wire Forgejo Actions CI/CD workflows (#22)
- ci.yml: API lint (ruff F+I) + pytest, web vue-tsc + vitest + build
- mirror.yml: push to GitHub (CircuitForgeLLC) + Codeberg (CircuitForge) on main/tags
- release.yml: Docker build → Forgejo registry + release via API; GHCR deferred pending BSL policy (cf-agents#3)
- .cliff.toml: git-cliff changelog config for semver releases
- pyproject.toml: add [dev] extras (pytest, ruff), ruff config
- Fix 45 ruff violations across codebase (import sorting, unused vars, unused imports)
2026-04-06 00:00:28 -07:00

58 lines
2 KiB
Python

import pytest
from app.platforms.ebay.normaliser import normalise_listing, normalise_seller
def test_normalise_listing_maps_fields():
raw = {
"itemId": "v1|12345|0",
"title": "RTX 4090 GPU",
"price": {"value": "950.00", "currency": "USD"},
"condition": "USED",
"seller": {"username": "techguy", "feedbackScore": 300, "feedbackPercentage": "99.1"},
"itemWebUrl": "https://ebay.com/itm/12345",
"image": {"imageUrl": "https://i.ebayimg.com/1.jpg"},
"additionalImages": [{"imageUrl": "https://i.ebayimg.com/2.jpg"}],
"itemCreationDate": "2026-03-20T00:00:00.000Z",
}
listing = normalise_listing(raw)
assert listing.platform == "ebay"
assert listing.platform_listing_id == "v1|12345|0"
assert listing.title == "RTX 4090 GPU"
assert listing.price == 950.0
assert listing.condition == "used"
assert listing.seller_platform_id == "techguy"
assert "https://i.ebayimg.com/1.jpg" in listing.photo_urls
assert "https://i.ebayimg.com/2.jpg" in listing.photo_urls
def test_normalise_listing_handles_missing_images():
raw = {
"itemId": "v1|999|0",
"title": "GPU",
"price": {"value": "100.00", "currency": "USD"},
"condition": "NEW",
"seller": {"username": "u"},
"itemWebUrl": "https://ebay.com/itm/999",
}
listing = normalise_listing(raw)
assert listing.photo_urls == []
def test_normalise_seller_maps_fields():
raw = {
"username": "techguy",
"feedbackScore": 300,
"feedbackPercentage": "99.1",
"registrationDate": "2020-03-01T00:00:00.000Z",
"sellerFeedbackSummary": {
"feedbackByCategory": [
{"transactionPercent": "95.0", "categorySite": "ELECTRONICS", "count": "50"}
]
}
}
seller = normalise_seller(raw)
assert seller.username == "techguy"
assert seller.feedback_count == 300
assert seller.feedback_ratio == pytest.approx(0.991, abs=0.001)
assert seller.account_age_days > 0