drive.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. set -e
  2. B=localhost:8787
  3. j(){ curl -s -b "$1" -c "$1" -H 'Content-Type: application/json' "${@:2}"; }
  4. # two members: anonymous sign-in, set names
  5. j /tmp/tom -X POST $B/api/auth/sign-in/anonymous -d '{}' >/dev/null; j /tmp/tom -X POST $B/api/me/name -d '{"name":"Tom"}' >/dev/null
  6. j /tmp/sam -X POST $B/api/auth/sign-in/anonymous -d '{}' >/dev/null; j /tmp/sam -X POST $B/api/me/name -d '{"name":"Sam"}' >/dev/null
  7. # phone OTP path smoke test
  8. j /tmp/phone -X POST $B/api/auth/phone-number/send-otp -d '{"phoneNumber":"+61400000000"}'; echo " <- send-otp"
  9. H=$(j /tmp/tom -X POST $B/api/hands -d '{"question":"Friday dinner","options":["Thai","Pizza","Ramen","Cook at home"],"constraints":["Sam is trying to spend less this month"]}' | python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])')
  10. echo "hand $H"
  11. A(){ j $1 -X POST $B/api/hands/$H/act -d "$2" >/dev/null; }
  12. A /tmp/tom '{"op":"join"}'; A /tmp/sam '{"op":"join"}'
  13. A /tmp/tom '{"op":"place","option":"o1","n":6}'; A /tmp/tom '{"op":"place","option":"o3","n":4}'
  14. A /tmp/sam '{"op":"place","option":"o2","n":8}'; A /tmp/sam '{"op":"place","option":"o4","n":2}'
  15. A /tmp/tom '{"op":"veto","option":"o2"}' # Tom vetoes pizza; Sam's 8 chips come back
  16. sleep 1.2
  17. curl -s $B/api/hands/$H | python3 -c '
  18. import sys,json; s=json.load(sys.stdin); r=s["round"]
  19. print("members",[m["name"] for m in s["members"]],"live",s["live"],"vetoed",r["vetoed"])
  20. print("chips",r["chips"])
  21. o=r["odds"]; print("odds", {k:round(v,2) for k,v in o["probabilities"].items()}, "conf",round(o["confidence"],2),"spice",round(o["spice"],2),"format",o["format"],"about",o["about"], o["ms"],"ms")'
  22. A /tmp/sam '{"op":"place","option":"o4","n":8}' # Sam goes all in on cooking
  23. sleep 0.6
  24. A /tmp/tom '{"op":"lock"}'; A /tmp/sam '{"op":"lock"}' # both locked -> lever pulls
  25. sleep 1.5
  26. curl -s $B/api/hands/$H | python3 -c '
  27. import sys,json; s=json.load(sys.stdin); r=s["round"]; p=r["pull"]
  28. lab=lambda i: next(o["label"] for o in r["options"] if o["id"]==i)
  29. print("status",s["status"]); print("odds at pull",{lab(k):round(v,2) for k,v in p["odds"].items()})
  30. print("WINNER",lab(p["winner"]),"| runner-up",lab(p["runnerUp"]),"| reel order",[lab(x) for x in p["order"]],"| seed",p["seed"])
  31. print("dealer:",p["dealer"])'
  32. A /tmp/tom '{"op":"again"}'; sleep 0.3
  33. A /tmp/tom '{"op":"place","option":"o1","n":10}'; A /tmp/sam '{"op":"place","option":"o1","n":10}'; sleep 1
  34. A /tmp/tom '{"op":"pull"}'; sleep 1.5
  35. A /tmp/tom '{"op":"accept"}'; A /tmp/sam '{"op":"accept"}'
  36. curl -s $B/api/hands/$H | python3 -c '
  37. import sys,json; s=json.load(sys.stdin); r=s["round"]; p=r["pull"]
  38. lab=lambda i: next(o["label"] for o in r["options"] if o["id"]==i)
  39. print("round",r["n"],"status",s["status"],"winner",lab(p["winner"]),{lab(k):round(v,2) for k,v in p["odds"].items()},"format",r["odds"]["format"]); print("dealer:",p["dealer"])'