#!/usr/bin/env bats # tests/unit/auth.bats — Auth URL construction tests setup() { export JOSH_SYNC_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)" source "$JOSH_SYNC_ROOT/lib/core.sh" source "$JOSH_SYNC_ROOT/lib/auth.sh" # Set up env vars as parse_config + load_target would export JOSH_PROXY_URL="https://josh.test.local" export MONOREPO_PATH="org/monorepo" export BOT_USER="sync-bot" export GITEA_TOKEN="test-token-123" export JOSH_FILTER=":/services/app-a" export SUBREPO_URL="https://gitea.test.local/ext/app-a.git" export SUBREPO_AUTH="https" export SUBREPO_TOKEN="subrepo-token-456" } @test "josh_auth_url builds correct HTTPS URL with credentials and filter" { local url url=$(josh_auth_url) [ "$url" = "https://sync-bot:test-token-123@josh.test.local/org/monorepo.git:/services/app-a.git" ] } @test "subrepo_auth_url injects credentials for HTTPS" { local url url=$(subrepo_auth_url) [ "$url" = "https://sync-bot:subrepo-token-456@gitea.test.local/ext/app-a.git" ] } @test "subrepo_auth_url returns bare URL for SSH" { export SUBREPO_AUTH="ssh" export SUBREPO_URL="git@gitea.test.local:ext/app-a.git" local url url=$(subrepo_auth_url) [ "$url" = "git@gitea.test.local:ext/app-a.git" ] }