git 저장소가 없어 히스토리·협업 기반이 아예 없던 상태를 연다.
함께 문서를 재편했다. 그동안 문서가 있어도 "이 제품이 뭘 푸는가"와
"어떻게 도는가"를 담은 문서가 없어서, 목표 문장이 backend/frontend
README 두 곳에 복붙돼 있었다 — 상위 문서가 없어 아래로 샌 것이다.
신설
README.md 레포 진입점 + 문서 지도 + 문서 규칙 4가지
AGENTS.md 에이전트·신규 합류자용 함정 목록과 규약
(CLAUDE.md 는 여기로 걸린 심볼릭 링크)
docs/PRODUCT.md 제품 정의 — 문제·사용자·원칙·**non-goals**·성공 기준
docs/ARCHITECTURE.md payload 경계·발행 파이프라인·서빙 결정·앱 분리 설계
이동
backend/docs/DECISIONS.md → docs/DECISIONS.md
백엔드만의 결정이 아니다. 게다가 코드 주석 ~25곳이 이미
`docs/DECISIONS.md` 로 적고 있어 레포 루트 기준으로는 그게 맞다.
갱신
docs/DEPLOY.md 서빙 결정 반영 — nginx 정적 서빙이 지금 경로(3절),
Azure 는 나중에 켤 때(4절)로 분리
docs/ARCHITECTURE.md 사이트 = 한 장(2026-08-31) 구조 반영
docs/COLLECTION_SEO_AEO_FLOW.md
robots.txt·sitemap.xml 은 오리진 루트에만 굽는다는 점 명시
frontend/site/scripts/prerender.ts
헤더 주석의 렌더 보고서 경로가 실제(422줄)와 달라 수정
.gitignore
★ CLAUDE.md 를 더 이상 무시하지 않는다. 에이전트 지침은 팀과 모든
에이전트가 공유하는 규약이라 커밋해야 한다 — 무시하면 클론한 사람이
"배포 후 republish_all.py 필수" 같은 함정을 전달받지 못한다.
개인용 오버라이드는 ~/.claude/CLAUDE.md 에 둔다.
200 lines
9.8 KiB
Python
200 lines
9.8 KiB
Python
"""동일 업소 후보 조회 — ★ 서버가 자동 확정하지 않고 사람이 고르게 한다.
|
|
|
|
남의 가게를 붙이는 게 이 서비스에서 제일 비싼 실수다(체크인 시간이 틀리면 실제 예약 클레임).
|
|
그래서 자동 판정이 MATCHED 여도 후보를 전부 내려보내 UI 가 확인시킬 수 있게 한다.
|
|
"""
|
|
from common.enums import ErrorType
|
|
from services.external import kakao as kakao_client
|
|
from services.external import naver as naver_client
|
|
|
|
|
|
def _np(name, addr, url=None):
|
|
return naver_client.NaverPlace(
|
|
name=name, road_address=addr, address=None, phone=None,
|
|
latitude=38.0, longitude=128.7, category_name="숙박>펜션",
|
|
place_url=url, naver_place_id=None,
|
|
)
|
|
|
|
|
|
def _match(outcome, place=None, candidates=None, reason=None):
|
|
return naver_client.MatchResult(
|
|
outcome=outcome, place=place, candidates=candidates or [], reason=reason, detail=None,
|
|
)
|
|
|
|
|
|
async def _place(client, h, name="핑크비치펜션"):
|
|
return (await client.post("/v1/place", headers=h, json={"name": name, "category": 1})).json()["place"]["place_id"]
|
|
|
|
|
|
def _patch_naver(monkeypatch, result):
|
|
"""네이버 판정을 고정값으로 바꾼다. 호출 인자를 그대로 돌려줘 호출측 규약도 볼 수 있게 한다."""
|
|
monkeypatch.setattr(kakao_client.KakaoLocalClient, "enabled", property(lambda self: False))
|
|
monkeypatch.setattr(naver_client.NaverLocalClient, "enabled", property(lambda self: True))
|
|
|
|
seen: dict = {}
|
|
|
|
async def _verify(self, name, address_hint=None, *, search_query=None):
|
|
seen["name"] = name
|
|
seen["search_query"] = search_query
|
|
return result
|
|
|
|
async def _close(self):
|
|
return None
|
|
|
|
monkeypatch.setattr(naver_client.NaverLocalClient, "verify_place", _verify)
|
|
monkeypatch.setattr(naver_client.NaverLocalClient, "aclose", _close)
|
|
return seen
|
|
|
|
|
|
async def test_single_match_is_auto_selectable(auth_headers, client, monkeypatch):
|
|
"""검증: 정확히 1건 일치하는 상호명.
|
|
기대결과: auto_selectable=true 로 내려오되 **후보는 그대로 내려온다** — UI 가 한 번 확인시킬 수 있다."""
|
|
only = _np("핑크비치펜션", "강원특별자치도 양양군 현북면 하조대3길 11", "http://pinkbeach.kr")
|
|
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.MATCHED, only, [only], "name_exact"))
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h)
|
|
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h)).json()
|
|
|
|
assert body["result"]["success"] is True
|
|
assert body["outcome"] == "matched"
|
|
assert body["auto_selectable"] is True
|
|
assert len(body["candidates"]) == 1
|
|
assert body["candidates"][0]["place_url"] == "http://pinkbeach.kr"
|
|
|
|
|
|
async def test_ambiguous_returns_all_candidates_for_ui(auth_headers, client, monkeypatch):
|
|
"""검증: 동명 업소가 여러 건이라 자동 판정이 안 된다.
|
|
기대결과: ★ auto_selectable=false + 후보 전체 — UI 가 목록을 그려 사람이 고른다."""
|
|
rows = [
|
|
_np("하조대펜션", "강원특별자치도 양양군 현북면 하조대3길 11"),
|
|
_np("하조대펜션", "강원특별자치도 양양군 현북면 하조대2길 48"),
|
|
_np("하조대펜션", "강원특별자치도 양양군 손양면 동명로 5"),
|
|
]
|
|
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.AMBIGUOUS, None, rows, "name_duplicate"))
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h, "하조대펜션")
|
|
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h)).json()
|
|
|
|
assert body["outcome"] == "ambiguous"
|
|
assert body["auto_selectable"] is False
|
|
assert len(body["candidates"]) == 3
|
|
assert body["reason"] == "name_duplicate"
|
|
# 사람이 고를 수 있게 주소가 다 실려 있어야 한다
|
|
assert len({c["road_address"] for c in body["candidates"]}) == 3
|
|
|
|
|
|
async def test_no_candidate_is_reported(auth_headers, client, monkeypatch):
|
|
"""검증: 외부 장소 DB 에 후보가 하나도 없다.
|
|
기대결과: PLACE_VERIFY_NO_CANDIDATE — 사장님이 직접 입력하는 경로로 안내해야 한다."""
|
|
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.NO_CANDIDATE, None, [], "empty"))
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h, "존재하지않는가게")
|
|
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h)).json()
|
|
assert body["result"]["code"] == ErrorType.PLACE_VERIFY_NO_CANDIDATE.value
|
|
|
|
|
|
async def test_picked_candidate_can_be_confirmed(auth_headers, client, monkeypatch):
|
|
"""검증: 후보 목록에서 하나를 골라 확정한다(UI 흐름 전체).
|
|
기대결과: 확정되고, 후보가 준 홈페이지가 공식 채널로 자동 등록된다."""
|
|
rows = [
|
|
_np("하조대펜션", "강원특별자치도 양양군 현북면 하조대3길 11", "http://hajodae-a.kr"),
|
|
_np("하조대펜션", "강원특별자치도 양양군 손양면 동명로 5", "http://hajodae-b.kr"),
|
|
]
|
|
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.AMBIGUOUS, None, rows, "name_duplicate"))
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h, "하조대펜션")
|
|
cands = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h)).json()["candidates"]
|
|
|
|
picked = cands[1] # 사람이 두 번째를 골랐다
|
|
r = (await client.post(f"/v1/place/{pid}/verify", headers=h, json={
|
|
"source": 2, "road_address": picked["road_address"],
|
|
"latitude": picked["latitude"], "longitude": picked["longitude"],
|
|
"place_url": picked["place_url"],
|
|
})).json()
|
|
assert r["result"]["success"] is True
|
|
assert r["place"]["road_address"] == "강원특별자치도 양양군 손양면 동명로 5"
|
|
|
|
links = (await client.get(f"/v1/place/{pid}/link/list", headers=h)).json()["links"]
|
|
official = [l for l in links if l["url"] == "http://hajodae-b.kr"]
|
|
assert official, "고른 후보의 홈페이지가 공식 채널로 등록되지 않았다"
|
|
assert official[0].get("confirmed_at") is None, "등록만 하고 확정은 따로다"
|
|
|
|
|
|
async def test_candidates_require_configured_source(auth_headers, client, monkeypatch):
|
|
"""검증: 카카오도 네이버도 키가 없다.
|
|
기대결과: LOCAL_NOT_CONFIGURED — 조용히 빈 목록을 주지 않는다."""
|
|
monkeypatch.setattr(kakao_client.KakaoLocalClient, "enabled", property(lambda self: False))
|
|
monkeypatch.setattr(naver_client.NaverLocalClient, "enabled", property(lambda self: False))
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h)
|
|
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h)).json()
|
|
assert body["result"]["code"] == ErrorType.LOCAL_NOT_CONFIGURED.value
|
|
|
|
|
|
async def test_candidates_scoped_to_company(auth_headers, client, other_company_id, monkeypatch):
|
|
"""검증: 다른 회사 계정으로 남의 사업장 후보를 조회한다.
|
|
기대결과: PLACE_NOT_FOUND."""
|
|
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.MATCHED, _np("a", "b"), [], "x"))
|
|
h1 = await auth_headers("o1")
|
|
pid = await _place(client, h1)
|
|
h2 = await auth_headers("o2", other_company_id)
|
|
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h2)).json()
|
|
assert body["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
|
|
|
|
|
async def test_region_stays_in_query_and_out_of_the_match_name(auth_headers, client, monkeypatch):
|
|
"""검증: 화면이 '상호명 + 위치'를 합쳐 query 로 보낸다.
|
|
기대결과: 검색어에는 지역이 그대로 실리고, 판정용 상호명에는 **상호만** 간다.
|
|
|
|
★ 왜 이걸 못 박아 두나: 판정(pick_match)은 후보 상호명과 정확일치를 본다. 지역이 붙은
|
|
문자열을 판정에 그대로 넘기면 정확일치가 구조적으로 성립할 수 없어, 후보가 단 1건인
|
|
경우까지 AMBIGUOUS 로 떨어진다 — 사장님은 매번 "비슷한 가게가 여럿입니다"를 읽는다.
|
|
실측(2026-08-28) 10건 전부 그랬다. 검색은 넓게, 판정은 좁게.
|
|
"""
|
|
only = _np("보사노바 커피로스터스 강릉점", "강원 강릉시 창해로14번길 28")
|
|
seen = _patch_naver(
|
|
monkeypatch, _match(kakao_client.MatchOutcome.MATCHED, only, [only], "name_exact")
|
|
)
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h, name="보사노바 커피로스터스 강릉점")
|
|
body = (
|
|
await client.get(
|
|
f"/v1/place/{pid}/verify/candidates",
|
|
headers=h,
|
|
params={"query": "보사노바 커피로스터스 강릉점 강릉 견소동"},
|
|
)
|
|
).json()
|
|
|
|
assert body["result"]["success"] is True
|
|
assert seen["search_query"] == "보사노바 커피로스터스 강릉점 강릉 견소동"
|
|
assert seen["name"] == "보사노바 커피로스터스 강릉점"
|
|
|
|
|
|
async def test_match_name_falls_back_to_query_when_place_has_no_name(auth_headers, client, monkeypatch):
|
|
"""검증: 사업장 상호가 비어 있다(직접 입력 등으로 이름 없이 만들어진 경우).
|
|
기대결과: 검색어를 판정용 상호명으로도 쓴다 — 조회 자체가 실패하지는 않는다."""
|
|
only = _np("핑크비치펜션", "강원특별자치도 양양군")
|
|
seen = _patch_naver(
|
|
monkeypatch, _match(kakao_client.MatchOutcome.MATCHED, only, [only], "name_exact")
|
|
)
|
|
|
|
h = await auth_headers("u1")
|
|
pid = await _place(client, h, name="핑크비치펜션")
|
|
# 상호를 비운다 — places.name 이 빈 문자열인 상태를 만든다.
|
|
await client.patch(f"/v1/place/{pid}", headers=h, json={"name": ""})
|
|
|
|
body = (
|
|
await client.get(
|
|
f"/v1/place/{pid}/verify/candidates", headers=h, params={"query": "핑크비치펜션 양양"}
|
|
)
|
|
).json()
|
|
|
|
assert body["result"]["success"] is True
|
|
assert seen["name"] == "핑크비치펜션 양양"
|