"""E2E smoke test for nomadweb production APIs.""" from __future__ import annotations import json import sys import urllib.request sys.stdout.reconfigure(encoding="utf-8", errors="replace") BASE = "https://nomadweb.nomadro.com/api/v1" def req(method: str, path: str, body: dict | None = None, token: str | None = None) -> dict: headers = {"Content-Type": "application/json"} if token: headers["Authorization"] = f"Bearer {token}" data = json.dumps(body).encode() if body is not None else None r = urllib.request.Request(f"{BASE}{path}", data=data, headers=headers, method=method) with urllib.request.urlopen(r, timeout=30) as res: return json.loads(res.read().decode()) def main() -> None: demo = req("GET", "/auth/demo") token = demo["token"] print("demo login OK", demo["user"]["name"]) meetups = req("GET", "/meetups") online = next(m for m in meetups if m.get("mode") in ("online", "hybrid")) sess = req("GET", f"/meetups/{online['id']}/session") print("meetup session", online["id"], "canJoin=", sess.get("canJoin")) if sess.get("videoUrl"): print(" video:", sess["videoUrl"][:80]) if sess.get("chatUrl"): print(" chat:", sess["chatUrl"][:80]) join = req("POST", "/social/join", {"city": "清迈", "bio": "test", "lookingFor": ["friends"]}, token) print("social join OK", join.get("success")) candidates = req("GET", "/social/matches/candidates?intent=friends", None, token) print("candidates", len(candidates)) pay = req( "POST", "/pay/create", {"pay_type": "join", "return_url": "https://nomadweb.nomadro.com/join/paid", "provider": "zpay"}, token, ) print("pay create", pay["order_id"], pay["status"]) print(" redirect:", pay["redirect_url"][:120]) course = req("GET", "/digital/course") print("digital modules", len(course.get("modules", []))) if __name__ == "__main__": main()