#!/bin/bash
## Description: Run the full test suite — PHPUnit + vitest + vue-tsc
## Usage: tests [phpunit-args]
## Example: ddev tests
## Example: ddev tests --filter test_id_tz_01

set -euo pipefail

echo "── PHP unit + integration ─────────────────────────────"
# DDEV's web_environment sets APP_ENV=dev for dev work — phpunit's xml <server>
# directive doesn't always override that cleanly, so force the env explicitly.
APP_ENV=test bin/phpunit "$@"

echo
echo "── Frontend typecheck + tests ─────────────────────────"
cd frontend
npx vue-tsc --noEmit -p tsconfig.app.json
npx vitest run

echo
echo "── Frontend production build ──────────────────────────"
# Rebuild public/build/ so what gets committed matches what passed tests.
# Without this step, deploys can ship source-correct features whose
# compiled bundle is stale (verified failure mode 2026-05-09).
npm run build
