snipe/tests/platforms/test_ebay_normaliser.py
pyr0ball f8dd1d261d
Some checks are pending
CI / Python tests (push) Waiting to run
CI / Frontend typecheck + tests (push) Waiting to run
Mirror / mirror (push) Waiting to run
feat: preferences store, community signals, a11y + API fixes
- Store: add save_community_signal, get/set_user_preference, get_all_preferences
- App.vue: move skip link before nav (correct a11y order); bootstrap preferences store after session
- useTrustFeedback: prefix fetch URL with VITE_API_BASE (fixes menagerie routing)
- search.ts: guard v-model.number empty-string from cleared price inputs
- Python: isort import ordering pass across adapters, trust, tasks, tests
2026-04-14 16:15:09 -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