feat: 나만의 각 1단계 — 공식 각 두 개를 섞어 내 각 만들기(점수는 낮은 쪽), 로그인 없이 1개·로그인하면 계정 저장, 친구에게 보낸 링크로 내 동네 점수 보기
This commit is contained in:
1 parent
96cbd19c61
commit
a8a126f6a5
18 files changed
+842
-6
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from crud.index_crud import IndexCRUD
|
||||
from router.router import app
|
||||
from services.my_gak_service import MAX_PER_USER
|
||||
|
||||
|
||||
def client():
|
||||
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
|
||||
|
||||
|
||||
async def _login(c, login_id: str) -> dict:
|
||||
body = (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": "섞기토끼"})).json()
|
||||
return {"Authorization": f"Bearer {body['access_token']}"}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_mixable_without_login_excludes_life_gak():
|
||||
async with client() as c:
|
||||
body = (await c.get("/v1/my-gak")).json()
|
||||
_, defs = await DB_SESSION_MNG.execute_lambda(lambda s: IndexCRUD().definitions(s))
|
||||
ids = {d.name: d.index_id for d in defs}
|
||||
assert body["items"] == []
|
||||
mixable = set(body["mixable"])
|
||||
assert {ids["러닝각"], ids["치맥각"]} <= mixable
|
||||
assert not {ids["우산각"], ids["교통체증각"]} & mixable
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_add_list_delete_and_same_pair_is_one():
|
||||
async with client() as c:
|
||||
assert (await c.post("/v1/my-gak", json={"index_ids": [1, 2]})).status_code == 401
|
||||
h = await _login(c, "mix_01")
|
||||
a, b = sorted((await c.get("/v1/my-gak")).json()["mixable"])[:2]
|
||||
first = (await c.post("/v1/my-gak", json={"index_ids": [b, a]}, headers=h)).json()["item"]
|
||||
assert first["index_ids"] == [a, b]
|
||||
again = (await c.post("/v1/my-gak", json={"index_ids": [a, b]}, headers=h)).json()["item"]
|
||||
assert again["my_gak_id"] == first["my_gak_id"]
|
||||
assert [g["my_gak_id"] for g in (await c.get("/v1/my-gak", headers=h)).json()["items"]] == [first["my_gak_id"]]
|
||||
assert (await c.delete(f"/v1/my-gak/{first['my_gak_id']}", headers=h)).json()["result"]["success"] is True
|
||||
assert (await c.get("/v1/my-gak", headers=h)).json()["items"] == []
|
||||
assert (await c.delete(f"/v1/my-gak/{first['my_gak_id']}", headers=h)).json()["result"]["desc"] == "NOT_FOUND"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_rejects_same_gak_unmixable_and_over_limit():
|
||||
async with client() as c:
|
||||
h = await _login(c, "mix_02")
|
||||
mixable = sorted((await c.get("/v1/my-gak")).json()["mixable"])
|
||||
bad = lambda ids: c.post("/v1/my-gak", json={"index_ids": ids}, headers=h) # noqa: E731
|
||||
assert (await bad([mixable[0], mixable[0]])).json()["result"]["desc"] == "INVALID_INPUT"
|
||||
assert (await bad([mixable[0], 9999])).json()["result"]["desc"] == "INVALID_INPUT"
|
||||
assert (await bad([mixable[0]])).status_code == 422
|
||||
pairs = [(mixable[0], x) for x in mixable[1 : MAX_PER_USER + 1]]
|
||||
for p in pairs:
|
||||
assert (await bad(list(p))).json()["item"]
|
||||
assert (await bad([mixable[1], mixable[2]])).json()["result"]["desc"] == "INVALID_INPUT"
|
||||
Reference in new issue
Block a user