#!/usr/bin/env bats # --json reports (lib/report.sh) and the argument checks of the new commands (what needs a server # is tested on a VM). bats_require_minimum_version 1.5.0 setup() { export CROSSCODE_NO_UPDATE=1 CC="$BATS_TEST_DIRNAME/../crosscode" } json() { node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const v=process.argv[1].split(".").reduce((o,k)=>o==null?o:o[k],JSON.parse(s));process.stdout.write(typeof v==="object"?JSON.stringify(v):String(v))})' "$1"; } @test "--json: one report on stdout, the log on stderr" { run --separate-stderr bash "$CC" help --json [ "$status" -eq 0 ] [ "$(printf '%s' "$output" | json schema)" = "crosscode.script-report/1" ] [ "$(printf '%s' "$output" | json status)" = "succeeded" ] [ "$(printf '%s' "$output" | json command)" = "help" ] [[ "$stderr" == *"crosscode deploy "* ]] } @test "--json on a failure: status failed and the reason" { run --separate-stderr bash "$CC" uninstall hope --json [ "$status" -eq 1 ] [ "$(printf '%s' "$output" | json status)" = "failed" ] [[ "$(printf '%s' "$output" | json message)" == *"--confirm hope"* ]] } @test "--config must be an existing JSON file" { run bash "$CC" status --config /nonexistent.json [ "$status" -eq 1 ] [[ "$output" == *"no file /nonexistent.json"* ]] echo 'not json' > "$BATS_TEST_TMPDIR/c.json" run bash "$CC" status --config "$BATS_TEST_TMPDIR/c.json" [ "$status" -eq 1 ] [[ "$output" == *"isn't JSON"* ]] } @test "uninstall and purge need --confirm with the church's own name" { run bash "$CC" uninstall hope [ "$status" -eq 1 ] [[ "$output" == *"add --confirm hope"* ]] run bash "$CC" uninstall hope --confirm other [ "$status" -eq 1 ] run bash "$CC" purge hope [ "$status" -eq 1 ] [[ "$output" == *"add --confirm hope"* ]] } @test "export needs an absolute .zip path" { run bash "$CC" export hope --out relative.zip [ "$status" -eq 1 ] [[ "$output" == *"absolute path ending in .zip"* ]] } @test "install --frp needs the ports from the Hub" { run bash "$CC" install hope --products events --domain hope.co.za --frp [ "$status" -eq 1 ] [[ "$output" == *"--frp needs --api-port and --web-port"* ]] } @test "help lists the new commands" { run bash "$CC" help [[ "$output" == *"crosscode uninstall --confirm "* ]] [[ "$output" == *"--json"* ]] run bash "$CC" help export [[ "$output" == *"crosscode.church-export/1"* ]] }