Files
crosscode-platform/scripts/tests/website.bats
T
joshuaandClaude Opus 5.5 c8e270dbf1 website 1.8.0: demo scenarios (the scenario's people lead, Events' events through the feed)
- `npm run demo -- --profile <p> --scenario <p>`: each profile's `scenarioTeam` names four
  parts, roles and portraits; the names are the scenario's people from @crosscode/demo, the
  pastor first (home page and messages' speaker).
- With a linked Cross Events, a scenario load makes no events of its own, turns on Show events
  from and fetches Events' whole feed at once; an unreachable Events doesn't fail the load.
- A scenario on a site with no church profile saves the scenario's church, not Acacia Hill.
- crosscode script: `crosscode demo <church> website --scenario` passes it on and refuses a
  Website before 1.8.0; the Website installs and builds packages/demo.
- Docs: HANDOVER, APP-1.0-PLAN, VERSIONS, CHANGELOGs, What's New.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 15:23:12 +02:00

95 lines
4.2 KiB
Bash

#!/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 <product>." {
[ "$(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 "1.8.0: demo is installed and built too (after contracts), where the release has it" {
checkout new
mkdir -p "$TMP/new/packages/demo"
echo '{"name":"@crosscode/demo"}' > "$TMP/new/packages/demo/package.json"
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 packages/demo -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/packages/demo 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 ]
}