Files
openhuman/scripts/e2e-payment.sh
T
29f542a3d7 feat: add E2E tests for card payment processing flow (#124)
* feat: add E2E tests for auth access control and billing/subscription flows

Add comprehensive E2E test coverage for authentication, access control,
and billing/subscription lifecycle using Appium mac2 + WebDriverIO.

New test cases (11 total):
- 1.1 User registration via deep link
- 1.1.1 Duplicate account handling
- 1.2 Multi-device sessions
- 3.1.1 Default FREE plan allocation
- 3.2.1 Upgrade flow (Stripe purchase API + polling)
- 3.2.2 Downgrade flow verification
- 3.3.1 Active subscription display
- 3.3.2 Renewal date handling
- 3.3.3 Cancellation via Stripe portal
- 1.3 Logout via Settings
- 1.3.1 Revoked session auto-logout

Mock server additions:
- Dynamic team data with subscription controlled by mockBehavior
- /payments/stripe/currentPlan, purchasePlan, portal routes
- /payments/coinbase/charge route

Split e2e.sh into per-flow scripts (e2e-login.sh, e2e-auth.sh) to
prevent Redux Persist state leaking between specs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix Prettier formatting for E2E test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address review findings for E2E auth spec

- clickFirstCandidate: check retry result, return null with tree dump on failure
- navigateToHome: throw on failure instead of silently continuing
- 3.2.2: assert exactly 1 Upgrade element (PRO only) and verify PRO visible

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add E2E tests for card payment processing flow

Add 8 new E2E tests covering checkout sessions, payment confirmation
via polling, duplicate prevention, and billing events for Stripe card
and Coinbase crypto payment flows.

New files:
- test/e2e/specs/card-payment-flow.spec.ts (8 test cases)
- scripts/e2e-payment.sh (standalone runner)

Modified:
- mock-server.ts: add purchaseError/coinbaseError behavior toggles
- package.json: add test:e2e:payment script and chain into test:e2e

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add assertions to waitForTextToDisappear calls and guard purchaseError cleanup

Ensure all waitForTextToDisappear results are asserted with expect().toBe(true)
instead of silently discarding the return value. Wrap 5.2.2 test body in
try/finally so the purchaseError mock flag is always reset even if assertions throw.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix Prettier formatting in card payment spec

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix pre-existing Prettier formatting issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add E2E tests for cryptocurrency payment processing flow

Covers invoice creation (Coinbase charge), confirmation handling
(success, underpayment, overpayment), and payment status updates
(polling, API errors, expired charges). Extends mock server with
crypto payment status endpoint and adds test runner script.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add E2E tests for Telegram integration flows

Covers sections 7.1-7.5: account linking, permission levels, command
processing, webhook handling, and disconnect/re-setup flows (13 tests).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add E2E tests for Notion integration flows

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add E2E tests for Gmail integration flows

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 10:57:12 +04:00

91 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Run E2E card payment flow tests only.
#
# Starts Appium, cleans app caches, runs the card-payment-flow spec,
# then tears everything down. Each flow script is self-contained so
# specs don't pollute each other's Redux Persist state.
#
# Usage:
# ./scripts/e2e-payment.sh
# APPIUM_PORT=4723 ./scripts/e2e-payment.sh
#
set -euo pipefail
APPIUM_PORT="${APPIUM_PORT:-4723}"
E2E_MOCK_PORT="${E2E_MOCK_PORT:-18473}"
SPEC="test/e2e/specs/card-payment-flow.spec.ts"
export VITE_BACKEND_URL="http://127.0.0.1:${E2E_MOCK_PORT}"
export BACKEND_URL="http://127.0.0.1:${E2E_MOCK_PORT}"
# Clean cached app data for a fresh state — Redux Persist would otherwise
# remember the JWT from a previous run and skip the login flow.
echo "Cleaning cached app data..."
rm -rf ~/Library/WebKit/com.alphahuman.app
rm -rf ~/Library/Caches/com.alphahuman.app
rm -rf "$HOME/Library/Application Support/com.alphahuman.app"
# Verify the frontend dist has the mock server URL baked in.
DIST_JS="$(ls dist/assets/index-*.js 2>/dev/null | head -1)"
if [ -z "$DIST_JS" ]; then
echo "ERROR: No frontend bundle found at dist/assets/index-*.js." >&2
echo " Run 'yarn test:e2e:build' to build the app before running E2E tests." >&2
exit 1
fi
if ! grep -q "127.0.0.1:${E2E_MOCK_PORT}" "$DIST_JS"; then
echo "ERROR: frontend bundle does NOT contain mock server URL (127.0.0.1:${E2E_MOCK_PORT})." >&2
echo " Run 'yarn test:e2e:build' to rebuild with the mock URL." >&2
exit 1
fi
echo "Verified: frontend bundle contains mock server URL."
# --- Resolve Node 24 via nvm ---------------------------------------------------
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
NODE24="$(nvm which 24 2>/dev/null || true)"
if [ -z "$NODE24" ] || [ ! -x "$NODE24" ]; then
echo "ERROR: Node 24 is required for appium v3. Install it with: nvm install 24" >&2
exit 1
fi
APPIUM_BIN="$(dirname "$NODE24")/appium"
if [ ! -x "$APPIUM_BIN" ]; then
echo "ERROR: appium not found at $APPIUM_BIN. Install it with: nvm use 24 && npm i -g appium" >&2
exit 1
fi
# --- Start Appium in the background -------------------------------------------
APPIUM_LOG="/tmp/appium-e2e-payment.log"
NODE_VER=$("$NODE24" --version)
echo "Starting Appium on port $APPIUM_PORT (Node $NODE_VER)..."
echo " Appium logs: $APPIUM_LOG"
"$NODE24" "$APPIUM_BIN" --port "$APPIUM_PORT" --relaxed-security > "$APPIUM_LOG" 2>&1 &
APPIUM_PID=$!
cleanup() {
echo "Stopping Appium (pid $APPIUM_PID)..."
kill "$APPIUM_PID" 2>/dev/null || true
wait "$APPIUM_PID" 2>/dev/null || true
}
trap cleanup EXIT
# Wait for Appium to be ready
for i in $(seq 1 30); do
if curl -sf "http://127.0.0.1:$APPIUM_PORT/status" >/dev/null 2>&1; then
echo "Appium is ready."
break
fi
if [ "$i" -eq 30 ]; then
echo "ERROR: Appium did not start within 30 seconds." >&2
exit 1
fi
sleep 1
done
# --- Run WebDriverIO ----------------------------------------------------------
echo "Running E2E card payment flow tests ($SPEC)..."
npx wdio run wdio.conf.ts --spec "$SPEC"