#!/usr/bin/env bash

setup() {
  load "$PWD/tests/integration/helpers/common"
  _common_setup

  if [[ -f "$HOME/.local/bin/abra" ]]; then
    mv "$HOME/.local/bin/abra" "$HOME/.local/bin/abra_before_test"
  fi
}

teardown(){
  if [[ -f "$HOME/.local/bin/abra_before_test" ]]; then
    rm -rf "$HOME/.local/bin/abra"
    mv "$HOME/.local/bin/abra_before_test" "$HOME/.local/bin/abra"
  fi
}

# bats test_tags=slow
@test "abra upgrade" {
  run $ABRA upgrade
  assert_success
  assert_output --partial 'Public interest infrastructure'

  assert_exists "$HOME/.local/bin/abra"
  run "$HOME/.local/bin/abra" -v
  assert_output --partial 'beta'
}

# bats test_tags=slow
@test "abra upgrade release candidate" {
  run $ABRA upgrade --rc
  assert_success
  assert_output --partial 'Public interest infrastructure'

  assert_exists "$HOME/.local/bin/abra"
  run "$HOME/.local/bin/abra" -v
  assert_output --partial '-rc'
}
