Files
AOS/aos-verify7.sh
T

104 lines
4.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Verify Contracts + Expenses modules (adapted from PerfEx CRM)
set -u
cd /home/z/my-project
BASE=http://127.0.0.1:3000
SHOTS=/home/z/my-project/aos-shots
mkdir -p "$SHOTS"
echo "=== Start server ==="
pkill -f "next dev" 2>/dev/null; pkill -f "tee dev.log" 2>/dev/null; sleep 2
bun run dev > dev.log 2>&1 &
SRV=$!
for i in $(seq 1 90); do curl -s -o /dev/null "$BASE/" 2>/dev/null && break; sleep 1; done
echo " ready after ${i}s"; sleep 2
echo "=== API tests ==="
echo -n " /api/aos/contracts -> "; curl -s -o /dev/null -w "HTTP %{http_code}\n" "$BASE/api/aos/contracts"
echo -n " /api/aos/expenses -> "; curl -s -o /dev/null -w "HTTP %{http_code}\n" "$BASE/api/aos/expenses"
echo " contracts count:"; curl -s "$BASE/api/aos/contracts" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f' {len(d[\"contracts\"])} contracts, stats: {d[\"stats\"]}')" 2>/dev/null
echo " expenses count:"; curl -s "$BASE/api/aos/expenses" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f' {len(d[\"expenses\"])} expenses, billable: {d[\"stats\"][\"billable\"]}, report cats: {len(d[\"report\"][\"byCategory\"])}')" 2>/dev/null
echo ""
echo "=== Browser: Contracts view ==="
agent-browser open "$BASE/" >/dev/null 2>&1
agent-browser wait --load networkidle >/dev/null 2>&1 || true
agent-browser wait 3000 >/dev/null 2>&1
agent-browser set viewport 1440 900 >/dev/null 2>&1
agent-browser find text "Verträge" click >/dev/null 2>&1
agent-browser wait 3000 >/dev/null 2>&1
H1=$(agent-browser get text h1 2>/dev/null | head -1)
echo " Contracts H1: $H1"
agent-browser screenshot --full "$SHOTS/v9-contracts.png" >/dev/null 2>&1 && echo " shot OK"
echo "=== Click first contract to open dialog ==="
agent-browser eval "document.querySelector('tbody tr')?.click()" >/dev/null 2>&1
agent-browser wait 2000 >/dev/null 2>&1
DIALOG=$(agent-browser eval "document.querySelector('[role=dialog]')?.textContent?.slice(0,150) || 'closed'" 2>/dev/null | tail -1 | tr -d '"')
echo " dialog: $(echo "$DIALOG" | head -c 120)"
agent-browser screenshot --full "$SHOTS/v9-contract-detail.png" >/dev/null 2>&1 && echo " detail shot OK"
# check if sign button present
SIGNBTN=$(agent-browser find text "E-Signatur anfordern" 2>&1 | head -1)
echo " sign button: $SIGNBTN"
agent-browser press Escape >/dev/null 2>&1; agent-browser wait 500 >/dev/null 2>&1
echo ""
echo "=== Browser: Expenses view ==="
agent-browser find text "Ausgaben" click >/dev/null 2>&1
agent-browser wait 3000 >/dev/null 2>&1
H1=$(agent-browser get text h1 2>/dev/null | head -1)
echo " Expenses H1: $H1"
agent-browser screenshot --full "$SHOTS/v9-expenses.png" >/dev/null 2>&1 && echo " shot OK"
echo "=== Switch to report tab ==="
agent-browser find role tab click --name "Ausgabenreport" >/dev/null 2>&1 || agent-browser find text "Ausgabenreport" click >/dev/null 2>&1
agent-browser wait 2000 >/dev/null 2>&1
agent-browser screenshot --full "$SHOTS/v9-expenses-report.png" >/dev/null 2>&1 && echo " report shot OK"
echo ""
echo "=== Test convert-to-invoice (API) ==="
# find a billable, not-invoiced expense
EXP_ID=$(curl -s "$BASE/api/aos/expenses" | python3 -c "
import sys,json
d=json.load(sys.stdin)
for e in d['expenses']:
if e['billable'] and e['status']!='invoiced' and e['companyName']:
print(e['id']); break
" 2>/dev/null)
echo " expense id to convert: $EXP_ID"
if [ -n "$EXP_ID" ]; then
RES=$(curl -s -X POST "$BASE/api/aos/expenses/$EXP_ID/convert")
echo " convert result: $(echo "$RES" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f'invoice {d[\"invoice\"][\"number\"]} = {d[\"invoice\"][\"grossCents\"]/100:.2f}€')" 2>/dev/null)"
fi
echo ""
echo "=== Test contract sign (API) ==="
CON_ID=$(curl -s "$BASE/api/aos/contracts" | python3 -c "
import sys,json
d=json.load(sys.stdin)
for c in d['contracts']:
if c['status'] in ('draft','sent'):
print(c['id']); break
" 2>/dev/null)
echo " contract id to sign: $CON_ID"
if [ -n "$CON_ID" ]; then
RES=$(curl -s -X PATCH "$BASE/api/aos/contracts/$CON_ID/sign" -H 'content-type: application/json' -d '{"signedBy":"Test-Kunde"}')
echo " sign result: $(echo "$RES" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f'status={d[\"contract\"][\"status\"]}, token={d[\"contract\"][\"signToken\"]}')" 2>/dev/null)"
fi
echo ""
echo "=== Errors ==="
agent-browser errors 2>&1 | head -8
echo "--- console last 5 ---"
agent-browser console 2>&1 | tail -5
echo ""
echo "=== Cleanup ==="
agent-browser close >/dev/null 2>&1
kill $SRV 2>/dev/null
echo "=== dev.log (errors) ==="
grep -iE "error|⨯|500" dev.log | grep -v SIGTERM | tail -8
echo ""
echo "=== DONE ==="
ls -la "$SHOTS"/v9-* 2>/dev/null | tail -6