#!/bin/bash

set -e

# defaults if not set
: "${SKIP_LINT:=0}"
: "${SKIP_INTEGRATION:=1}"
: "${SKIP_E2E:=1}"
: "${SKIP_SALESFORCE:=1}"
: "${COV_REPORT:=term}"
: "${COV_PORT:=8000}"

# convert to all lowercase
COV_REPORT=$(echo $COV_REPORT | tr '[:upper:]' '[:lower:]')

# run linting of python and yaml files
if [ "$SKIP_LINT" -ne 1 ]; then
    echo 'Running linting...'
    yamllint -s docker-compose.yaml
    flake8 tests/
else
    echo 'Skipping linting...'
fi

if [ "$SKIP_INTEGRATION" -ne 1 ]; then
  echo 'Running integration tests...'
  pytest tests/test_account_creation.py
else
  echo 'Skipping integration tests...'
fi

if [ "$SKIP_E2E" -ne 1 ]; then
  echo 'Running e2e tests...'
  pytest -s --reruns 1 tests/test_awal_account_creation.py
else
  echo 'Skipping e2e tests...'
fi

if [ "$SKIP_SALESFORCE" -ne 1 ]; then
  pytest -s tests/test_salesforce_configuration.py
else
  echo 'Skipping salesforce tests...'
fi
echo 'Done!'
