95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
from uuid import uuid4
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
from app.main import app
|
|
from app.db.models import AppUser
|
|
from app.features.admin.deps import get_admin_service, get_current_admin
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_public_plans(async_client: AsyncClient) -> None:
|
|
response = await async_client.get("/api/plans")
|
|
assert response.status_code == 200
|
|
assert isinstance(response.json(), list)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_admin_plans_list_with_eur(
|
|
async_client: AsyncClient,
|
|
sample_admin: AppUser,
|
|
) -> None:
|
|
mock_service = MagicMock()
|
|
mock_plans = [
|
|
{
|
|
"base_code": "POINTS_ACU",
|
|
"name": "Acu Points Module (1 Yr)",
|
|
"description": "",
|
|
"plan_type": "single_module",
|
|
"billing_period": "yearly",
|
|
"is_active": True,
|
|
"price_inr": 300.0,
|
|
"price_usd": 5.0,
|
|
"price_eur": 5.0,
|
|
"modules": [],
|
|
"module_ids": [],
|
|
"subscribers_count": 0,
|
|
}
|
|
]
|
|
mock_service.plans = MagicMock()
|
|
mock_service.plans.list_plans = AsyncMock(return_value=mock_plans)
|
|
mock_service.list_plans = AsyncMock(return_value=mock_plans)
|
|
|
|
app.dependency_overrides[get_current_admin] = lambda: sample_admin
|
|
app.dependency_overrides[get_admin_service] = lambda: mock_service
|
|
|
|
try:
|
|
response = await async_client.get(
|
|
"/api/admin/plans",
|
|
headers={"Authorization": "Bearer admin_token"},
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert len(data) == 1
|
|
assert data[0]["price_eur"] == 5.0
|
|
assert data[0]["price_usd"] == 5.0
|
|
assert data[0]["price_inr"] == 300.0
|
|
finally:
|
|
app.dependency_overrides.pop(get_current_admin, None)
|
|
app.dependency_overrides.pop(get_admin_service, None)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_admin_plans_update_pricing_with_eur(
|
|
async_client: AsyncClient,
|
|
sample_admin: AppUser,
|
|
) -> None:
|
|
mock_service = MagicMock()
|
|
mock_service.plans = MagicMock()
|
|
mock_service.plans.update_pricing = AsyncMock(return_value={
|
|
"status": "success",
|
|
"message": "Pricing and metadata for plan 'POINTS_ACU' updated successfully."
|
|
})
|
|
mock_service.update_plan_pricing = AsyncMock(return_value={
|
|
"status": "success",
|
|
"message": "Pricing and metadata for plan 'POINTS_ACU' updated successfully."
|
|
})
|
|
|
|
app.dependency_overrides[get_current_admin] = lambda: sample_admin
|
|
app.dependency_overrides[get_admin_service] = lambda: mock_service
|
|
|
|
try:
|
|
response = await async_client.put(
|
|
"/api/admin/plans/POINTS_ACU/pricing",
|
|
json={"price_inr": 300.0, "price_usd": 5.0, "price_eur": 6.0},
|
|
headers={"Authorization": "Bearer admin_token"},
|
|
)
|
|
assert response.status_code == 200
|
|
assert response.json()["status"] == "success"
|
|
finally:
|
|
app.dependency_overrides.pop(get_current_admin, None)
|
|
app.dependency_overrides.pop(get_admin_service, None)
|