#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

find "$ROOT" -type f -name '*.php' -print0 | xargs -0 -n1 php -l
php "$ROOT/tests/commercial_unit.php"
php "$ROOT/tests/workshop_unit.php"
php "$ROOT/tests/currency_unit.php"
php "$ROOT/tests/notification_unit.php"
php "$ROOT/tests/notification_message_unit.php"
php "$ROOT/tests/notification_smtp_security_unit.php"
bash "$ROOT/bin/verify_notification_smtp.sh"
bash "$ROOT/tests/notification_wrapper_unit.sh"
bash "$ROOT/tests/notification_cron_unit.sh"
python3 - "$ROOT/docs/openapi-commercial.yaml" <<'PY'
import sys, yaml
with open(sys.argv[1], encoding="utf-8") as handle:
    document = yaml.safe_load(handle)
assert document["openapi"] == "3.1.0"
assert "/api/v1/commercial/estimates" in document["paths"]
assert "/api/v1/chat/lead-handoffs" in document["paths"]
print("openapi-commercial: PASS")
PY
python3 - "$ROOT/docs/openapi-workshop.yaml" <<'PY'
import sys, yaml
with open(sys.argv[1], encoding="utf-8") as handle:
    document = yaml.safe_load(handle)
assert document["openapi"] == "3.1.0"
assert "/api/v1/workshop-booking/holds" in document["paths"]
assert "/api/v1/workshop-checkout/charge" in document["paths"]
assert "/api/v1/workshop-payments/midtrans/notification" in document["paths"]
print("openapi-workshop: PASS")
PY
