Files
crosscode-platform/scripts/tests/cli.bats
T
joshuaandClaude Opus 5.5 e1c6a4cce1 crosscode: install and add Accounts; agent: Accounts installs and add-product
crosscode install takes --products accounts (one product per install);
crosscode add <church> <product> installs a product next to a church's
others, as its app user, undoing only its own folder, database, PM2 and
site if a step fails. install_events/install_accounts share the checks,
ports and nginx site. Agent 1.1.0: install jobs for Accounts, and
add-product jobs (behind frp, with the Hub's ports and release).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 14:31:36 +02:00

120 lines
3.6 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 website --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"can only add events and accounts"* ]]
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>"* ]]
}