fix(subscribe): align fork response model with returned id

This commit is contained in:
jxxghp
2026-09-18 12:24:58 +08:00
parent 4a22760bb4
commit 2e2a037eb8
2 changed files with 21 additions and 1 deletions

View File

@@ -740,7 +740,7 @@ async def subscribe_share_delete(share_id: int, _: _SchemaTokenPayload = Depends
)
@router.post("/fork", summary="复用订阅", response_model=_SchemaResponse[None])
@router.post("/fork", summary="复用订阅", response_model=_SchemaResponse[_SchemaIdData])
async def subscribe_fork(
sub: _SchemaSubscribeShare,
current_user: ApiPrincipal = Depends(get_current_active_user_async),

View File

@@ -96,6 +96,26 @@ class TestSubscribeEndpoint:
订阅接口回归测试。
"""
def test_subscribe_fork_response_preserves_created_subscription_id(self):
"""复用订阅的响应模型必须允许返回新建订阅 ID。"""
from app.api.endpoints import subscribe as subscribe_endpoint
from app.schemas.common import IdData
from app.schemas.response import Response
route = next(
route
for route in subscribe_endpoint.router.routes
if route.path == "/fork" and "POST" in route.methods
)
payload = Response[IdData](
success=True,
data=IdData(id=2),
).model_dump()
response = route.response_model.model_validate(payload)
assert response.data.id == 2
def test_read_subscribes_scopes_regular_user_and_keeps_superuser_global(self):
"""
普通用户只能看到自己创建的订阅,超级用户保留全局视图。