freshyo/tests/e2e/full-suite/run.sh
2026-10-05 11:46:47 +05:30

135 lines
5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Full-suite runner for tests/e2e-suite.txt (steps 4-24; steps 1-3 via Playwright).
# Usage:
# cp tests/e2e/full-suite/.env.example tests/e2e/full-suite/.env # fill in
# npx playwright test --config tests/web/playwright.config.ts e2e-setup # steps 1-3, writes .env.e2e
# bash tests/e2e/full-suite/run.sh # everything
# bash tests/e2e/full-suite/run.sh user-journey.yaml # subset (reuses last readback)
set -euo pipefail
cd "$(dirname "$0")"
if [ ! -f .env ]; then
echo "Missing tests/e2e/full-suite/.env — copy .env.example to .env and fill it in." >&2
exit 1
fi
set -a; source ./.env; set +a
# Per-run hand-off from the Playwright setup spec (steps 1-3). Falls back to
# the static .env admin when it hasn't been generated (ids must then exist).
if [ -f .env.e2e ]; then
set -a; source ./.env.e2e; set +a
else
echo "NOTE: .env.e2e missing — run the Playwright e2e-setup spec first for a fresh admin." >&2
ADMIN_NAME="${STAFF_NAME:?}"; ADMIN_PASSWORD="${STAFF_PASSWORD:?}"
STAMP="manual"; REGION_ID="${REGION_ID:-1}"
fi
: "${SIM_UDID:?SIM_UDID is required}"
: "${BACKEND_URL:?BACKEND_URL is required}"
: "${USER_MOBILE:?USER_MOBILE is required}"
: "${USER_PASSWORD:?USER_PASSWORD is required}"
# Deterministic per-run names (backend rejects duplicate product names).
STORE1="E2E${STAMP} Store One"
STORE2="E2E${STAMP} Store Two"
P1="E2E${STAMP} Chicken"
P2="E2E${STAMP} Rice"
COMBO="E2E${STAMP} Combo"
TAG1="E2E${STAMP} Fresh"
TAG2="E2E${STAMP} Value"
export BACKEND_URL ADMIN_NAME ADMIN_PASSWORD
export STAMP STORE1 STORE2 P1 P2 COMBO TAG1 TAG2
MENV=(
-e "APP_ID=${APP_ID:-in.freshyo.adminui}" -e "USER_APP_ID=${USER_APP_ID:-com.freshyotrial.app}"
-e "STAFF_NAME=$ADMIN_NAME" -e "STAFF_PASSWORD=$ADMIN_PASSWORD"
-e "REGION_ID=$REGION_ID"
-e "STAMP=$STAMP"
-e "STORE1=$STORE1" -e "STORE2=$STORE2"
-e "P1=$P1" -e "P2=$P2" -e "COMBO=$COMBO"
-e "TAG1=$TAG1" -e "TAG2=$TAG2"
-e "USER_MOBILE=$USER_MOBILE" -e "USER_PASSWORD=$USER_PASSWORD"
)
ma_admin() {
# Fresh navigation state for every flow (auth/keychain survive terminate).
xcrun simctl terminate "$SIM_UDID" "${APP_ID:-in.freshyo.adminui}" >/dev/null 2>&1 || true
maestro test --udid "$SIM_UDID" "${MENV[@]}" "$@"
}
ma_user() {
xcrun simctl terminate "$SIM_UDID" "${USER_APP_ID:-com.freshyotrial.app}" >/dev/null 2>&1 || true
maestro test --udid "$SIM_UDID" "${MENV[@]}" "$@"
}
ma() { ma_admin "$@"; }
# Subset mode: reuse the last readback, run only the given flows.
if [ "$#" -gt 0 ]; then
[ -f gen/readback.env ] && { set -a; source gen/readback.env; set +a; }
EXTRA=()
for v in STAFF_ID STORE1_ID STORE2_ID TAG1_ID TAG2_ID SLOT1 SLOT2 SLOT3 SLOT4 SLOT5 SLOT6 SLOT7 SLOT8; do
[ -n "${!v:-}" ] && EXTRA+=(-e "$v=${!v}")
done
maestro test --udid "$SIM_UDID" "${MENV[@]}" "${EXTRA[@]}" "$@"
exit 0
fi
: > gen/readback.env
# Suite step 12: pin the sim inside region 1 (Mbnr-1) before the user leg.
# Applied now so it is settled well before the user app launches.
xcrun simctl location "$SIM_UDID" set "${GEO_LAT},${GEO_LNG}"
echo "==> staff id"
python3 scripts/readback.py --staff | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
echo "==> step 5: stores"
python3 scripts/gen_flows.py stores
ma -e "STAFF_ID=$STAFF_ID" gen/admin-stores.yaml
python3 scripts/readback.py --stores | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
MENV+=(-e "STORE1_ID=$STORE1_ID" -e "STORE2_ID=$STORE2_ID" -e "STAFF_ID=$STAFF_ID")
echo "==> steps 6-7: products"
python3 scripts/gen_flows.py products
ma gen/admin-product-p1.yaml
ma gen/admin-product-p2.yaml
python3 scripts/readback.py --skus | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
echo "==> step 8: combo"
python3 scripts/gen_flows.py combo-tags
ma gen/admin-combo.yaml
python3 scripts/readback.py --skus | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
export P1SK0 P1SK1 P2SK0 P2SK1 P2SK2 P2SK3 CBSK
export SLOT1_SKUS="$P1SK0,$P1SK1,$CBSK" SLOT2_SKUS="$P2SK0,$P2SK1,$P2SK2,$P2SK3"
for n in 3 4 5 6 7 8; do export "SLOT${n}_SKUS=$P1SK0,$P2SK0"; done
echo "==> step 11: tags"
ma gen/admin-tags.yaml
python3 scripts/readback.py --tags | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
MENV+=(-e "TAG1_ID=$TAG1_ID" -e "TAG2_ID=$TAG2_ID")
echo "==> step 10: slots (generate fresh, then create)"
STAMP="$STAMP" P1="$P1" P2="$P2" COMBO="$COMBO" python3 scripts/gen_slots.py
ma gen/admin-slots.yaml
# Wheel minute drags undershoot (~3-4 rows); exact the freeze offset via API.
python3 scripts/normalize_slots.py | tee -a gen/readback.env
python3 scripts/readback.py --slots | tee -a gen/readback.env
set -a; source gen/readback.env; set +a
for n in 1 2 3 4 5 6 7 8; do
eval "d=\$SLOT${n}_DATE h=\$SLOT${n}_HOUR m=\$SLOT${n}_MIN"
MENV+=(-e "SLOT$n=slot-$d-$h-$m")
echo "SLOT$n=slot-$d-$h-$m" | tee -a gen/readback.env
done
echo "==> steps 13-23: user journey"
ma_user user-journey.yaml
echo "==> step 24: verify order in admin app"
ma_admin admin-verify-order.yaml
echo "FULL SUITE DONE"