.PHONY: install_with_dev install_with_dev_from_lock dev lint test test_unit pip_test_integration test_integration test_integration_transfer_ownership clean clean_test_integration ci_unit_lint ci_test_integration

# Update and install all dependencies (including dev)
install_with_dev:
	PIPENV_VENV_IN_PROJECT=1 pipenv --rm install --dev

# Install all dependencies (including dev) from lock file
install_with_dev_from_lock:
	PIPENV_VENV_IN_PROJECT=1 pipenv --rm install --dev --ignore-pipfile

# Run application
dev:
	pipenv run python dev.py

lint:
	pipenv run pre-commit run --all-files

test_unit:
	pipenv run pytest tests/unit/

test_unit_cov:
	pipenv run pytest --cov analytics tests/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	pipenv run pytest -n auto --dist loadscope --ignore tests/integration/transfer_ownership --ignore tests/integration/endpoint_diff tests/integration

test_integration_endpoints:
	pipenv run python tests/integration/run_endpoints.py -n 15

test_integration_endpoints_serial:
	pipenv run pytest tests/integration/endpoints -v

test_integration_consistency:
	pipenv run pytest tests/integration/consistency

test_integration_non_endpoints:
	pipenv run pytest --ignore tests/integration/endpoints --ignore tests/integration/transfer_ownership --ignore tests/integration/endpoint_diff tests/integration

# Transfer-ownership suite: parametrized on placeholder InsightsProfile fixtures
# (99918930-99918935) that need to be provisioned in QA Permissions API with
# the insights_transfer_product_ownership feature flag assigned. Lower
# parallelism than test_integration_endpoints to keep Snowflake QA load reasonable.
test_integration_transfer_ownership:
	pipenv run pytest tests/integration/transfer_ownership -n 6 -v

clean:
	rm -rf .venv

create_split_config:
	touch ~/.split

ci_unit_lint:
	 docker build --target pr_tests -t ows-analytics-unit-tests:local .
	 docker run -v $(PWD):/var/app ows-analytics-unit-tests:local pytest -p no:cacheprovider --cov analytics tests/unit/ --cov-report xml --junitxml=/var/app/pyunit.xml

ci_test_integration:
	 docker build --target pr_tests -t ows-analytics-unit-tests:local .
	 docker run -e INTEGRATION_TESTS_BASE_URL=https://qa-ows-analytics.theorchard.io ows-analytics-unit-tests:local python tests/integration/run_endpoints.py -n 15
	 docker run -e INTEGRATION_TESTS_BASE_URL=https://qa-ows-analytics.theorchard.io ows-analytics-unit-tests:local pytest tests/integration/consistency
	 docker run -e INTEGRATION_TESTS_BASE_URL=https://qa-ows-analytics.theorchard.io ows-analytics-unit-tests:local pytest --ignore tests/integration/endpoints --ignore tests/integration/transfer_ownership --ignore tests/integration/endpoint_diff tests/integration
