fix(site): 修复手动新增站点失败 (#6531)

This commit is contained in:
jxxghp
2026-09-01 19:33:01 +08:00
parent 3b4d7399bf
commit 297c0d798d
2 changed files with 16 additions and 0 deletions

View File

@@ -149,6 +149,7 @@ class SiteMutationCommand:
if await self._repository.async_get_by_domain(domain):
return SiteMutationResult(False, f"{domain} 站点己存在")
values.pop("id", None)
values.update(
{
"domain": domain,

View File

@@ -4,6 +4,7 @@ import pytest
from app.application.site.contract import SiteMutation, SitePriorityMutation
from app.application.site.mutation import SiteMutationCommand
from app.schemas.site import Site
def _command(**overrides):
@@ -56,6 +57,20 @@ async def test_create_site_commits_before_updated_event():
assert mutation.values["public"] == 1
@pytest.mark.asyncio
async def test_create_site_ignores_schema_identity_field():
"""手动新增站点应忽略请求 Schema 自动补出的空主键。"""
command, dependencies = _command()
result = await command.create(
Site(url="https://demo.example/path").model_dump()
)
assert result.success is True
mutation = dependencies["repository"].stage_create.await_args.args[0]
assert "id" not in mutation.values
@pytest.mark.asyncio
async def test_update_site_returns_legacy_not_found_without_writes():
"""更新不存在站点时保持失败响应且不产生事务或事件。"""