feat(카페24): 대표 이미지(썸네일) 예약 교체

- 편집기 아래 「예약 적용」 폼에 대표 이미지 파일 칸 — 고르면 그 시각에 교체
  (상세페이지·진열·판매와 한 예약에 같이 걸 수 있음, 이미지만도 가능)
- 마이그레이션 006: 예약 image_type/image_name + cafe24_schedule_images(BYTEA, CASCADE),
  "할 일 없는 예약" CHECK 에 이미지 포함
- worker: 이미지 먼저 set_main_image(즉시 교체와 같은 A 타입) → 스냅샷 → 상세페이지·진열/판매
- 예약 목록 「적용 내용」에 대표이미지 표시 + 미리보기 썸네일(GET /cafe24/schedules/{id}/image)
- 이미지 없는 예약 INSERT 는 006 컬럼을 안 써서 마이그레이션 전에도 기존 예약 등록 유지
- 테스트(경로·검증·worker 순서)·문서 갱신, cafe24.css 캐시 버전 올림

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 16:38:05 +09:00
parent 36834c65b2
commit 6822329ff2
17 changed files with 286 additions and 45 deletions
+44
View File
@@ -583,6 +583,50 @@ def test_worker_real_db_success_and_needs_review():
assert q("SELECT status FROM cafe24_write_attempts WHERE schedule_id=%s", sid2)[0]["status"] == "RECORDED"
def test_schedule_main_image_route_and_worker():
"""대표 이미지 예약(006): 등록 → 파일 DB 보관 → 그 시각에 worker 가 교체 → 목록 미리보기."""
no, cafe = _new_product("<p>A</p>")
at = (now_kst() + timedelta(days=1)).strftime("%Y-%m-%dT%H:%M")
png = b"\x89PNG\r\n\x1a\n" + b"x" * 64
form = {"product_no": str(no), "scheduled_at": at, "set_display": "", "set_selling": ""}
# 내용 없는 예약(이미지도 안 고름 — 이름 없는 빈 파트) 거부
resp = req("POST", "/cafe24/schedules", data=form, files={"image": ("", b"", "application/octet-stream")})
assert "하나 이상" in _location(resp).get("err", ""), resp.headers
# 이미지 아닌 파일 거부
resp = req("POST", "/cafe24/schedules", data=form, files={"image": ("a.txt", b"hi", "text/plain")})
assert "이미지만" in _location(resp).get("err", ""), resp.headers
resp = req("POST", "/cafe24/schedules", data=form, files={"image": ("가을.png", png, "image/png")})
assert "대표이미지" in _location(resp).get("msg", ""), resp.headers
sid = q("SELECT id FROM cafe24_product_schedules WHERE product_no=%s", no)[0]["id"]
row = ST.get_schedule(sid)
assert row["image_type"] == "image/png" and row["image_name"] == "가을.png" and row["revision_id"] is None
got = req("GET", f"/cafe24/schedules/{sid}/image")
assert got.status_code == 200 and got.content == png and got.headers["content-type"] == "image/png"
listed = json.loads(req("GET", "/cafe24/schedules").text.split("\n", 1)[1])["rows"]
mine = [r for r in listed if r["id"] == sid][0]
assert mine["image_type"] == "image/png" and mine["action_label"] == "대표이미지", mine
q("UPDATE cafe24_product_schedules SET scheduled_at = now() - interval '3000 days' WHERE id=%s RETURNING id", sid)
worker.process_once(ST, fakes.FakeApi(MULTI))
row = ST.get_schedule(sid)
assert row["status"] == "SUCCESS", row
posts = [c for c in cafe.calls if c[0] == "POST" and c[1].endswith("/images")]
assert len(posts) == 1 and posts[0][2]["request"]["detail_image"].startswith("data:image/png;base64,")
assert cafe.state["detail_image"] == f"/web/product/detail/{no}_1.png"
assert [c for c in cafe.calls if c[0] == "PUT"] == [] # 이미지만 — 상세설명·진열 PUT 없음
assert ST.get_write_snapshot(no)["product"]["data"]["detail_image"] == cafe.state["detail_image"]
# 이미지 + 진열을 한 예약에: 이미지 먼저, 그다음 진열 PUT
no2, cafe2 = _new_product("<p>A</p>")
sid2 = ST.create_schedule(product_no=no2, scheduled_at=now_kst() - timedelta(days=3000), revision_id=None,
set_display=False, set_selling=None, image=png, image_type="image/png", image_name="b.png")
worker.process_once(ST, fakes.FakeApi(MULTI))
assert ST.get_schedule(sid2)["status"] == "SUCCESS"
kinds = [(c[0], c[1].rsplit("/", 1)[-1]) for c in cafe2.calls if c[0] in ("POST", "PUT")]
assert kinds == [("POST", "images"), ("PUT", str(no2))], kinds
assert cafe2.state["display"] == "F" and cafe2.state["detail_image"].endswith(f"{no2}_1.png")
def test_worker_real_db_recovers_crash_after_remote_ok():
no, cafe = _new_product("<p>A</p>")
rid = _draft(no, "<p>R</p>")