added admin routes

This commit is contained in:
2025-02-28 19:11:16 -05:00
parent 29ef485e29
commit da40f652a7
10 changed files with 152 additions and 82 deletions
+20 -17
View File
@@ -1,6 +1,8 @@
#!/bin/bash
CONTAINER_NAME="batched-server"
SERVER_URL="http://localhost:15521"
VOLUME_PATH="/app/data" # Path inside container
test_server_running() {
echo "Testing if the server is running..."
@@ -14,40 +16,41 @@ test_server_running() {
fi
}
test_submit_email() {
echo "Testing email submission..."
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "email=test@example.com" "$SERVER_URL/submit")
test_form_submission() {
echo "Testing form submission to dynamic endpoint..."
FORM_NAME="testform"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "email=test@example.com" "$SERVER_URL/$FORM_NAME")
if [ "$RESPONSE" -eq 200 ]; then
echo "✅ Email submission successful (Status: 200 OK)"
echo "✅ Form submission to /$FORM_NAME successful (Status: 200 OK)"
else
echo "Email submission failed (Received status: $RESPONSE)"
echo "Form submission failed (Received status: $RESPONSE)"
exit 1
fi
}
test_csv_written() {
CSV_FILE="batched-server/emails.csv"
CSV_FILE="$VOLUME_PATH/emails.csv"
FORM_NAME="testform"
if [ -f "$CSV_FILE" ]; then
if grep -q "test@example.com" "$CSV_FILE"; then
echo "✅ Email found in $CSV_FILE"
# Use docker exec to check CSV inside container
if docker exec $CONTAINER_NAME /bin/sh -c "[ -f $CSV_FILE ]"; then
if docker exec $CONTAINER_NAME grep -q "test@example.com,$FORM_NAME" "$CSV_FILE"; then
echo "✅ Entry found in CSV (form: $FORM_NAME)"
else
echo "❌ Email NOT found in $CSV_FILE"
echo "❌ Entry NOT found in CSV"
exit 1
fi
else
echo "❌ CSV file not found!"
echo "❌ CSV file not found in container!"
exit 1
fi
}
# run the tests
# Run tests
test_server_running
test_submit_email
sleep 2 # wait for the batched write to complete
test_form_submission
sleep 2 # Allow time for batched write
test_csv_written
echo "✅ All tests passed successfully!"
echo "✅ All batched CSV tests passed!"
+29 -30
View File
@@ -1,58 +1,57 @@
#!/bin/bash
CONTAINER_NAME="sqlite-server"
SERVER_URL="http://localhost:15521"
VOLUME_PATH="/app/data"
test_server_running() {
# testing if the server is running...
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL/")
if [ "$RESPONSE" -eq 200 ]; then
echo "✅ server is running (status: 200 ok)";
echo "✅ Server is running (status: 200 OK)"
else
echo "server is not running (received status: $RESPONSE)";
exit 1;
echo "Server is not running (received status: $RESPONSE)"
exit 1
fi
}
test_submit_email() {
# testing email submission...
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "email=test@example.com" "$SERVER_URL/submit")
test_form_submission() {
FORM_NAME="testform"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "email=test@example.com" "$SERVER_URL/$FORM_NAME")
if [ "$RESPONSE" -eq 200 ]; then
echo "✅ email submission successful (status: 200 ok)";
echo "✅ Form submission to /$FORM_NAME successful (status: 200 OK)"
else
echo "email submission failed (received status: $RESPONSE)";
exit 1;
echo "Form submission failed (received status: $RESPONSE)"
exit 1
fi
}
test_db_entry() {
# testing if the email was written to the sqlite database...
DB_FILE="sqlite-server/emails.db"
DB_FILE="$VOLUME_PATH/emails.db"
FORM_NAME="testform"
if [ -f "$DB_FILE" ]; then
if ! command -v sqlite3 >/dev/null 2>&1; then
echo "❌ sqlite3 is not installed. please install sqlite3 to run this test";
exit 1;
fi;
# Use docker exec to check database inside container
if docker exec $CONTAINER_NAME /bin/sh -c "[ -f $DB_FILE ]"; then
result=$(docker exec $CONTAINER_NAME sqlite3 "$DB_FILE" \
"SELECT email FROM emails WHERE email='test@example.com' AND formname='$FORM_NAME';")
result=$(sqlite3 "$DB_FILE" "select email from emails where email='test@example.com';")
if [ "$result" == "test@example.com" ]; then
echo "email found in $DB_FILE";
echo "Entry found in database (form: $FORM_NAME)"
else
echo "❌ email not found in $DB_FILE";
exit 1;
fi;
echo "❌ Entry not found in database"
exit 1
fi
else
echo "database file $DB_FILE not found!";
exit 1;
echo "❌ Database file not found in container!"
exit 1
fi
}
# run the tests
test_server_running;
test_submit_email;
sleep 2; # wait for the write to complete
test_db_entry;
# Run tests
test_server_running
test_form_submission
sleep 2 # Allow time for async write
test_db_entry
echo "✅ all tests passed successfully!";
echo "✅ All SQLite tests passed!"