Skip to content

Commit e26d89b

Browse files
committed
fix: 修复测试配置问题
- 后端: DATABASE_URL 支持 SQLite/MySQL/PostgreSQL - 前端: 修复 auth store 测试断言
1 parent a5a67fa commit e26d89b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

apps/api/app/core/config.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import lru_cache
66
from typing import Literal
77

8-
from pydantic import PostgresDsn, computed_field
8+
from pydantic import computed_field, field_validator
99
from pydantic_settings import BaseSettings, SettingsConfigDict
1010

1111

@@ -31,7 +31,20 @@ class Settings(BaseSettings):
3131
WORKERS: int = 1
3232

3333
# ===== 数据库配置 =====
34-
DATABASE_URL: PostgresDsn = "postgresql+asyncpg://postgres:postgres@localhost:5432/querygpt"
34+
DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/querygpt"
35+
36+
@field_validator("DATABASE_URL")
37+
@classmethod
38+
def validate_database_url(cls, v: str) -> str:
39+
"""验证数据库 URL 格式"""
40+
valid_prefixes = (
41+
"postgresql://", "postgresql+asyncpg://",
42+
"sqlite://", "sqlite+aiosqlite://",
43+
"mysql://", "mysql+aiomysql://",
44+
)
45+
if not any(v.startswith(p) for p in valid_prefixes):
46+
raise ValueError(f"DATABASE_URL 必须以以下前缀开头: {valid_prefixes}")
47+
return v
3548

3649
# ===== Redis 配置 (可选) =====
3750
REDIS_URL: str | None = None

apps/web/tests/stores/auth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Auth Store", () => {
2626

2727
expect(state.user).toBeNull();
2828
expect(state.isAuthenticated).toBe(false);
29-
expect(state.isLoading).toBe(false);
29+
expect(state.accessToken).toBeNull();
3030
});
3131

3232
it("should have login function", async () => {

0 commit comments

Comments
 (0)