"""날짜 칸 메모(2026-10-22, 마이그레이션 010) — API 규칙(종류·코드·길이·지우기·010 미적용 503), 매출·광고비 화면의 메모 표시, 기타광고비 채널.""" from __future__ import annotations import importlib from datetime import date import pytest from fastapi import FastAPI from fastapi.testclient import TestClient from app.modules.performance import ad_spend, common from app.modules.performance.db import MemoMigrationNeeded perf_router = importlib.import_module("app.modules.performance.router") class Store: def __init__(self, missing=False): self.saved, self.missing = [], missing def list_marketplaces(self): return [{"code": "coupang", "name": "쿠팡", "enabled": True, "include_in_sales": True, "manual_input": True}] def set_cell_memo(self, kind, code, day, memo, *, user=""): if self.missing: raise MemoMigrationNeeded() self.saved.append((kind, code, day, memo, user)) @pytest.fixture def client_store(monkeypatch): st = Store() monkeypatch.setattr(common, "require_store", lambda request, admin=False: (st, {"email": "me@x"})) app = FastAPI() app.include_router(perf_router.router) return TestClient(app), st def test_cell_memo_api(client_store): c, st = client_store r = c.put("/performance/api/cell-memos/sales/coupang/2026-10-05", json={"memo": " 행사 매출 포함\r\n2차 정산 예정 "}) assert r.status_code == 200 and r.json()["memo"] == "행사 매출 포함\n2차 정산 예정" assert st.saved[-1] == ("sales", "coupang", date(2026, 10, 5), "행사 매출 포함\n2차 정산 예정", "me@x") r = c.put("/performance/api/cell-memos/ad/etc/2026-10-30", json={"memo": "전단지"}) # 기타광고비·앞날도 됨 assert r.status_code == 200 and st.saved[-1][:2] == ("ad", "etc") assert c.put("/performance/api/cell-memos/ad/etc/2026-10-30", json={"memo": " "}).status_code == 200 assert st.saved[-1][3] is None # 빈 메모 = 지움 assert c.put("/performance/api/cell-memos/sales/nope/2026-10-05", json={"memo": "x"}).status_code == 404 assert c.put("/performance/api/cell-memos/ad/cafe24/2026-10-05", json={"memo": "x"}).status_code == 404 # 광고 채널 아님 assert c.put("/performance/api/cell-memos/other/coupang/2026-10-05", json={"memo": "x"}).status_code == 404 assert c.put("/performance/api/cell-memos/sales/coupang/2026-10-05", json={"memo": "가" * 1001}).status_code == 400 st.missing = True r = c.put("/performance/api/cell-memos/sales/coupang/2026-10-05", json={"memo": "x"}) assert r.status_code == 503 and "010" in r.json()["detail"] def test_etc_channel_has_no_roas(): assert ad_spend.CHANNEL_CODES[-2:] == ("atomy", "etc") and ad_spend.CHANNEL_NAMES["etc"] == "기타광고비" assert ad_spend.channel_roas("etc", lambda m: 1_000_000, 50_000) is None assert ad_spend.roas_basis("etc") == "" from app.modules.performance.dashboard import sales_ad_channels assert not any(ch == "etc" for lines in sales_ad_channels().values() for ch, _ in lines) # 매출 탭 광고비 줄에 안 나옴