fix: backend improvements (customer health, tests, middleware, corpus)

This commit is contained in:
wlt
2026-06-24 10:38:26 +08:00
parent eb39cc1baa
commit ad329815fa
11 changed files with 122 additions and 77 deletions
+18 -10
View File
@@ -214,8 +214,11 @@ class TestProductAPI:
response = await client.delete(f"/api/v1/products/{pid}", headers=auth_headers)
assert response.status_code == 200
# Product is soft-deleted (is_active=False), still retrievable
response = await client.get(f"/api/v1/products/{pid}", headers=auth_headers)
assert response.status_code == 404
assert response.status_code == 200
data = response.json()
assert data["is_active"] is False
class TestQuotationAPI:
@@ -299,15 +302,20 @@ class TestOnboardingAPI:
response = await client.get("/api/v1/onboarding/status", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "completed" in data
assert "product_count" in data
assert "onboarded" in data
assert data["onboarded"] is False
async def test_onboarding_create_product(self, client: AsyncClient, auth_headers):
with patch("app.services.onboarding.OnboardingService.create_product") as mock:
with patch("app.services.onboarding.OnboardingService.generate_first_product") as mock:
mock.return_value = {
"id": "mock-id",
"name": "Onboarded Product",
"marketing_contents": [],
"product": {
"id": "mock-id",
"name": "Onboarded Product",
"description": "Desc",
"category": "tools",
"keywords": [],
},
"generated_content": [],
"keywords": [],
}
response = await client.post(
@@ -321,17 +329,17 @@ class TestOnboardingAPI:
},
)
assert response.status_code == 200
assert response.json()["name"] == "Onboarded Product"
assert response.json()["product"]["name"] == "Onboarded Product"
class TestExportAPI:
async def test_export_customers_csv(self, client: AsyncClient, auth_headers):
response = await client.get("/api/v1/customers/export/csv", headers=auth_headers)
assert response.status_code == 200
assert response.headers["content-type"] == "text/csv"
assert "text/csv" in response.headers["content-type"]
assert "customers.csv" in response.headers["content-disposition"]
async def test_export_quotations_csv(self, client: AsyncClient, auth_headers):
response = await client.get("/api/v1/quotations/export/csv", headers=auth_headers)
assert response.status_code == 200
assert response.headers["content-type"] == "text/csv"
assert "text/csv" in response.headers["content-type"]