Branchwell

Jobley / app · jobley.ai / scripts / test-api.sh

1#!/usr/bin/env bash
2# Runs the JobleyKit tests against the real API code: starts jobley-site's dev server on a fresh
3# in-memory database with the five sample jobs, points the tests at it, then stops it.
4# SITE=~/Documents/GIT_SOURCE/jobley-site scripts/test-api.sh
5set -euo pipefail
6SITE=${SITE:-"$HOME/Documents/GIT_SOURCE/jobley-site"}
7PORT=${PORT:-8790}
8TOKEN=dev-admin-token-not-for-production-0000
9(cd "$SITE" && PORT=$PORT DB_FILE=:memory: exec node --experimental-sqlite tools/dev-server.mjs --seed) > /tmp/jobley-test-server.log 2>&1 &
10SERVER=$!
11trap 'kill $SERVER 2>/dev/null' EXIT
12for _ in $(seq 1 50); do curl -sf "http://localhost:$PORT/api/meta" >/dev/null && break; sleep 0.2; done
13JOBLEY_TEST_BASE="http://localhost:$PORT" JOBLEY_TEST_TOKEN=$TOKEN swift test "$@"