feat(performance): 자동 업데이트가 끝나면 매출 실적·광고비 화면 새로 고침
- 화면이 20초마다 GET /api/update-status?kind=sales|ads 로 마지막으로 끝난 업데이트를 보고, 그린 때(update_watch.seen)와 다르고 도는 중이 아니면 reload (jobs.last_finished — 메모리만, DB 안 읽음) - 보는 사람이 직접 누른 업데이트는 제외(진행 창이 새로 그림), 매출·광고비 따로 - 칸 입력·창·메뉴·확인 창이 열려 있으면 닫힐 때까지 기다리고 "새 데이터 있음" 안내, 탭이 안 보이면 안 물음 - 테스트: last_finished·update-status API, 브라우저(새로 고침·기다림·종류별) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""화면 자동 새로 고침(2026-10-26) — 자동 업데이트가 끝나면 매출 실적·광고비 화면이 알아채도록:
|
||||
jobs.last_finished(종류별·보는 사람 것 제외) · GET /api/update-status · 화면 데이터 update_watch."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import time
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.modules.performance import auto_sync, common, jobs
|
||||
|
||||
perf_router = importlib.import_module("app.modules.performance.router")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clean_jobs(monkeypatch):
|
||||
monkeypatch.setattr(jobs, "_JOBS", {})
|
||||
|
||||
|
||||
def _job(kind="sales", user=auto_sync.AUTO_USER, finished=True, at=None):
|
||||
j = jobs.create_job(user=user, start=None, end=None, kind=kind)
|
||||
if finished:
|
||||
j.finish()
|
||||
if at is not None:
|
||||
j.finished_at = at
|
||||
return j
|
||||
|
||||
|
||||
def test_last_finished_by_kind_and_excludes_viewer():
|
||||
assert jobs.last_finished("sales") is None
|
||||
a = _job(at=time.time() - 100)
|
||||
b = _job(user="me@x", at=time.time() - 10) # 보는 사람이 누른 것 — 진행 창이 알아서 새로 그림
|
||||
ad = _job(kind="ads", at=time.time())
|
||||
_job(finished=False) # 도는 중인 작업은 아님
|
||||
assert jobs.last_finished("sales") is b
|
||||
assert jobs.last_finished("sales", exclude_user="me@x") is a
|
||||
assert jobs.last_finished("ads", exclude_user="me@x") is ad
|
||||
assert perf_router._update_watch("sales", {"email": "me@x"}) == {"kind": "sales", "seen": a.id}
|
||||
assert perf_router._update_watch("ads", {"email": "other@x"}) == {"kind": "ads", "seen": ad.id}
|
||||
|
||||
|
||||
def test_update_status_api(monkeypatch):
|
||||
monkeypatch.setattr(common, "require_store", lambda request, admin=False: (object(), {"email": "me@x"}))
|
||||
app = FastAPI()
|
||||
app.include_router(perf_router.router)
|
||||
c = TestClient(app)
|
||||
assert c.get("/performance/api/update-status?kind=sales").json() == {"kind": "sales", "running": False, "done": "", "user": ""}
|
||||
run = _job(finished=False)
|
||||
r = c.get("/performance/api/update-status?kind=sales").json()
|
||||
assert r["running"] and r["done"] == ""
|
||||
run.finish()
|
||||
r = c.get("/performance/api/update-status?kind=sales").json()
|
||||
assert r == {"kind": "sales", "running": False, "done": run.id, "user": auto_sync.AUTO_USER}
|
||||
_job(user="me@x") # 내 업데이트는 done 을 바꾸지 않는다
|
||||
assert c.get("/performance/api/update-status?kind=sales").json()["done"] == run.id
|
||||
assert c.get("/performance/api/update-status?kind=ads").json()["done"] == "" # 광고비는 따로
|
||||
assert c.get("/performance/api/update-status?kind=nope").status_code == 404
|
||||
Reference in New Issue
Block a user