#!/usr/bin/env bats

load 'helpers'

setup() {
  setup_party_sandbox
  require_party_group
}
teardown() { teardown_party_sandbox; }

@test "full lifecycle: host → invite → voice → mute → kick → close" {
  other=$(pick_other_user)
  [ -n "$other" ] || skip "no second user on this box"

  "$PARTY_BIN" host e2e

  # discover
  run "$PARTY_BIN" list
  [[ "$output" == *"e2e"* ]]

  # invite
  "$PARTY_BIN" invite "$other" -r
  rec="$PARTY_SOCKET_DIR/party-$USER:e2e.d/roster"
  sock=$(awk -F= '$1=="SOCKET"{print $2}' "$rec")
  tmux -S "$sock" server-access -l | grep -q "^$other"

  # voice → mute
  "$PARTY_BIN" voice "$other"
  "$PARTY_BIN" mute "$other"

  # kick
  "$PARTY_BIN" kick "$other"

  # close
  "$PARTY_BIN" close e2e
  [ ! -f "$rec" ]
  [ ! -S "$sock" ]
}

@test "all subcommands appear in --help" {
  run "$PARTY_BIN" --help
  for sub in host close join leave invite voice mute kick detach role list who status; do
    [[ "$output" == *"$sub"* ]] || { echo "missing in --help: $sub"; false; }
  done
}
