diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..20b1eee Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index f8dee5d..e2c0080 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,19 @@ npm run dev # Start the server docker compose up --build ``` + +## Localhost API Test + +After the API is running on port 8080, run this smoke test: + +```bash +bash scripts/test_localhost.sh +``` + +If your API is running on a different host or port: + +```bash +bash scripts/test_localhost.sh http://localhost:9000 +``` + +The script sends a valid request to `POST /api/submit/exec-form` and fails with a non-zero exit code if the endpoint does not return a successful response. diff --git a/scripts/test_localhost.sh b/scripts/test_localhost.sh new file mode 100755 index 0000000..502d239 --- /dev/null +++ b/scripts/test_localhost.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +set -euo pipefail + +BASE_URL="${1:-http://localhost:8080}" +ENDPOINT="${BASE_URL%/}/api/submit/exec-form" + +PAYLOAD='{ + "fullName": "Local Test User", + "email": "local.test@example.com", + "studentId": "12345678", + "yearOfStudy": "3", + "faculty": "Engineering", + "major": "Software Engineering", + "coopTerm": "no", + "firstChoiceTeam": "TECHNOLOGY", + "questions": { + "tech_q1": "I enjoy building backend services.", + "tech_q2": "I want to grow in API design.", + "tech_q3": "Python and FastAPI.", + "tech_q4": "I collaborate through pull requests and code reviews." + } +}' + +TMP_BODY="$(mktemp)" +trap 'rm -f "$TMP_BODY"' EXIT + +HTTP_CODE="$(curl -sS -o "$TMP_BODY" -w "%{http_code}" \ + -X POST "$ENDPOINT" \ + -H "Content-Type: application/json" \ + -d "$PAYLOAD")" + +BODY="$(cat "$TMP_BODY")" + +if [[ "$HTTP_CODE" != "200" ]]; then + echo "Localhost test failed: expected HTTP 200, got HTTP $HTTP_CODE" + echo "Endpoint: $ENDPOINT" + echo "Response body:" + echo "$BODY" + exit 1 +fi + +if [[ "$BODY" != *'"message":"Submission received successfully"'* ]]; then + echo "Localhost test failed: success message not found in response" + echo "Endpoint: $ENDPOINT" + echo "Response body:" + echo "$BODY" + exit 1 +fi + +echo "Localhost test passed" +echo "Endpoint: $ENDPOINT" +echo "HTTP $HTTP_CODE" +echo "$BODY"