Files
crosscode-platform/scripts/tests/cli.bats
T
joshuaandClaude Opus 5.5 58960b5e93 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>
2026-11-25 09:27:07 +02:00

124 lines
3.7 KiB
Bash

#!/usr/bin/env bats
# The crosscode entry script: help, and the argument checks that run before anything needs root.
setup() {
export CROSSCODE_NO_UPDATE=1
CC="$BATS_TEST_DIRNAME/../crosscode"
}
@test "help lists the commands" {
run bash "$CC" help
[ "$status" -eq 0 ]
[[ "$output" == *"crosscode deploy <church>"* ]]
[[ "$output" == *"crosscode adopt <church> --undo"* ]]
}
@test "help <command> shows that command's options" {
run bash "$CC" help deploy
[ "$status" -eq 0 ]
[[ "$output" == *"--every-church"* ]]
run bash "$CC" adopt --help
[ "$status" -eq 0 ]
[[ "$output" == *"--events-dir"* ]]
}
@test "an unknown command fails" {
run bash "$CC" frobnicate
[ "$status" -eq 1 ]
[[ "$output" == *'Unknown command "frobnicate"'* ]]
}
@test "the copy it runs from is removed afterwards" {
before="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)"
run bash "$CC" help
after="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)"
[ "$before" -eq "$after" ]
}
@test "deploy refuses bad arguments before touching anything" {
run bash "$CC" deploy hopefamily events --version events@2.2
[ "$status" -eq 1 ]
[[ "$output" == *"expected <product>@<x.y.z>"* ]]
run bash "$CC" deploy hopefamily --version events@2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"name events as well"* ]]
run bash "$CC" deploy hopefamily events --main --version events@2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"not both"* ]]
run bash "$CC" deploy hopefamily calendar
[ "$status" -eq 1 ]
[[ "$output" == *'Unknown product "calendar"'* ]]
run bash "$CC" deploy hopefamily --frobnicate
[ "$status" -eq 1 ]
run bash "$CC" deploy events --every-church
[ "$status" -eq 1 ]
[[ "$output" != *"doesn't take a church name"* ]]
run bash "$CC" deploy hopefamily --every-church
[ "$status" -eq 1 ]
[[ "$output" == *"doesn't take a church name"* ]]
}
@test "install and adopt check their arguments" {
run bash "$CC" install Hope --products events --domain hope.co.za --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"isn't a church name"* ]]
run bash "$CC" install hope --products website --domain hope.co.za --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"can only install events"* ]]
run bash "$CC" install hope --products events --domain hope.co.za
[ "$status" -eq 1 ]
[[ "$output" == *"--email is required"* ]]
run bash "$CC" adopt hope
[ "$status" -eq 1 ]
[[ "$output" == *"--events-dir is required"* ]]
run bash "$CC" adopt hope --events-dir /var/www/hope-events --version 2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"expected events@x.y.z"* ]]
}
@test "install takes accounts too, one product at a time" {
run bash "$CC" install hope --products events,accounts --domain hope.co.za --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"One product per install"* ]]
run bash "$CC" install hope --products accounts --domain hope.co.za --version events@2.4.0 --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"expected accounts@x.y.z"* ]]
run bash "$CC" install hope --products accounts --domain hope.co.za --frp
[ "$status" -eq 1 ]
[[ "$output" == *"--frp needs --api-port and --web-port"* ]]
}
@test "add checks its arguments before anything needs root" {
run bash "$CC" add hope
[ "$status" -eq 1 ]
[[ "$output" == *"Name the church and the product"* ]]
run bash "$CC" add hope app --no-ssl
[ "$status" -eq 1 ]
[[ "$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 ]
[[ "$output" == *"--email is required"* ]]
run bash "$CC" help add
[ "$status" -eq 0 ]
[[ "$output" == *"crosscode add <church> <product>"* ]]
}