[refactor] solution/backend,frontend,postgres-init: 회사(테넌트) 제거 — 사장님 계정이 곧 스코프
가입 한 번이 회사를 하나 만들고 사장님이 그 회사의 직원이 됐다. 가입 폼은 "상호"를 묻고
에디터 헤더에는 "이름 · 회사명" 이 붙었다 — 쓰는 사람은 사장님 한 명인데.
negodata 보일러플레이트의 멀티테넌트 스코프 키를 그대로 물려받은 것이고,
DECISIONS.md 2절이 "대행사/운영사 단위로 그대로 쓴다" 로 유지 결정을 적어 뒀던 자리다.
- gmodel: `UserInfo.company_id` 삭제 — JWT 클레임에서도 사라진다. 스코프 키는 `user_id` 다
- place_crud·site_crud: WHERE 를 `places.owner_user_id` 로. `list_company_sites` → `list_owner_sites`
- place_service: **주인은 토큰이 정한다.** `Req_CreatePlace.owner_user_id` 를 없앴다 —
body 로 받으면 남의 계정을 적어 만들자마자 남의 목록에 넣을 수 있다.
실측: 기존 92건은 아무도 안 보내서 전부 NULL 이었고 스코프는 회사가 대신 하고 있었다
- 워커(collect·copy·build·vision): 잡 페이로드 키 `company_id` → `owner_user_id`.
잡이 세우는 `UserInfo.user_id` 는 이제 **사업장 주인**이다 — 예전엔 요청자·검증자·랜덤 uuid
순으로 채웠는데, 그 랜덤 uuid 가 스코프 키가 되는 순간 "남의 사업장" 이라 fact 조회가 0건이 된다
- auth: `Res_Me.company` · `Req_Signup.company_name` · `CompanyData` 삭제
- models·init.sql: `company.companies` 테이블 · `users.company_id` 삭제,
`places.owner_user_id` NOT NULL. 마이그레이션은 백필 → NOT NULL → DROP 순서다.
회사에 계정이 여럿이면 **가장 먼저 만든 계정**에게 몰고, 주인을 못 찾은 행은 지운다 —
스코프가 없으면 아무에게도 안 보이는 유령이다.
실측(로컬): place 92 → 91(고아 1건 삭제), `demoebf050` 56 · `test` 35
- 프론트: 가입 폼의 상호 칸, 내 정보의 상호 항목, 헤더의 "이름 · 회사명" 삭제
- 테스트: `company_id`/`other_company_id` 픽스처 → `owner_id` 하나.
격리는 `auth_headers("o2")` 를 한 번 더 부르면 그게 남이다
남긴 것 — DB 스키마 이름 `company` 는 그대로다. rename 은 모든 모델의 `__table_args__` 를
건드려야 해서 이번 변경에 섞지 않았다.
검증: 전체 568 passed(실패 1건은 HEAD 에서도 깨지는 레이트리밋 테스트) ·
프론트 tsc+eslint 통과 · 실제 API 로 가입→사업장→목록→격리→발행 한 바퀴
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLWEFx4X3XRmKewUKjJWow
This commit is contained in:
1 parent
00e13bca7f
commit
94551afdaf
53 files changed
+296
-456
No files matched your search
@@ -4,9 +4,9 @@
|
||||
"""
|
||||
|
||||
|
||||
async def test_login_and_me_flow(auth_headers, client, company_id):
|
||||
async def test_login_and_me_flow(auth_headers, client):
|
||||
"""검증: 시드된 유저가 로그인해 받은 토큰으로 /me 호출.
|
||||
기대결과: 200, 본인 id·name·소속사(company_id)가 그대로 반환."""
|
||||
기대결과: 200, 본인 id·name 이 그대로 반환."""
|
||||
h = await auth_headers("user1", name="홍길동")
|
||||
|
||||
r = await client.get("/v1/auth/me", headers=h)
|
||||
@@ -14,7 +14,8 @@ async def test_login_and_me_flow(auth_headers, client, company_id):
|
||||
me = r.json()
|
||||
assert me["id"] == "user1"
|
||||
assert me["name"] == "홍길동"
|
||||
assert me["company"]["company_id"] == company_id
|
||||
# ★ 소속사 필드는 없다. 회사(테넌트)를 걷어냈다(2026-09-08) — 쓰는 사람은 사장님 혼자다.
|
||||
assert "company" not in me
|
||||
|
||||
|
||||
async def test_login_with_wrong_password(auth_headers, client):
|
||||
@@ -49,7 +50,7 @@ _SIGNUP = {"id": "sajang1", "password": "pw12345678", "name": "김사장", "emai
|
||||
|
||||
async def test_signup_creates_account_and_logs_in(client, db_engine):
|
||||
"""검증: 가입 → 받은 토큰으로 곧바로 /me.
|
||||
기대결과: 토큰이 실려 오고, /me 가 방금 만든 신원과 **새로 생긴 소속사**를 돌려준다."""
|
||||
기대결과: 토큰이 실려 오고, /me 가 방금 만든 신원을 돌려준다."""
|
||||
r = await client.post("/v1/auth/signup", json=_SIGNUP)
|
||||
body = r.json()
|
||||
assert body["result"]["success"] is True
|
||||
@@ -59,7 +60,6 @@ async def test_signup_creates_account_and_logs_in(client, db_engine):
|
||||
assert me["id"] == "sajang1"
|
||||
assert me["email"] == "boss@example.com"
|
||||
assert me["provider"] == 1 # AuthProvider.LOCAL
|
||||
assert me["company"]["name"] == "김사장" # 회사명 미입력 → 이름으로 채운다
|
||||
|
||||
|
||||
async def test_signup_rejects_duplicate_id(client, db_engine):
|
||||
|
||||
@@ -264,12 +264,12 @@ async def test_versions_accumulate(auth_headers, client, db_engine):
|
||||
assert [v["version"] for v in versions] == [2, 1]
|
||||
|
||||
|
||||
async def test_site_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사이트를 본다.
|
||||
async def test_site_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사이트를 본다.
|
||||
기대결과: PLACE_NOT_FOUND."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _place(client, h1, "스코프펜션")
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.get(f"/v1/place/{pid}/site", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
@@ -156,13 +156,13 @@ async def test_targeted_collect_payload_carries_requested_confirmed_link(auth_he
|
||||
assert job["payload"]["link_ids"] == [confirmed]
|
||||
|
||||
|
||||
async def test_collect_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 수집을 시작한다.
|
||||
async def test_collect_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장 수집을 시작한다.
|
||||
기대결과: PLACE_NOT_FOUND — 사업장이 안 보이니 수집도 못 건다."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _place(client, h1, kakao="c7")
|
||||
await _confirmed_link(client, h1, pid)
|
||||
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.post(f"/v1/place/{pid}/collect", headers=h2, json={})
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
@@ -208,7 +208,7 @@ async def test_recollect_cannot_overwrite_corrected_value(auth_headers, client):
|
||||
assert check_in[0]["status"] == FactStatus.CORRECTED.value
|
||||
|
||||
|
||||
async def test_pipeline_refuses_unverified_place(db_engine, company_id):
|
||||
async def test_pipeline_refuses_unverified_place(db_engine, owner_id):
|
||||
"""검증: 검증 안 된 사업장의 수집 잡이 큐에 직접 들어간 경우(잡 적재 후 검증이 취소된 상황).
|
||||
기대결과: 잡이 실패한다 — ★ 잡 실행 시점에도 게이트를 다시 확인한다."""
|
||||
from sqlalchemy import text
|
||||
@@ -216,13 +216,13 @@ async def test_pipeline_refuses_unverified_place(db_engine, company_id):
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text("INSERT INTO places (place_id, company_id, name, category, status) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status) "
|
||||
"VALUES (:pid, :cid, :n, 1, 1)"),
|
||||
{"pid": pid, "cid": uuid.UUID(company_id), "n": "미검증펜션"},
|
||||
{"pid": pid, "cid": uuid.UUID(owner_id), "n": "미검증펜션"},
|
||||
)
|
||||
|
||||
q = JobQueue()
|
||||
job_id = await q.enqueue(JobType.COLLECT.value, {"place_id": str(pid), "company_id": company_id}, max_attempts=1)
|
||||
job_id = await q.enqueue(JobType.COLLECT.value, {"place_id": str(pid), "owner_user_id": owner_id}, max_attempts=1)
|
||||
worker = Worker("test-worker", q, build_handler(), backoff_fn=lambda _a: 0)
|
||||
await worker.process_one()
|
||||
|
||||
|
||||
@@ -269,12 +269,12 @@ async def test_crawl_only_does_not_mark_rebuild(auth_headers, client):
|
||||
assert place.get("content_updated_at") is None
|
||||
|
||||
|
||||
async def test_facts_are_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 fact 를 조회한다.
|
||||
async def test_facts_are_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장 fact 를 조회한다.
|
||||
기대결과: PLACE_NOT_FOUND — 사업장이 안 보이니 fact 도 안 보인다."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _verified_place(client, h1, kakao="p6")
|
||||
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.get(f"/v1/place/{pid}/fact/list", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
@@ -22,17 +22,17 @@ from common.enums import (
|
||||
)
|
||||
|
||||
|
||||
async def _seed_place(db_engine, company_id) -> str:
|
||||
async def _seed_place(db_engine, owner_id) -> str:
|
||||
"""검증까지 끝난 사업장 1개를 시드하고 place_id 를 돌려준다."""
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text(
|
||||
"INSERT INTO places (place_id, company_id, name, category, status, external_place_id, verified_at) "
|
||||
"INSERT INTO places (place_id, owner_user_id, name, category, status, external_place_id, verified_at) "
|
||||
"VALUES (:pid, :cid, :name, :cat, :status, :kakao, now())"
|
||||
),
|
||||
{
|
||||
"pid": pid, "cid": uuid.UUID(company_id), "name": "테스트펜션",
|
||||
"pid": pid, "cid": uuid.UUID(owner_id), "name": "테스트펜션",
|
||||
"cat": PlaceCategory.LODGING.value, "status": PlaceStatus.DRAFT.value,
|
||||
"kakao": "12345678",
|
||||
},
|
||||
@@ -54,20 +54,20 @@ async def _insert_fact(db_engine, place_id, key, value, status, unit_id=None):
|
||||
)
|
||||
|
||||
|
||||
async def test_published_fact_is_unique_per_place_and_key(db_engine, company_id):
|
||||
async def test_published_fact_is_unique_per_place_and_key(db_engine, owner_id):
|
||||
"""검증: 같은 사업장·같은 key 로 노출 상태 fact 를 두 번 넣는다.
|
||||
기대결과: 두 번째 INSERT 가 유니크 인덱스에 막힌다(체크인 시간이 두 값으로 갈라지지 않는다)."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.CORRECTED)
|
||||
|
||||
|
||||
async def test_candidates_coexist_with_published_value(db_engine, company_id):
|
||||
async def test_candidates_coexist_with_published_value(db_engine, owner_id):
|
||||
"""검증: 노출값이 있는 상태에서 재수집 후보를 여러 건 넣는다.
|
||||
기대결과: 전부 공존한다 — ★ 재수집이 노출 중인 사실을 밀어내지 않는다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.PENDING_OWNER)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "14:00", FactStatus.UNVERIFIED)
|
||||
@@ -80,10 +80,10 @@ async def test_candidates_coexist_with_published_value(db_engine, company_id):
|
||||
assert len(rows) == 3, "노출값 1건 + 후보 2건이 공존해야 한다"
|
||||
|
||||
|
||||
async def test_rejected_fact_frees_the_key(db_engine, company_id):
|
||||
async def test_rejected_fact_frees_the_key(db_engine, owner_id):
|
||||
"""검증: 기존 값을 REJECTED 로 내린 뒤 같은 key 를 새로 노출한다.
|
||||
기대결과: 통과 — 틀린 값은 이력으로 남고, 새 값이 노출 자리를 차지한다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.REJECTED)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.VERIFIED)
|
||||
|
||||
@@ -95,18 +95,18 @@ async def test_rejected_fact_frees_the_key(db_engine, company_id):
|
||||
assert len(rows) == 2, "REJECTED 이력과 새 값이 함께 남아야 한다"
|
||||
|
||||
|
||||
async def test_expired_fact_frees_the_key(db_engine, company_id):
|
||||
async def test_expired_fact_frees_the_key(db_engine, owner_id):
|
||||
"""검증: 유효기간이 지나 EXPIRED 로 내린 값과 새 수집값의 공존.
|
||||
기대결과: 통과 — EXPIRED 도 유니크에서 빠진다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "cancel_policy", "구 규정", FactStatus.EXPIRED)
|
||||
await _insert_fact(db_engine, place_id, "cancel_policy", "새 규정", FactStatus.VERIFIED)
|
||||
|
||||
|
||||
async def test_same_key_allowed_across_units(db_engine, company_id):
|
||||
async def test_same_key_allowed_across_units(db_engine, owner_id):
|
||||
"""검증: 객실이 다르면 같은 key 를 각각 가질 수 있는지.
|
||||
기대결과: 통과 — A동·B동이 각자의 기준 인원을 갖는다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
unit_a, unit_b = uuid.uuid4(), uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
for uid, name in ((unit_a, "A동"), (unit_b, "B동")):
|
||||
@@ -122,10 +122,10 @@ async def test_same_key_allowed_across_units(db_engine, company_id):
|
||||
await _insert_fact(db_engine, place_id, "standard_capacity", "6", FactStatus.CORRECTED, unit_id=unit_a)
|
||||
|
||||
|
||||
async def test_unit_fact_and_place_fact_are_separate(db_engine, company_id):
|
||||
async def test_unit_fact_and_place_fact_are_separate(db_engine, owner_id):
|
||||
"""검증: 같은 key 를 사업장 단위와 객실 단위로 동시에 갖는 경우.
|
||||
기대결과: 통과 — 부분 인덱스가 unit_id NULL 여부로 갈라져 있다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
unit_id = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
|
||||
@@ -56,14 +56,14 @@ async def test_generated_faq_is_pending_and_not_publishable(auth_headers, client
|
||||
assert (await _list(client, h, pid, publishable_only=True)).get("faqs", []) == []
|
||||
|
||||
|
||||
async def test_other_company_cannot_read_or_touch_faq(auth_headers, client, db_engine, other_company_id):
|
||||
"""검증: 남의 회사 사용자가 place_id 를 알아내 FAQ 를 조회·전이한다.
|
||||
async def test_other_owner_cannot_read_or_touch_faq(auth_headers, client, db_engine):
|
||||
"""검증: 남의 사용자가 place_id 를 알아내 FAQ 를 조회·전이한다.
|
||||
기대결과: PLACE_NOT_FOUND — 존재 여부조차 알려주지 않는다."""
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place(client, h)
|
||||
fid = await _seed_generated_faq(db_engine, pid)
|
||||
|
||||
other = await auth_headers("u2", other_company_id)
|
||||
other = await auth_headers("u2")
|
||||
assert (await _list(client, other, pid))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
body = await _transition(client, other, pid, fid, {"status": FactStatus.VERIFIED.value})
|
||||
assert body["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
이 경로가 절대 하면 안 되는 것:
|
||||
- 사이트가 아직 없는 사업장을 빼는 것 — 위저드를 걸어오다 만 가게가 목록에서 사라지면
|
||||
사장님은 그걸 다시 찾을 길이 없다(에디터 주소를 아무도 기억하지 않는다).
|
||||
- 회사 스코프를 놓치는 것 — 남의 가게가 내 목록에 섞이면 그건 목록이 아니라 사고다.
|
||||
- 사장님 스코프를 놓치는 것 — 남의 가게가 내 목록에 섞이면 그건 목록이 아니라 사고다.
|
||||
- 단건(GET /v1/place/{id}/site)과 다른 재빌드 판정을 내는 것 — 목록과 에디터가 서로 다른
|
||||
답을 하면 사장님은 어느 쪽을 믿을지 알 수 없다.
|
||||
"""
|
||||
@@ -53,11 +53,11 @@ async def test_site_row_is_joined_into_the_line(auth_headers, client):
|
||||
assert row["status"] == SiteStatus.DRAFT.value
|
||||
|
||||
|
||||
async def test_other_company_sites_are_not_listed(auth_headers, client, other_company_id):
|
||||
"""검증: 회사(테넌트) 스코프. 남의 회사 사업장은 보이지 않는다.
|
||||
async def test_other_owners_sites_are_not_listed(auth_headers, client):
|
||||
"""검증: 사장님 스코프. 남의 사업장은 보이지 않는다.
|
||||
기대결과: 각자 자기 것만 1건."""
|
||||
mine = await auth_headers("my3")
|
||||
theirs = await auth_headers("my3b", other_company_id)
|
||||
theirs = await auth_headers("my3b")
|
||||
await _place(client, mine, "내펜션")
|
||||
await _place(client, theirs, "남의펜션")
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""places 도메인 e2e — 등록 / 동일 업소 검증 / 회사 스코프 / 채널 URL 확정 게이트.
|
||||
"""places 도메인 e2e — 등록 / 동일 업소 검증 / 사장님 스코프 / 채널 URL 확정 게이트.
|
||||
|
||||
★ 이 도메인의 핵심 규칙 두 개를 고정한다:
|
||||
1. 검증(verify) 전에는 채널 URL 을 확정할 수 없다 → 크롤링이 안 열린다
|
||||
2. 남의 회사 사업장은 '없음'으로 보인다
|
||||
2. 남의 사업장은 '없음'으로 보인다
|
||||
"""
|
||||
import uuid
|
||||
|
||||
@@ -61,7 +61,7 @@ async def test_verify_place_opens_collection(auth_headers, client):
|
||||
|
||||
|
||||
async def test_duplicate_kakao_place_is_allowed(auth_headers, client):
|
||||
"""검증: 같은 회사에서 같은 카카오 장소를 두 사업장에 붙인다.
|
||||
"""검증: 같은 사장님이 같은 카카오 장소를 두 사업장에 붙인다.
|
||||
기대결과: 둘 다 등록된다 — 한 사용자가 같은 실제 업장으로 여러 프로젝트를 만들 수 있다."""
|
||||
h = await auth_headers("u1")
|
||||
first = (await _create_place(client, h, "A펜션"))["place"]["place_id"]
|
||||
@@ -138,13 +138,13 @@ async def test_verify_without_any_identifier_is_rejected(auth_headers, client):
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_VERIFY_NO_CANDIDATE.value
|
||||
|
||||
|
||||
async def test_place_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장을 조회한다.
|
||||
async def test_place_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장을 조회한다.
|
||||
기대결과: PLACE_NOT_FOUND — 존재 자체가 보이지 않는다(IDOR 차단)."""
|
||||
h1 = await auth_headers("owner1")
|
||||
pid = (await _create_place(client, h1))["place"]["place_id"]
|
||||
|
||||
h2 = await auth_headers("owner2", other_company_id)
|
||||
h2 = await auth_headers("owner2")
|
||||
r = await client.get(f"/v1/place/{pid}", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ async def test_search_leaks_nothing_of_ours(client, monkeypatch):
|
||||
|
||||
item = (await client.get("/v1/place/search", params={"q": "하조대펜션"})).json()["items"][0]
|
||||
|
||||
for leaked in ("place_id", "company_id", "owner_user_id", "phone", "latitude", "longitude",
|
||||
for leaked in ("place_id", "owner_user_id", "phone", "latitude", "longitude",
|
||||
"external_place_id", "address"):
|
||||
assert leaked not in item, f"{leaked} 가 공개 응답에 나갔다"
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_empty_site_returns_actionable_failures():
|
||||
assert any(c["status"] == "fail" and c["recommendation"] for c in report["checks"])
|
||||
|
||||
|
||||
async def test_audit_api_is_company_scoped(auth_headers, client, other_company_id):
|
||||
async def test_audit_api_is_owner_scoped(auth_headers, client):
|
||||
h1 = await auth_headers("audit-owner")
|
||||
pid = (await client.post("/v1/place", headers=h1, json={"name": "진단가게", "category": 2})).json()["place"]["place_id"]
|
||||
|
||||
@@ -41,6 +41,6 @@ async def test_audit_api_is_company_scoped(auth_headers, client, other_company_i
|
||||
assert 0 <= own["aeo_score"] <= 100
|
||||
assert own["checks"]
|
||||
|
||||
h2 = await auth_headers("audit-other", other_company_id)
|
||||
h2 = await auth_headers("audit-other")
|
||||
denied = (await client.get(f"/v1/place/{pid}/site/audit", headers=h2)).json()
|
||||
assert denied["result"]["success"] is False
|
||||
@@ -13,14 +13,14 @@ from sqlalchemy import text
|
||||
from common.enums import PlaceCategory, PlaceStatus, SiteStatus
|
||||
|
||||
|
||||
async def _publish(db_engine, company_id, name, *, status, domain, thumb=None, minutes_ago=0):
|
||||
async def _publish(db_engine, owner_id, name, *, status, domain, thumb=None, minutes_ago=0):
|
||||
"""places + sites 를 직접 넣는다 — 여기서 보는 건 목록 조회지 빌드 파이프라인이 아니다."""
|
||||
pid, sid = uuid.uuid4(), uuid.uuid4()
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(
|
||||
text("INSERT INTO places (place_id, company_id, name, category, status, road_address, address, phone) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status, road_address, address, phone) "
|
||||
"VALUES (:p,:c,:n,:cat,:st,:road,:addr,:phone)"),
|
||||
{"p": pid, "c": uuid.UUID(company_id), "n": name, "cat": PlaceCategory.LODGING.value,
|
||||
{"p": pid, "c": uuid.UUID(owner_id), "n": name, "cat": PlaceCategory.LODGING.value,
|
||||
"st": PlaceStatus.PUBLISHED.value,
|
||||
"road": "강원특별자치도 양양군 현북면 하조대3길 12-3", "addr": "강원특별자치도 양양군 현북면 하광정리 1-2",
|
||||
"phone": "033-672-0000"},
|
||||
@@ -34,12 +34,12 @@ async def _publish(db_engine, company_id, name, *, status, domain, thumb=None, m
|
||||
return str(pid)
|
||||
|
||||
|
||||
async def test_발행된_사이트만_로그인_없이_보인다(client, db_engine, company_id):
|
||||
async def test_발행된_사이트만_로그인_없이_보인다(client, db_engine, owner_id):
|
||||
"""검증: 발행본 1개 + 미발행(DRAFT) 1개를 두고 인증 헤더 없이 부른다.
|
||||
기대결과: 발행본만 나온다."""
|
||||
await _publish(db_engine, company_id, "하조대펜션", status=SiteStatus.PUBLISHED.value,
|
||||
await _publish(db_engine, owner_id, "하조대펜션", status=SiteStatus.PUBLISHED.value,
|
||||
domain="hajodae", thumb="https://w4ai.o2o.kr/thumbs/hajodae.jpg")
|
||||
await _publish(db_engine, company_id, "아직펜션", status=SiteStatus.DRAFT.value, domain="notyet")
|
||||
await _publish(db_engine, owner_id, "아직펜션", status=SiteStatus.DRAFT.value, domain="notyet")
|
||||
|
||||
res = await client.get("/v1/showcase")
|
||||
|
||||
@@ -51,10 +51,10 @@ async def test_발행된_사이트만_로그인_없이_보인다(client, db_engi
|
||||
assert items[0]["category"] == PlaceCategory.LODGING.value
|
||||
|
||||
|
||||
async def test_개인정보와_내부값은_나가지_않는다(client, db_engine, company_id):
|
||||
async def test_개인정보와_내부값은_나가지_않는다(client, db_engine, owner_id):
|
||||
"""검증: 응답 항목의 키를 그대로 본다.
|
||||
기대결과: 상호명·업종·지역·주소·썸네일뿐. 지역은 시·군까지고 상세 주소는 없다."""
|
||||
await _publish(db_engine, company_id, "하조대펜션", status=SiteStatus.PUBLISHED.value, domain="hajodae")
|
||||
await _publish(db_engine, owner_id, "하조대펜션", status=SiteStatus.PUBLISHED.value, domain="hajodae")
|
||||
|
||||
item = (await client.get("/v1/showcase")).json()["items"][0]
|
||||
|
||||
@@ -66,10 +66,10 @@ async def test_개인정보와_내부값은_나가지_않는다(client, db_engin
|
||||
assert "하조대3길" not in body
|
||||
|
||||
|
||||
async def test_썸네일이_없으면_키가_없다(client, db_engine, company_id):
|
||||
async def test_썸네일이_없으면_키가_없다(client, db_engine, owner_id):
|
||||
"""★ 썸네일은 발행의 부수 효과라 실패할 수 있다(대표 사진이 없거나 CDN 이 죽었거나).
|
||||
그때 카드는 글자로 떨어져야지 목록에서 사라지면 안 된다."""
|
||||
await _publish(db_engine, company_id, "그림없는집", status=SiteStatus.PUBLISHED.value, domain="nopic")
|
||||
await _publish(db_engine, owner_id, "그림없는집", status=SiteStatus.PUBLISHED.value, domain="nopic")
|
||||
|
||||
item = (await client.get("/v1/showcase")).json()["items"][0]
|
||||
|
||||
@@ -77,9 +77,9 @@ async def test_썸네일이_없으면_키가_없다(client, db_engine, company_i
|
||||
assert "thumbnail_url" not in item
|
||||
|
||||
|
||||
async def test_최신_발행순이고_limit_로_자른다(client, db_engine, company_id):
|
||||
await _publish(db_engine, company_id, "먼저", status=SiteStatus.PUBLISHED.value, domain="first", minutes_ago=60)
|
||||
await _publish(db_engine, company_id, "나중", status=SiteStatus.PUBLISHED.value, domain="second", minutes_ago=1)
|
||||
async def test_최신_발행순이고_limit_로_자른다(client, db_engine, owner_id):
|
||||
await _publish(db_engine, owner_id, "먼저", status=SiteStatus.PUBLISHED.value, domain="first", minutes_ago=60)
|
||||
await _publish(db_engine, owner_id, "나중", status=SiteStatus.PUBLISHED.value, domain="second", minutes_ago=1)
|
||||
|
||||
items = (await client.get("/v1/showcase")).json()["items"]
|
||||
assert [i["name"] for i in items] == ["나중", "먼저"]
|
||||
|
||||
@@ -129,11 +129,11 @@ async def test_published_site_slug_is_locked(auth_headers, client, db_engine):
|
||||
assert same["site"]["domain"] == "published-stay"
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장 주소는 확인도 예약도 못 한다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장 주소는 확인도 예약도 못 한다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("slug5")
|
||||
intruder = await auth_headers("slug6", other_company_id)
|
||||
intruder = await auth_headers("slug6")
|
||||
pid = await _place(client, h)
|
||||
|
||||
assert (await _check(client, intruder, pid, "doflo"))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -99,11 +99,11 @@ async def test_published_site_template_is_not_locked(auth_headers, client, db_en
|
||||
assert changed["needs_rebuild"] is True
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장의 템플릿은 바꿀 수 없다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장의 템플릿은 바꿀 수 없다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("tpl6")
|
||||
intruder = await auth_headers("tpl7", other_company_id)
|
||||
intruder = await auth_headers("tpl7")
|
||||
pid = await _place(client, h)
|
||||
|
||||
blocked = await _set_template(client, intruder, pid, "stay-quiet-margin")
|
||||
|
||||
@@ -129,11 +129,11 @@ async def test_published_site_theme_is_not_locked(auth_headers, client, db_engin
|
||||
assert changed["needs_rebuild"] is True
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장의 디자인은 바꿀 수 없다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장의 디자인은 바꿀 수 없다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("thm7")
|
||||
intruder = await auth_headers("thm8", other_company_id)
|
||||
intruder = await auth_headers("thm8")
|
||||
pid = await _place(client, h)
|
||||
|
||||
assert (await _set_theme(client, intruder, pid, _THEME))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -10,13 +10,13 @@ from common.enums import FactStatus, MediaStatus, PlaceCategory, SourceType
|
||||
from services.snapshot import build_snapshot
|
||||
|
||||
|
||||
async def _seed(db_engine, company_id, category=PlaceCategory.LODGING):
|
||||
async def _seed(db_engine, owner_id, category=PlaceCategory.LODGING):
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(
|
||||
text("INSERT INTO places (place_id, company_id, name, category, status, road_address, phone, verified_at) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status, road_address, phone, verified_at) "
|
||||
"VALUES (:p,:c,:n,:cat,3,:addr,:tel,now())"),
|
||||
{"p": pid, "c": uuid.UUID(company_id), "n": "스냅샷펜션", "cat": category.value,
|
||||
{"p": pid, "c": uuid.UUID(owner_id), "n": "스냅샷펜션", "cat": category.value,
|
||||
"addr": "강원특별자치도 양양군 현북면 하조대3길 11", "tel": "033-000-0000"},
|
||||
)
|
||||
return pid
|
||||
@@ -53,10 +53,10 @@ class _Place:
|
||||
self.longitude = None
|
||||
|
||||
|
||||
async def test_only_publishable_facts_enter_snapshot(db_engine, company_id):
|
||||
async def test_only_publishable_facts_enter_snapshot(db_engine, owner_id):
|
||||
"""검증: 여러 상태의 fact 를 섞어 넣는다.
|
||||
기대결과: ★ VERIFIED·CORRECTED 만 스냅샷에 담긴다 — 미검증 값이 사이트로 새지 않는다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _fact(db_engine, pid, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
await _fact(db_engine, pid, "wifi", "true", FactStatus.CORRECTED)
|
||||
await _fact(db_engine, pid, "parking", "true", FactStatus.UNVERIFIED)
|
||||
@@ -69,10 +69,10 @@ async def test_only_publishable_facts_enter_snapshot(db_engine, company_id):
|
||||
assert keys == {"check_in_time", "wifi"}
|
||||
|
||||
|
||||
async def test_only_approved_media_enters_snapshot(db_engine, company_id):
|
||||
async def test_only_approved_media_enters_snapshot(db_engine, owner_id):
|
||||
"""검증: 승인/확인대기/반려 사진을 섞어 넣는다.
|
||||
기대결과: ★ APPROVED 만 담긴다 — Vision 신뢰도가 낮아 확인 큐에 남은 사진은 안 나간다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _media(db_engine, pid, "https://cdn.test/ok.jpg", MediaStatus.APPROVED)
|
||||
await _media(db_engine, pid, "https://cdn.test/pending.jpg", MediaStatus.PENDING_REVIEW)
|
||||
await _media(db_engine, pid, "https://cdn.test/no.jpg", MediaStatus.REJECTED)
|
||||
@@ -81,10 +81,10 @@ async def test_only_approved_media_enters_snapshot(db_engine, company_id):
|
||||
assert [m["url"] for m in snap["media"]] == ["https://cdn.test/ok.jpg"]
|
||||
|
||||
|
||||
async def test_media_without_alt_is_excluded(db_engine, company_id):
|
||||
async def test_media_without_alt_is_excluded(db_engine, owner_id):
|
||||
"""검증: 승인됐지만 alt 텍스트가 없는 사진.
|
||||
기대결과: 빠진다 — alt 없는 이미지는 접근성도 AI 검색 신호도 없다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _media(db_engine, pid, "https://cdn.test/noalt.jpg", MediaStatus.APPROVED, alt="")
|
||||
await _media(db_engine, pid, "https://cdn.test/withalt.jpg", MediaStatus.APPROVED, alt="침실 사진")
|
||||
|
||||
@@ -92,10 +92,10 @@ async def test_media_without_alt_is_excluded(db_engine, company_id):
|
||||
assert [m["url"] for m in snap["media"]] == ["https://cdn.test/withalt.jpg"]
|
||||
|
||||
|
||||
async def test_fact_labels_come_from_category_schema(db_engine, company_id):
|
||||
async def test_fact_labels_come_from_category_schema(db_engine, owner_id):
|
||||
"""검증: 스냅샷의 fact 라벨.
|
||||
기대결과: 업종 스키마의 한글 라벨이 붙는다 — 화면이 key 를 그대로 노출하지 않게."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _fact(db_engine, pid, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
|
||||
snap = await build_snapshot(_Place(pid))
|
||||
@@ -104,10 +104,10 @@ async def test_fact_labels_come_from_category_schema(db_engine, company_id):
|
||||
assert f["scope"] == "place"
|
||||
|
||||
|
||||
async def test_unit_scoped_facts_carry_unit_id(db_engine, company_id):
|
||||
async def test_unit_scoped_facts_carry_unit_id(db_engine, owner_id):
|
||||
"""검증: 객실 단위 fact.
|
||||
기대결과: unit_id 가 실려 빌더가 객실별로 묶을 수 있다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
uid = uuid.uuid4()
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(text("INSERT INTO units (unit_id, place_id, name, sort_order) VALUES (:u,:p,:n,0)"),
|
||||
@@ -120,10 +120,10 @@ async def test_unit_scoped_facts_carry_unit_id(db_engine, company_id):
|
||||
assert snap["facts"][0]["scope"] == "unit"
|
||||
|
||||
|
||||
async def test_empty_place_gives_empty_snapshot(db_engine, company_id):
|
||||
async def test_empty_place_gives_empty_snapshot(db_engine, owner_id):
|
||||
"""검증: 아무것도 없는 사업장.
|
||||
기대결과: 빈 스냅샷 — 게이트가 고유 콘텐츠 0건으로 거부할 재료가 된다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
snap = await build_snapshot(_Place(pid))
|
||||
assert snap["facts"] == [] and snap["media"] == [] and snap["faqs"] == []
|
||||
assert snap["place"]["name"] == "스냅샷펜션"
|
||||
@@ -156,13 +156,13 @@ class _RegionPlace(_Place):
|
||||
self.region_code = region_code
|
||||
|
||||
|
||||
async def test_only_published_local_content_enters_snapshot(db_engine, company_id):
|
||||
async def test_only_published_local_content_enters_snapshot(db_engine, owner_id):
|
||||
"""검증: 검수대기·종료·발행 지역 정보를 섞어 넣는다.
|
||||
기대결과: ★ PUBLISHED 만 담긴다 — 운영자가 검수하지 않은 외부 API 원문이 사이트로 새면
|
||||
'미검증 값 노출 금지'가 깨진다(fact 를 VERIFIED 로 거르는 것과 같은 규칙)."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "발행축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.REVIEW, "검수대기축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.ENDED, "종료축제")
|
||||
@@ -171,7 +171,7 @@ async def test_only_published_local_content_enters_snapshot(db_engine, company_i
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["발행축제"]
|
||||
|
||||
|
||||
async def test_local_content_outside_display_window_is_excluded(db_engine, company_id):
|
||||
async def test_local_content_outside_display_window_is_excluded(db_engine, owner_id):
|
||||
"""검증: 발행됐지만 노출 기간을 벗어난 지역 정보.
|
||||
기대결과: 빠진다 — 끝난 축제를 '이번 주말 행사'로 걸어두는 것도 틀린 정보다."""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
@@ -179,7 +179,7 @@ async def test_local_content_outside_display_window_is_excluded(db_engine, compa
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "지금축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "끝난축제",
|
||||
display_end_at=now - timedelta(days=1))
|
||||
@@ -190,12 +190,12 @@ async def test_local_content_outside_display_window_is_excluded(db_engine, compa
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["지금축제"]
|
||||
|
||||
|
||||
async def test_local_content_is_scoped_to_the_places_region(db_engine, company_id):
|
||||
async def test_local_content_is_scoped_to_the_places_region(db_engine, owner_id):
|
||||
"""검증: 지역 캐시는 region_code 로 묶인다.
|
||||
기대결과: 다른 지역의 발행 콘텐츠는 담기지 않는다."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "우리지역축제")
|
||||
await _local(db_engine, "5011025", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "남의지역축제")
|
||||
|
||||
@@ -203,7 +203,7 @@ async def test_local_content_is_scoped_to_the_places_region(db_engine, company_i
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["우리지역축제"]
|
||||
|
||||
|
||||
async def test_region_code_is_derived_from_the_address_when_missing(db_engine, company_id):
|
||||
async def test_region_code_is_derived_from_the_address_when_missing(db_engine, owner_id):
|
||||
"""검증: region_code 가 비어 있지만 도로명주소는 있는 사업장.
|
||||
기대결과: 주소에서 지역 키를 유도해 그 지역 콘텐츠를 담는다 — places.region_code 를 채우는
|
||||
코드가 생기기 전에 만들어진 사업장(실측 28곳 중 25곳)이 영영 지역 정보 없이 발행되지 않게 한다."""
|
||||
@@ -211,7 +211,7 @@ async def test_region_code_is_derived_from_the_address_when_missing(db_engine, c
|
||||
from services.external.naver import region_key
|
||||
|
||||
derived = region_key(_Place("x").road_address)
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, derived, LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "양양축제")
|
||||
|
||||
snap = await build_snapshot(_RegionPlace(pid, ""))
|
||||
@@ -219,12 +219,12 @@ async def test_region_code_is_derived_from_the_address_when_missing(db_engine, c
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["양양축제"]
|
||||
|
||||
|
||||
async def test_place_without_any_region_key_gets_no_local_content(db_engine, company_id):
|
||||
async def test_place_without_any_region_key_gets_no_local_content(db_engine, owner_id):
|
||||
"""검증: 지역 코드도 읽을 만한 주소도 없는 사업장.
|
||||
기대결과: 빈 목록 — 조회할 캐시 키가 없다. 지어내지 않는다."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "어딘가축제")
|
||||
|
||||
place = _RegionPlace(pid, "")
|
||||
|
||||
@@ -136,13 +136,13 @@ async def test_candidates_require_configured_source(auth_headers, client, monkey
|
||||
assert body["result"]["code"] == ErrorType.LOCAL_NOT_CONFIGURED.value
|
||||
|
||||
|
||||
async def test_candidates_scoped_to_company(auth_headers, client, other_company_id, monkeypatch):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 후보를 조회한다.
|
||||
async def test_candidates_scoped_to_owner(auth_headers, client, 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)
|
||||
h2 = await auth_headers("o2")
|
||||
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h2)).json()
|
||||
assert body["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
Reference in new issue
Block a user