#!/usr/bin/env bash # Bulk-delete regression test: create two scratch teams, then delete BOTH in a # single API call and poll the job until it settles. # # Proves the endpoint exists, validates input, runs teams sequentially inside # one background job, and leaves the real teams untouched. set -uo pipefail BASE=/opt/gemastik18-final cd "$BASE" CJ=/tmp/bulk_cj U=$(grep -oP '^PANEL_ADMIN_USER=\K.*' panel/.env) P=$(grep -oP '^PANEL_ADMIN_PASS=\K.*' panel/.env) curl -sS -c "$CJ" -X POST -H 'Content-Type: application/json' \ -d "{\"user\":\"$U\",\"pass\":\"$P\"}" http://127.0.0.1:18081/api/login -o /dev/null echo "=== validation ===" printf " empty list -> " curl -sS -b "$CJ" -X POST -H 'Content-Type: application/json' -d '{"indices":[]}' \ http://127.0.0.1:18081/api/teams/bulk-delete -w ' [%{http_code}]\n' printf " missing tms -> " curl -sS -b "$CJ" -X POST -H 'Content-Type: application/json' -d '{"indices":[99,98]}' \ http://127.0.0.1:18081/api/teams/bulk-delete -w ' [%{http_code}]\n' echo "=== BEFORE ===" for i in 5 6; do printf " team%s dir=%s\n" "$i" "$([ -d "teams/team$i" ] && echo present || echo GONE)" done echo "=== BULK DELETE [5,6] ===" S=$(date +%s) curl -sS -b "$CJ" -X POST -H 'Content-Type: application/json' \ -d '{"indices":[5,6],"purge_scores":true}' \ http://127.0.0.1:18081/api/teams/bulk-delete -o /tmp/bulk.json -w ' HTTP %{http_code}\n' cat /tmp/bulk.json; echo JOB=$(python3 -c "import json;print(json.load(open('/tmp/bulk.json'))['job'])") echo " job: $JOB" while :; do curl -sS -b "$CJ" "http://127.0.0.1:18081/api/teams/bulk-delete/$JOB" -o /tmp/bulkjob.json read -r ST DET <<<"$(python3 -c " import json;d=json.load(open('/tmp/bulkjob.json'));print(d['state'],d.get('detail',''))")" echo " [$(( $(date +%s) - S ))s] $ST — $DET" [ "$ST" != "running" ] && break sleep 15 done echo " elapsed: $(( $(date +%s) - S ))s" python3 -c " import json;d=json.load(open('/tmp/bulkjob.json')) print(' state:',d['state'],' errors:',d.get('errors')) for x in d.get('done',[]): print(' deleted team',x['team'],x['label'],'->',x['steps'])" echo "=== AFTER ===" for i in 5 6; do printf " team%s dir=%s\n" "$i" "$([ -d "teams/team$i" ] && echo present || echo GONE)" done echo " real teams: $(curl -sS -b "$CJ" http://127.0.0.1:18081/api/teams \ | python3 -c "import json,sys;print([t['index'] for t in json.load(sys.stdin)['teams']])")"