| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/usr/bin/env bash
- set -euo pipefail
- B=${BASE_URL:-http://localhost:8787}
- COOKIE_DIR=$(mktemp -d)
- trap 'rm -rf "$COOKIE_DIR"' EXIT
- TOM="$COOKIE_DIR/tom"
- SAM="$COOKIE_DIR/sam"
- PHONE="$COOKIE_DIR/phone"
- j(){ curl --silent --show-error --fail-with-body -b "$1" -c "$1" -H 'Content-Type: application/json' "${@:2}"; }
- # two members: anonymous sign-in, set names
- j "$TOM" -X POST "$B/api/auth/sign-in/anonymous" -d '{}' >/dev/null; j "$TOM" -X POST "$B/api/me/name" -d '{"name":"Tom"}' >/dev/null
- j "$SAM" -X POST "$B/api/auth/sign-in/anonymous" -d '{}' >/dev/null; j "$SAM" -X POST "$B/api/me/name" -d '{"name":"Sam"}' >/dev/null
- # phone OTP path smoke test
- j "$PHONE" -X POST "$B/api/auth/phone-number/send-otp" -d '{"phoneNumber":"+61400000000"}'; echo " <- send-otp"
- H=$(j "$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"])')
- echo "hand $H"
- A(){ j "$1" -X POST "$B/api/hands/$H/act" -d "$2" >/dev/null; }
- A "$TOM" '{"op":"join"}'; A "$SAM" '{"op":"join"}'
- A "$TOM" '{"op":"place","option":"o1","n":6}'; A "$TOM" '{"op":"place","option":"o3","n":4}'
- A "$SAM" '{"op":"place","option":"o2","n":8}'; A "$SAM" '{"op":"place","option":"o4","n":2}'
- A "$TOM" '{"op":"veto","option":"o2"}' # Tom vetoes pizza; Sam's 8 chips come back
- sleep 1.2
- curl --silent --show-error --fail-with-body "$B/api/hands/$H" | python3 -c '
- import sys,json; s=json.load(sys.stdin); r=s["round"]
- print("members",[m["name"] for m in s["members"]],"live",s["live"],"vetoed",r["vetoed"])
- print("chips",r["chips"])
- 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")'
- A "$SAM" '{"op":"place","option":"o4","n":8}' # Sam goes all in on cooking
- sleep 0.6
- A "$TOM" '{"op":"lock"}'; A "$SAM" '{"op":"lock"}' # both locked -> lever pulls
- sleep 1.5
- curl --silent --show-error --fail-with-body "$B/api/hands/$H" | python3 -c '
- import sys,json; s=json.load(sys.stdin); r=s["round"]; p=r["pull"]
- lab=lambda i: next(o["label"] for o in r["options"] if o["id"]==i)
- print("status",s["status"]); print("odds at pull",{lab(k):round(v,2) for k,v in p["odds"].items()})
- print("WINNER",lab(p["winner"]),"| runner-up",lab(p["runnerUp"]),"| reel order",[lab(x) for x in p["order"]],"| seed",p["seed"])
- print("dealer:",p["dealer"])'
- A "$TOM" '{"op":"again"}'; sleep 0.3
- A "$TOM" '{"op":"place","option":"o1","n":10}'; A "$SAM" '{"op":"place","option":"o1","n":10}'; sleep 1
- A "$TOM" '{"op":"lock"}'; A "$SAM" '{"op":"lock"}'; sleep 1.5
- A "$TOM" '{"op":"accept"}'; A "$SAM" '{"op":"accept"}'
- curl --silent --show-error --fail-with-body "$B/api/hands/$H" | python3 -c '
- import sys,json; s=json.load(sys.stdin); r=s["round"]; p=r["pull"]
- lab=lambda i: next(o["label"] for o in r["options"] if o["id"]==i)
- 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"])'
|