test(saas): Phase 1 integration tests — billing + scheduled_task + knowledge (68 tests)
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

- Fix TIMESTAMPTZ decode errors: add ::TEXT cast to all SELECT queries
  where Row structs use String for TIMESTAMPTZ columns (~22 locations)
- Fix Axum 0.7 route params: {id} → :id in billing/knowledge/scheduled_task routes
- Fix JSONB bind: scheduled_task INSERT uses ::jsonb cast for input_payload
- Add billing_test.rs (14 tests): plans, subscription, usage, payments, invoices
- Add scheduled_task_test.rs (12 tests): CRUD, validation, isolation
- Add knowledge_test.rs (20 tests): categories, items, versions, search, analytics, permissions
- Fix auth test regression: 6 tests were failing due to TIMESTAMPTZ type mismatch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-04-07 14:25:34 +08:00
parent a5b887051d
commit 7de486bfca
27 changed files with 1317 additions and 187 deletions

View File

@@ -63,8 +63,8 @@ pub async fn create_payment(
.bind(plan.price_cents)
.bind(&plan.currency)
.bind(format!("{} - {} ({})", plan.display_name, plan.interval, now.format("%Y-%m")))
.bind(due.to_rfc3339())
.bind(now.to_rfc3339())
.bind(&due)
.bind(&now)
.execute(&mut *tx)
.await?;
@@ -83,7 +83,7 @@ pub async fn create_payment(
.bind(&plan.currency)
.bind(req.payment_method.to_string())
.bind(&trade_no)
.bind(now.to_rfc3339())
.bind(&now)
.execute(&mut *tx)
.await?;
@@ -168,7 +168,7 @@ pub async fn handle_payment_callback(
tracing::warn!("DEV: Skipping amount verification for trade={}", sanitize_log(trade_no));
}
let now = chrono::Utc::now().to_rfc3339();
let now = chrono::Utc::now();
if status == "success" || status == "TRADE_SUCCESS" || status == "SUCCESS" {
// 3. 更新支付状态
@@ -211,8 +211,8 @@ pub async fn handle_payment_callback(
// 7. 创建新订阅30 天周期)
let sub_id = uuid::Uuid::new_v4().to_string();
let period_end = (chrono::Utc::now() + chrono::Duration::days(30)).to_rfc3339();
let period_start = chrono::Utc::now().to_rfc3339();
let period_end = chrono::Utc::now() + chrono::Duration::days(30);
let period_start = chrono::Utc::now();
sqlx::query(
"INSERT INTO billing_subscriptions \