#!/usr/bin/env bats # The Church App's hooks that don't need a server (APP-1.0-PLAN ยง12), and where `crosscode add` # puts it on the church's address. Run with `npm run test:scripts`. setup() { # shellcheck source=../lib/common.sh source "$BATS_TEST_DIRNAME/../lib/common.sh" # shellcheck source=../lib/install.sh source "$BATS_TEST_DIRNAME/../lib/install.sh" # shellcheck source=../products/app.sh source "$BATS_TEST_DIRNAME/../products/app.sh" TMP="$BATS_TEST_TMPDIR" CALLS="$TMP/calls" : > "$CALLS" # Record what would run, as the app user, instead of running it. run_as() { local user="$1" dir="$2"; shift 2; echo "$user|${dir#"$TMP"/}|$*" >> "$CALLS"; } CENV=() } checkout() { local dir="$TMP/$1" p for p in contracts ui auth-client seo demo; do mkdir -p "$dir/packages/$p" echo "{\"name\":\"@crosscode/$p\"}" > "$dir/packages/$p/package.json" done mkdir -p "$dir/apps/app/backend" "$dir/apps/app/frontend" echo '{"version":"1.0.0"}' > "$dir/apps/app/backend/package.json" cp "$BATS_TEST_DIRNAME/../../apps/app/ecosystem.config.example.cjs" "$dir/apps/app/" } @test "the App goes on app.
" { [ "$(default_domain app hopefamily.co.za)" = app.hopefamily.co.za ] [ "$(default_domain app hope.crosscode.co.za)" = app.hope.crosscode.co.za ] } @test "the App is a product this script deploys, last" { is_supported_product app [ "${PRODUCT_ORDER[*]}" = "accounts events website app" ] } @test "contracts, ui, auth-client, seo and demo are installed; all but ui built before the App" { checkout new app_install_deps "$TMP/new" hope grep -qx 'hope|new|npm ci --include=dev --no-audit --no-fund --include-workspace-root -w packages/contracts -w packages/ui -w packages/auth-client -w packages/seo -w packages/demo -w apps/app/backend -w apps/app/frontend' "$CALLS" : > "$CALLS" app_build "$TMP/new" hope [ "$(cut -d'|' -f2 "$CALLS" | tr '\n' ' ')" = "new/packages/contracts new/packages/auth-client new/packages/seo new/packages/demo new/apps/app/backend new/apps/app/frontend " ] } @test "ports default to 5400 / 3400, else church.env's" { [ "$(app_api_port)" = 5400 ] [ "$(app_web_port)" = 3400 ] church_env_set APP_PORTS "5510 3510" [ "$(app_health_url)" = http://127.0.0.1:5510/api/health ] [ "$(app_web_port)" = 3510 ] } @test "the PM2 config is made once, with the church's names and port" { checkout new church_env_set APP_PM2 "hope-app-backend hope-app-frontend" church_env_set APP_PORTS "5510 3510" info() { :; } app_ensure_pm2_config "$TMP/new" "$(id -un)" conf="$TMP/new/apps/app/ecosystem.config.cjs" grep -q "'hope-app-backend'" "$conf" grep -q "'hope-app-frontend'" "$conf" grep -q -- "-p 3510" "$conf" echo changed > "$conf" app_ensure_pm2_config "$TMP/new" "$(id -un)" [ "$(cat "$conf")" = changed ] } @test "the export is the App's own script, into the folder given" { checkout new app_export "$TMP/new" hope "$TMP/out" grep -qx "hope|new/apps/app/backend|npx tsx scripts/export-church.ts --out-dir $TMP/out" "$CALLS" } @test "the uploads are copied into the export; none is fine" { command -v rsync >/dev/null || skip "rsync isn't installed here" checkout new app_copy_uploads "$TMP/new" "$TMP/out1" [ -d "$TMP/out1" ] mkdir -p "$TMP/new/apps/app/backend/uploads/2026/12" echo jpg > "$TMP/new/apps/app/backend/uploads/2026/12/campaign.jpg" app_copy_uploads "$TMP/new" "$TMP/out2" [ "$(cat "$TMP/out2/2026/12/campaign.jpg")" = jpg ] } @test "the env template in the script is the App's own (the Hub reads apps/app's at the tag)" { diff <(node -e 'console.log(JSON.stringify(require(process.argv[1])))' "$BATS_TEST_DIRNAME/../products/app.env.template.json") \ <(node -e 'console.log(JSON.stringify(require(process.argv[1])))' "$BATS_TEST_DIRNAME/../../apps/app/env.template.json") }