295dbc09ab
- 简化套餐配置结构,删除冗余的 default.yaml 和 us.yaml - 优化 Apple IAP 服务和验证逻辑 - 更新套餐数据模型和协议文档 - 添加支付相关测试用例
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
"""
|
|
Integration tests for Apple IAP payment verify flow.
|
|
|
|
Prerequisite: backend must be running via `./infra/scripts/app.sh restart`.
|
|
These tests hit the live HTTP API against the test database.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_verify_endpoint_returns_401_without_auth() -> None:
|
|
import httpx
|
|
|
|
base_url = "http://localhost:8000"
|
|
try:
|
|
async with httpx.AsyncClient(base_url=base_url, timeout=5) as client:
|
|
response = await client.post(
|
|
"/api/v1/payments/apple/transactions/verify",
|
|
json={
|
|
"productCode": "starter_pack",
|
|
"appStoreProductId": "com.meeyao.qianwen.starter_pack",
|
|
"transactionId": "0000000000000001",
|
|
"signedTransactionInfo": "fake_jws",
|
|
},
|
|
)
|
|
assert response.status_code in (401, 403)
|
|
except httpx.ConnectError:
|
|
pytest.skip("Backend not running, skipping integration test")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_notifications_endpoint_returns_200() -> None:
|
|
import httpx
|
|
|
|
base_url = "http://localhost:8000"
|
|
try:
|
|
async with httpx.AsyncClient(base_url=base_url, timeout=5) as client:
|
|
response = await client.post(
|
|
"/api/v1/payments/apple/notifications",
|
|
json={"signedPayload": ""},
|
|
)
|
|
assert response.status_code == 200
|
|
except httpx.ConnectError:
|
|
pytest.skip("Backend not running, skipping integration test")
|