feat(fulfillment): 增加订单匹配起算时间
This commit is contained in:
@@ -5,12 +5,23 @@ from __future__ import annotations
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from web.backend.models import PlatformFulfillmentTask, User
|
||||
from web.backend.models import (
|
||||
PlatformFulfillmentSetting,
|
||||
PlatformFulfillmentTask,
|
||||
User,
|
||||
)
|
||||
from web.backend.services.platform_fulfillment import auto_allocator
|
||||
|
||||
|
||||
def test_auto_allocator_only_scans_ready_unassigned_tasks(db):
|
||||
actor = User(username="auto-alloc-actor", password_hash="h", role="super_admin")
|
||||
db.add(
|
||||
PlatformFulfillmentSetting(
|
||||
id=1,
|
||||
lease_duration_minutes=None,
|
||||
order_match_started_at=datetime.now(UTC) - timedelta(days=1),
|
||||
)
|
||||
)
|
||||
ready = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="1",
|
||||
@@ -35,7 +46,20 @@ def test_auto_allocator_only_scans_ready_unassigned_tasks(db):
|
||||
exchange_status="not_started",
|
||||
updated_at=datetime.now(UTC) - timedelta(minutes=2),
|
||||
)
|
||||
db.add_all([actor, ready, mapped_pending])
|
||||
old_ready = PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="3",
|
||||
source_order_item_id="3",
|
||||
platform_order_id="AUTO-OLD",
|
||||
internal_sku_key="skin",
|
||||
commodity_id="commodity-1",
|
||||
execution_status="ready",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
created_at=datetime.now(UTC) - timedelta(days=2),
|
||||
updated_at=datetime.now(UTC) - timedelta(days=2),
|
||||
)
|
||||
db.add_all([actor, ready, mapped_pending, old_ready])
|
||||
db.commit()
|
||||
|
||||
calls: list[int] = []
|
||||
@@ -45,8 +69,7 @@ def test_auto_allocator_only_scans_ready_unassigned_tasks(db):
|
||||
auto_allocator.service,
|
||||
"allocate_task",
|
||||
side_effect=lambda _db, *, task_id, current: (
|
||||
calls.append(task_id)
|
||||
or {"task": {"account": {"id": 9}}}
|
||||
calls.append(task_id) or {"task": {"account": {"id": 9}}}
|
||||
),
|
||||
),
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user