feat(website): crosscode website.sh and signing in through Accounts
crosscode: scripts/products/website.sh (ports 5300/3300, uploads in the export), crosscode add <church> website (needs Accounts; www.<address> or the Cross Code address), one install_app for Accounts and the Website, env template copy, bats tests. Backend: Hub client (protocol v2, product website), crosscode.link/1 with automatic connect to the church's Accounts, sign-in through @crosscode/auth-client with the Website's own session and roles, the first Owner from HUB_ADMIN_EMAIL (verified), 2FA for Owners and Admins, back-channel logout, Accounts' user.* calls, and the church export. Frontend: admin sign-in/out and the sign-in problem page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,9 +105,13 @@ setup() {
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"Name the church and the product"* ]]
|
||||
|
||||
run bash "$CC" add hope website --no-ssl
|
||||
run bash "$CC" add hope app --no-ssl
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"can only add events and accounts"* ]]
|
||||
[[ "$output" == *"can only add events, accounts and website"* ]]
|
||||
|
||||
run bash "$CC" add hope website
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"--email is required"* ]]
|
||||
|
||||
run bash "$CC" add hope accounts
|
||||
[ "$status" -eq 1 ]
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/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; 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 and auth-client are installed; contracts and auth-client 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 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/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 ]
|
||||
}
|
||||
Reference in New Issue
Block a user