#!/usr/bin/env bats # The Church Website's hooks that don't need a server (WEBSITE-1.0-PLAN ยง11), 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/website.sh source "$BATS_TEST_DIRNAME/../products/website.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; do mkdir -p "$dir/packages/$p" echo "{\"name\":\"@crosscode/$p\"}" > "$dir/packages/$p/package.json" done mkdir -p "$dir/apps/website/backend" "$dir/apps/website/frontend" echo '{"version":"1.0.0"}' > "$dir/apps/website/backend/package.json" cp "$BATS_TEST_DIRNAME/../../apps/website/ecosystem.config.example.cjs" "$dir/apps/website/" } @test "the Website goes on www., or on the Cross Code address itself; other products on ." { [ "$(default_domain website hopefamily.co.za)" = www.hopefamily.co.za ] [ "$(default_domain website hope.crosscode.co.za)" = hope.crosscode.co.za ] [ "$(default_domain events hopefamily.co.za)" = events.hopefamily.co.za ] [ "$(default_domain accounts hope.crosscode.co.za)" = accounts.hope.crosscode.co.za ] } @test "the Website is a product this script deploys" { is_supported_product website } @test "contracts, ui, auth-client and seo are installed; contracts, auth-client and seo built before the Website" { checkout new website_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 apps/website/backend -w apps/website/frontend' "$CALLS" : > "$CALLS" website_build "$TMP/new" hope [ "$(cut -d'|' -f2 "$CALLS" | tr '\n' ' ')" = "new/packages/contracts new/packages/auth-client new/packages/seo new/apps/website/backend new/apps/website/frontend " ] } @test "ports default to 5300 / 3300, else church.env's" { [ "$(website_api_port)" = 5300 ] [ "$(website_web_port)" = 3300 ] church_env_set WEBSITE_PORTS "5410 3410" [ "$(website_health_url)" = http://127.0.0.1:5410/api/health ] [ "$(website_web_port)" = 3410 ] } @test "the PM2 config is made once, with the church's names and port" { checkout new church_env_set WEBSITE_PM2 "hope-website-backend hope-website-frontend" church_env_set WEBSITE_PORTS "5410 3410" info() { :; } website_ensure_pm2_config "$TMP/new" "$(id -un)" conf="$TMP/new/apps/website/ecosystem.config.cjs" grep -q "'hope-website-backend'" "$conf" grep -q "'hope-website-frontend'" "$conf" grep -q -- "-p 3410" "$conf" echo changed > "$conf" website_ensure_pm2_config "$TMP/new" "$(id -un)" [ "$(cat "$conf")" = changed ] } @test "the uploads are copied into the export; none is fine" { command -v rsync >/dev/null || skip "rsync isn't installed here" checkout new website_copy_uploads "$TMP/new" "$TMP/out1" [ -d "$TMP/out1" ] mkdir -p "$TMP/new/apps/website/backend/uploads/2026" echo jpg > "$TMP/new/apps/website/backend/uploads/2026/hero.jpg" website_copy_uploads "$TMP/new" "$TMP/out2" [ "$(cat "$TMP/out2/2026/hero.jpg")" = jpg ] }