mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-07-08 18:52:32 +08:00
fix(logic): isolate atomic batch counters and token sync fields
This commit is contained in:
72
tests/test_account_token_sync_status.py
Normal file
72
tests/test_account_token_sync_status.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from src.database import crud
|
||||
from src.database.session import DatabaseSessionManager
|
||||
|
||||
|
||||
def test_create_account_marks_token_sync_pending_when_tokens_persist(tmp_path):
|
||||
manager = DatabaseSessionManager(f"sqlite:///{tmp_path}/test.db")
|
||||
manager.create_tables()
|
||||
manager.migrate_tables()
|
||||
|
||||
with manager.session_scope() as session:
|
||||
account = crud.create_account(
|
||||
session,
|
||||
email="sync@example.com",
|
||||
email_service="tempmail",
|
||||
access_token="access-token",
|
||||
refresh_token="refresh-token",
|
||||
)
|
||||
|
||||
assert account.token_sync_status == "pending"
|
||||
assert account.token_sync_updated_at is not None
|
||||
|
||||
|
||||
def test_update_account_marks_token_sync_pending_when_tokens_change(tmp_path):
|
||||
manager = DatabaseSessionManager(f"sqlite:///{tmp_path}/test.db")
|
||||
manager.create_tables()
|
||||
manager.migrate_tables()
|
||||
|
||||
with manager.session_scope() as session:
|
||||
account = crud.create_account(
|
||||
session,
|
||||
email="nosync@example.com",
|
||||
email_service="tempmail",
|
||||
)
|
||||
|
||||
assert account.token_sync_status == "not_ready"
|
||||
|
||||
updated = crud.update_account(
|
||||
session,
|
||||
account.id,
|
||||
access_token="new-access-token",
|
||||
)
|
||||
|
||||
assert updated is not None
|
||||
assert updated.token_sync_status == "pending"
|
||||
assert updated.token_sync_updated_at is not None
|
||||
|
||||
|
||||
def test_update_account_preserves_pending_status_when_other_tokens_remain(tmp_path):
|
||||
manager = DatabaseSessionManager(f"sqlite:///{tmp_path}/test.db")
|
||||
manager.create_tables()
|
||||
manager.migrate_tables()
|
||||
|
||||
with manager.session_scope() as session:
|
||||
account = crud.create_account(
|
||||
session,
|
||||
email="partial-sync@example.com",
|
||||
email_service="tempmail",
|
||||
access_token="access-token",
|
||||
refresh_token="refresh-token",
|
||||
)
|
||||
|
||||
updated = crud.update_account(
|
||||
session,
|
||||
account.id,
|
||||
refresh_token="",
|
||||
)
|
||||
|
||||
assert updated is not None
|
||||
assert updated.access_token == "access-token"
|
||||
assert updated.refresh_token == ""
|
||||
assert updated.token_sync_status == "pending"
|
||||
assert updated.token_sync_updated_at is not None
|
||||
Reference in New Issue
Block a user