#!/usr/bin/env bash
# Common helpers for orca bats tests (C-15). Sourced by every test file.
# See scripts/tests/README.md for the bash testing policy.

# Resolve the scripts/ dir relative to this test file.
# BASH_SOURCE[0] is this helper file (scripts/tests/test_helper.bash).
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
export SCRIPTS_DIR

# assert_status <expected> <actual> — assert a command's exit status.
assert_status() {
	local expected="$1" actual="$2"
	[ "$expected" = "$actual" ] || {
		echo "expected status $expected, got $actual" >&2
		return 1
	}
}

# assert_contains <haystack> <needle> — substring assertion.
assert_contains() {
	local haystack="$1" needle="$2"
	case "$haystack" in
		*"$needle"*) return 0 ;;
		*) echo "expected [$haystack] to contain [$needle]" >&2; return 1 ;;
	esac
}

# assert_not_contains <haystack> <needle> — negative substring assertion.
assert_not_contains() {
	local haystack="$1" needle="$2"
	case "$haystack" in
		*"$needle"*) echo "expected [$haystack] to NOT contain [$needle]" >&2; return 1 ;;
	esac
	:
}

# assert_json_field <json> <field> — crude JSON field presence check (no jq dep).
# Matches "<field>": present anywhere in the JSON string.
assert_json_field() {
	local json="$1" field="$2"
	assert_contains "$json" "\"$field\""
}