# Veza Platform - Root Makefile
# Test Coverage targets (T0043)

.PHONY: test-coverage coverage-html help

help: ## Show this help message
	@echo 'Usage: make [target]'
	@echo ''
	@echo 'Test Coverage targets:'
	@echo '  test-coverage  - Run tests and generate coverage report (T0043)'
	@echo '  coverage-html  - Generate HTML coverage report from existing coverage.out (T0043)'

test-coverage: ## Run tests and generate coverage report (T0043)
	@echo "📊 Generating test coverage report..."
	@bash scripts/test-coverage.sh

coverage-html: ## Generate HTML coverage report from existing coverage.out (T0043)
	@echo "📊 Generating HTML coverage report..."
	@cd veza-backend-api && go tool cover -html=coverage/coverage.out -o coverage/coverage.html
	@echo "✅ Coverage report generated: veza-backend-api/coverage/coverage.html"

# >>> VEZA:BEGIN QA TARGETS
.PHONY: smoke e2e postman lighthouse load qa-all visual backstop-ref backstop-test loki lh a11y start-services

smoke: ## Run API smoke tests (curl + httpie)
	@echo "🔥 Running API smoke tests..."
	@bash .veza/qa/scripts/wait_for_http.sh "$${VEZA_API_BASE_URL:-http://localhost:8080}/health" 90
	@bash .veza/qa/scripts/smoke_curl.sh
	@bash .veza/qa/scripts/smoke_httpie.sh || true

start-services: ## Start services required for QA tests
	@echo "🚀 Starting services for QA tests..."
	@bash .veza/qa/scripts/start-services-for-tests.sh

e2e: ## Run E2E tests with Playwright
	@echo "🎭 Running E2E tests..."
	@cd .veza/qa/playwright && \
		if [ ! -d "node_modules" ] || [ ! -f "node_modules/@playwright/test/package.json" ]; then \
			echo "📦 Installing Playwright dependencies..."; \
			npm install --silent; \
		fi && \
		npx playwright test --config=playwright.config.ts

postman: ## Run Postman/Newman tests
	@echo "📮 Running Postman/Newman tests..."
	@newman run .veza/qa/postman/veza_api_collection.json \
		-e .veza/qa/data/postman_env_local.json \
		--reporters cli,junit \
		--reporter-junit-export reports/newman.xml || true

lighthouse: ## Run Lighthouse CI
	@echo "💡 Running Lighthouse CI..."
	@npx lhci autorun --config=.veza/qa/lighthouse/lighthouserc.json || true

load: ## Run k6 load tests
	@echo "⚡ Running k6 load tests..."
	@k6 run .veza/qa/k6/smoke.js || true

visual: ## Run Playwright visual regression tests
	@echo "🖼️  Running Playwright visual regression tests..."
	@cd .veza/qa/playwright && \
		if [ ! -d "node_modules" ] || [ ! -f "node_modules/@playwright/test/package.json" ]; then \
			echo "📦 Installing Playwright dependencies..."; \
			npm install --silent; \
		fi && \
		npx playwright test tests/visual/ --config=playwright.config.ts

visual-update: ## Generate/update Playwright visual snapshots
	@echo "📸 Generating Playwright visual snapshots..."
	@cd .veza/qa/playwright && \
		if [ ! -d "node_modules" ] || [ ! -f "node_modules/@playwright/test/package.json" ]; then \
			echo "📦 Installing Playwright dependencies..."; \
			npm install --silent; \
		fi && \
		npx playwright test tests/visual/ --config=playwright.config.ts --update-snapshots

backstop-ref: ## Generate BackstopJS reference images
	@echo "📸 Generating BackstopJS reference images..."
	@cd .veza/qa/backstop && npx backstop reference --config=backstop.json || true

backstop-test: ## Run BackstopJS visual regression tests
	@echo "🔍 Running BackstopJS visual regression tests..."
	@cd .veza/qa/backstop && npx backstop test --config=backstop.json || true

loki: ## Run Loki visual regression tests (requires Storybook)
	@echo "📚 Running Loki visual regression tests..."
	@echo "⚠️  Loki requires Storybook to be set up. See .veza/qa/README.md for setup instructions."
	@if [ -d ".storybook" ] || [ -d "apps/web/.storybook" ]; then \
		npx loki test || true; \
	else \
		echo "❌ Storybook not found. Install Storybook first to use Loki."; \
		exit 1; \
	fi

lh: lighthouse ## Alias for lighthouse

a11y: ## Run Pa11y accessibility tests
	@echo "♿ Running Pa11y accessibility tests..."
	@npx pa11y-ci --config .veza/qa/pa11y/.pa11yci.json || true

qa-all: smoke e2e postman lighthouse load visual a11y ## Run all QA tests
	@echo "✅ All QA tests completed!"
# <<< VEZA:END QA TARGETS
