#!/usr/bin/env bash
# Fresh test database with two accounts, then the API on :8099 in the foreground.
# Used by the app's sync-engine tests:  bash server/tests/serve.sh &  then  UO_API=... npm test
set -euo pipefail
cd "$(dirname "$0")/.."
MYSQL=${MYSQL:-mysql -uroot}
DB=${UO_TEST_DB:-uni_organiser_test}
$MYSQL -e "DROP DATABASE IF EXISTS $DB; CREATE DATABASE $DB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
$MYSQL "$DB" < db/sql/001_initial.sql
UO_DB=$DB UO_PASSWORD='correct horse battery' php bin/create-user.php rob@example.com Rob >/dev/null
UO_DB=$DB UO_PASSWORD='another long password' php bin/create-user.php eve@example.com Eve >/dev/null
exec env UO_DB=$DB php -S 127.0.0.1:8099 -t public public/router.php
