Stage 3.4
This commit is contained in:
50
test/scripts/test_all.sh
Normal file
50
test/scripts/test_all.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB FULL API TEST SUITE"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Проверяем, что сервер запущен
|
||||
if ! curl -s "http://localhost:8080/health" | grep -q "ok"; then
|
||||
echo "❌ Server is not running. Please start the server first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
|
||||
run_test() {
|
||||
echo ""
|
||||
echo "▶ Running $1..."
|
||||
if bash "$SCRIPTS_DIR/$1"; then
|
||||
((PASSED++))
|
||||
echo "✅ $1 PASSED"
|
||||
else
|
||||
((FAILED++))
|
||||
echo "❌ $1 FAILED"
|
||||
fi
|
||||
}
|
||||
|
||||
run_test "test_auth_api.sh"
|
||||
run_test "test_calendar_api.sh"
|
||||
run_test "test_event_api.sh"
|
||||
run_test "test_booking_api.sh"
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
echo " TEST SUMMARY"
|
||||
echo "============================================================"
|
||||
echo "Passed: $PASSED"
|
||||
echo "Failed: $FAILED"
|
||||
echo "============================================================"
|
||||
|
||||
if [ $FAILED -eq 0 ]; then
|
||||
echo "🎉 ALL TESTS PASSED!"
|
||||
exit 0
|
||||
else
|
||||
echo "❌ SOME TESTS FAILED"
|
||||
exit 1
|
||||
fi
|
||||
217
test/scripts/test_auth_api.sh
Normal file
217
test/scripts/test_auth_api.sh
Normal file
@@ -0,0 +1,217 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:8080"
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
||||
|
||||
extract_json() {
|
||||
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
|
||||
}
|
||||
|
||||
http_post() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
else
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url=$1
|
||||
local token=$2
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X GET "$url" \
|
||||
-H "Authorization: Bearer $token"
|
||||
else
|
||||
curl -s -X GET "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB AUTHENTICATION API TEST SCRIPT"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
log_info "Checking if server is running..."
|
||||
if ! curl -s "$BASE_URL/health" | grep -q "ok"; then
|
||||
log_error "Server is not running"
|
||||
exit 1
|
||||
fi
|
||||
log_success "Server is running"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 1: Healthcheck"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/health" "")
|
||||
if echo "$response" | grep -q "ok"; then
|
||||
log_success "Healthcheck passed: $response"
|
||||
else
|
||||
log_error "Healthcheck failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 2: Register new user"
|
||||
log_info "============================================================"
|
||||
|
||||
TEST_EMAIL="test_auth_$(date +%s)@example.com"
|
||||
TEST_PASSWORD="testpass123"
|
||||
|
||||
log_info "Registering $TEST_EMAIL..."
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$TEST_EMAIL\",\"password\":\"$TEST_PASSWORD\"}" "")
|
||||
|
||||
if echo "$response" | grep -q "token"; then
|
||||
TOKEN=$(extract_json "$response" "token")
|
||||
USER_ID=$(extract_json "$response" "id")
|
||||
log_success "Registration successful"
|
||||
log_info "User ID: $USER_ID"
|
||||
log_info "Token: ${TOKEN:0:30}..."
|
||||
else
|
||||
log_error "Registration failed: $response"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 3: Register with existing email (should fail)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$TEST_EMAIL\",\"password\":\"$TEST_PASSWORD\"}" "")
|
||||
if echo "$response" | grep -q "already exists"; then
|
||||
log_success "Duplicate registration correctly rejected"
|
||||
else
|
||||
log_error "Duplicate registration not rejected: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 4: Login with correct credentials"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/login" "{\"email\":\"$TEST_EMAIL\",\"password\":\"$TEST_PASSWORD\"}" "")
|
||||
|
||||
if echo "$response" | grep -q "token"; then
|
||||
LOGIN_TOKEN=$(extract_json "$response" "token")
|
||||
REFRESH_TOKEN=$(extract_json "$response" "refresh_token")
|
||||
log_success "Login successful"
|
||||
log_info "Refresh token received: ${REFRESH_TOKEN:0:30}..."
|
||||
else
|
||||
log_error "Login failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 5: Login with wrong password (should fail)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/login" "{\"email\":\"$TEST_EMAIL\",\"password\":\"wrongpassword\"}" "")
|
||||
if echo "$response" | grep -q "Invalid credentials"; then
|
||||
log_success "Wrong password correctly rejected"
|
||||
else
|
||||
log_error "Wrong password not rejected: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 6: Get user profile with valid token"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/user/me" "$TOKEN")
|
||||
if echo "$response" | grep -q "$TEST_EMAIL"; then
|
||||
log_success "Profile retrieved successfully"
|
||||
log_info "Response: $response"
|
||||
else
|
||||
log_error "Profile retrieval failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 7: Get user profile with invalid token"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/user/me" "invalid.token.here")
|
||||
if echo "$response" | grep -q "Invalid token"; then
|
||||
log_success "Invalid token correctly rejected"
|
||||
else
|
||||
log_error "Invalid token not rejected: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 8: Get user profile without token"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/user/me" "")
|
||||
if echo "$response" | grep -q "Missing or invalid Authorization"; then
|
||||
log_success "Missing token correctly rejected"
|
||||
else
|
||||
log_error "Missing token not rejected: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 9: Refresh token"
|
||||
log_info "============================================================"
|
||||
|
||||
if [ -n "$REFRESH_TOKEN" ]; then
|
||||
response=$(http_post "$BASE_URL/v1/refresh" "{\"refresh_token\":\"$REFRESH_TOKEN\"}" "")
|
||||
if echo "$response" | grep -q "token"; then
|
||||
NEW_TOKEN=$(extract_json "$response" "token")
|
||||
NEW_REFRESH=$(extract_json "$response" "refresh_token")
|
||||
log_success "Token refreshed successfully"
|
||||
log_info "New token: ${NEW_TOKEN:0:30}..."
|
||||
log_info "New refresh token: ${NEW_REFRESH:0:30}..."
|
||||
else
|
||||
log_error "Token refresh failed: $response"
|
||||
fi
|
||||
|
||||
log_info "Trying to reuse old refresh token (should fail)..."
|
||||
response=$(http_post "$BASE_URL/v1/refresh" "{\"refresh_token\":\"$REFRESH_TOKEN\"}" "")
|
||||
if echo "$response" | grep -q "Invalid refresh token"; then
|
||||
log_success "Old refresh token correctly rejected"
|
||||
else
|
||||
log_warning "Old refresh token not rejected: $response"
|
||||
fi
|
||||
else
|
||||
log_warning "No refresh token to test"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 10: Access protected endpoint with new token"
|
||||
log_info "============================================================"
|
||||
|
||||
if [ -n "$NEW_TOKEN" ]; then
|
||||
response=$(http_get "$BASE_URL/v1/user/me" "$NEW_TOKEN")
|
||||
if echo "$response" | grep -q "$TEST_EMAIL"; then
|
||||
log_success "Protected endpoint accessible with new token"
|
||||
else
|
||||
log_error "Protected endpoint not accessible: $response"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
log_success "AUTHENTICATION TESTS COMPLETED!"
|
||||
echo "============================================================"
|
||||
265
test/scripts/test_booking_api.sh
Normal file
265
test/scripts/test_booking_api.sh
Normal file
@@ -0,0 +1,265 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:8080"
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
extract_json() {
|
||||
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
|
||||
}
|
||||
|
||||
http_post() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
else
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url=$1
|
||||
local token=$2
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X GET "$url" \
|
||||
-H "Authorization: Bearer $token"
|
||||
else
|
||||
curl -s -X GET "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
http_put() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
curl -s -X PUT "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
}
|
||||
|
||||
http_delete() {
|
||||
local url=$1
|
||||
local token=$2
|
||||
|
||||
curl -s -X DELETE "$url" \
|
||||
-H "Authorization: Bearer $token"
|
||||
}
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB BOOKING API TEST SCRIPT"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
log_info "Checking if server is running..."
|
||||
if ! curl -s "$BASE_URL/health" | grep -q "ok"; then
|
||||
log_error "Server is not running"
|
||||
exit 1
|
||||
fi
|
||||
log_success "Server is running"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 1: Create test users"
|
||||
log_info "============================================================"
|
||||
|
||||
OWNER_EMAIL="owner_test@example.com"
|
||||
OWNER_PASSWORD="owner123"
|
||||
PARTICIPANT_EMAIL="participant_test@example.com"
|
||||
PARTICIPANT_PASSWORD="participant123"
|
||||
|
||||
# Пробуем зарегистрировать владельца
|
||||
log_info "Creating calendar owner..."
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$OWNER_EMAIL\",\"password\":\"$OWNER_PASSWORD\"}" "")
|
||||
|
||||
if echo "$response" | grep -q "token"; then
|
||||
OWNER_TOKEN=$(extract_json "$response" "token")
|
||||
OWNER_ID=$(extract_json "$response" "id")
|
||||
log_success "Owner registered: $OWNER_EMAIL"
|
||||
else
|
||||
log_info "Owner exists, trying login..."
|
||||
response=$(http_post "$BASE_URL/v1/login" "{\"email\":\"$OWNER_EMAIL\",\"password\":\"$OWNER_PASSWORD\"}" "")
|
||||
OWNER_TOKEN=$(extract_json "$response" "token")
|
||||
OWNER_ID=$(extract_json "$response" "id")
|
||||
fi
|
||||
|
||||
if [ -z "$OWNER_TOKEN" ]; then
|
||||
log_error "Failed to get owner token"
|
||||
echo "$response"
|
||||
exit 1
|
||||
fi
|
||||
log_success "Owner ready (ID: $OWNER_ID)"
|
||||
|
||||
# Пробуем зарегистрировать участника
|
||||
log_info "Creating participant..."
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$PARTICIPANT_EMAIL\",\"password\":\"$PARTICIPANT_PASSWORD\"}" "")
|
||||
|
||||
if echo "$response" | grep -q "token"; then
|
||||
PARTICIPANT_TOKEN=$(extract_json "$response" "token")
|
||||
PARTICIPANT_ID=$(extract_json "$response" "id")
|
||||
log_success "Participant registered: $PARTICIPANT_EMAIL"
|
||||
else
|
||||
log_info "Participant exists, trying login..."
|
||||
response=$(http_post "$BASE_URL/v1/login" "{\"email\":\"$PARTICIPANT_EMAIL\",\"password\":\"$PARTICIPANT_PASSWORD\"}" "")
|
||||
PARTICIPANT_TOKEN=$(extract_json "$response" "token")
|
||||
PARTICIPANT_ID=$(extract_json "$response" "id")
|
||||
fi
|
||||
|
||||
if [ -z "$PARTICIPANT_TOKEN" ]; then
|
||||
log_error "Failed to get participant token"
|
||||
echo "$response"
|
||||
exit 1
|
||||
fi
|
||||
log_success "Participant ready (ID: $PARTICIPANT_ID)"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 2: Create calendars"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Creating AUTO calendar..."
|
||||
response=$(http_post "$BASE_URL/v1/calendars" "{\"title\":\"Auto Calendar\",\"confirmation\":\"auto\"}" "$OWNER_TOKEN")
|
||||
AUTO_CALENDAR_ID=$(extract_json "$response" "id")
|
||||
log_success "Auto calendar: $AUTO_CALENDAR_ID"
|
||||
|
||||
log_info "Creating MANUAL calendar..."
|
||||
response=$(http_post "$BASE_URL/v1/calendars" "{\"title\":\"Manual Calendar\",\"confirmation\":\"manual\"}" "$OWNER_TOKEN")
|
||||
MANUAL_CALENDAR_ID=$(extract_json "$response" "id")
|
||||
log_success "Manual calendar: $MANUAL_CALENDAR_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 3: Create events"
|
||||
log_info "============================================================"
|
||||
|
||||
EVENT_START="2026-05-01T10:00:00Z"
|
||||
|
||||
log_info "Creating event in AUTO calendar..."
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$AUTO_CALENDAR_ID/events" \
|
||||
"{\"title\":\"Auto Event\",\"start_time\":\"$EVENT_START\",\"duration\":60,\"capacity\":10}" "$OWNER_TOKEN")
|
||||
AUTO_EVENT_ID=$(extract_json "$response" "id")
|
||||
log_success "Auto event: $AUTO_EVENT_ID"
|
||||
|
||||
log_info "Creating event in MANUAL calendar..."
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$MANUAL_CALENDAR_ID/events" \
|
||||
"{\"title\":\"Manual Event\",\"start_time\":\"$EVENT_START\",\"duration\":60,\"capacity\":10}" "$OWNER_TOKEN")
|
||||
MANUAL_EVENT_ID=$(extract_json "$response" "id")
|
||||
log_success "Manual event: $MANUAL_EVENT_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 4: Test AUTO confirmation"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Participant booking AUTO event..."
|
||||
response=$(http_post "$BASE_URL/v1/events/$AUTO_EVENT_ID/bookings" "" "$PARTICIPANT_TOKEN")
|
||||
echo "Response: $response"
|
||||
AUTO_BOOKING_STATUS=$(extract_json "$response" "status")
|
||||
|
||||
if [ "$AUTO_BOOKING_STATUS" = "confirmed" ]; then
|
||||
log_success "Auto-booking confirmed immediately"
|
||||
else
|
||||
log_error "Auto-booking status: $AUTO_BOOKING_STATUS"
|
||||
fi
|
||||
|
||||
# Сохраняем ID авто-бронирования
|
||||
AUTO_BOOKING_ID=$(extract_json "$response" "id")
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 5: Test MANUAL confirmation"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Participant booking MANUAL event..."
|
||||
response=$(http_post "$BASE_URL/v1/events/$MANUAL_EVENT_ID/bookings" "" "$PARTICIPANT_TOKEN")
|
||||
MANUAL_BOOKING_ID=$(extract_json "$response" "id")
|
||||
MANUAL_BOOKING_STATUS=$(extract_json "$response" "status")
|
||||
|
||||
if [ "$MANUAL_BOOKING_STATUS" = "pending" ]; then
|
||||
log_success "Manual-booking is pending: $MANUAL_BOOKING_ID"
|
||||
else
|
||||
log_error "Manual-booking status: $MANUAL_BOOKING_STATUS"
|
||||
fi
|
||||
|
||||
log_info "Owner confirming booking..."
|
||||
response=$(http_put "$BASE_URL/v1/bookings/$MANUAL_BOOKING_ID" "{\"action\":\"confirm\"}" "$OWNER_TOKEN")
|
||||
CONFIRMED_STATUS=$(extract_json "$response" "status")
|
||||
|
||||
if [ "$CONFIRMED_STATUS" = "confirmed" ]; then
|
||||
log_success "Booking confirmed by owner"
|
||||
else
|
||||
log_error "Confirmation failed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 6: Test booking lists"
|
||||
log_info "============================================================"
|
||||
|
||||
log_info "Owner viewing event bookings..."
|
||||
response=$(http_get "$BASE_URL/v1/events/$MANUAL_EVENT_ID/bookings" "$OWNER_TOKEN")
|
||||
echo "Response: $response"
|
||||
|
||||
log_info "Participant viewing their bookings..."
|
||||
response=$(http_get "$BASE_URL/v1/user/bookings" "$PARTICIPANT_TOKEN")
|
||||
echo "Response: $response"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "STEP 7: Test booking cancellation"
|
||||
log_info "============================================================"
|
||||
|
||||
# Используем первое бронирование для отмены
|
||||
if [ -n "$AUTO_BOOKING_ID" ]; then
|
||||
CANCEL_BOOKING_ID="$AUTO_BOOKING_ID"
|
||||
log_info "Using auto-booking for cancellation: $CANCEL_BOOKING_ID"
|
||||
else
|
||||
# Создаём новое событие для теста отмены
|
||||
log_info "Creating new event for cancellation test..."
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$MANUAL_CALENDAR_ID/events" \
|
||||
"{\"title\":\"Cancel Test Event\",\"start_time\":\"$EVENT_START\",\"duration\":60,\"capacity\":10}" "$OWNER_TOKEN")
|
||||
CANCEL_EVENT_ID=$(extract_json "$response" "id")
|
||||
log_info "Event created: $CANCEL_EVENT_ID"
|
||||
|
||||
log_info "Creating booking to cancel..."
|
||||
response=$(http_post "$BASE_URL/v1/events/$CANCEL_EVENT_ID/bookings" "" "$PARTICIPANT_TOKEN")
|
||||
CANCEL_BOOKING_ID=$(extract_json "$response" "id")
|
||||
log_info "Created: $CANCEL_BOOKING_ID"
|
||||
fi
|
||||
|
||||
if [ -n "$CANCEL_BOOKING_ID" ]; then
|
||||
log_info "Cancelling booking $CANCEL_BOOKING_ID..."
|
||||
response=$(http_delete "$BASE_URL/v1/bookings/$CANCEL_BOOKING_ID" "$PARTICIPANT_TOKEN")
|
||||
CANCELLED_STATUS=$(extract_json "$response" "status")
|
||||
|
||||
if [ "$CANCELLED_STATUS" = "cancelled" ]; then
|
||||
log_success "Booking cancelled"
|
||||
else
|
||||
log_error "Cancellation failed: $response"
|
||||
fi
|
||||
else
|
||||
log_error "No booking to cancel"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
log_success "TESTS COMPLETED!"
|
||||
echo "============================================================"
|
||||
217
test/scripts/test_calendar_api.sh
Normal file
217
test/scripts/test_calendar_api.sh
Normal file
@@ -0,0 +1,217 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:8080"
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
extract_json() {
|
||||
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
|
||||
}
|
||||
|
||||
http_post() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
else
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url=$1
|
||||
local token=$2
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X GET "$url" \
|
||||
-H "Authorization: Bearer $token"
|
||||
else
|
||||
curl -s -X GET "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
http_put() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
curl -s -X PUT "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
}
|
||||
|
||||
http_delete() {
|
||||
local url=$1; local token=$2
|
||||
curl -s -X DELETE "$url" -H "Authorization: Bearer $token"
|
||||
}
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB CALENDAR API TEST SCRIPT"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
log_info "Setting up test users..."
|
||||
|
||||
# Создаём двух пользователей
|
||||
OWNER_EMAIL="calendar_owner_$(date +%s)@example.com"
|
||||
OWNER_PASS="owner123"
|
||||
OTHER_EMAIL="calendar_other_$(date +%s)@example.com"
|
||||
OTHER_PASS="other123"
|
||||
|
||||
# Владелец
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$OWNER_EMAIL\",\"password\":\"$OWNER_PASS\"}" "")
|
||||
OWNER_TOKEN=$(extract_json "$response" "token")
|
||||
OWNER_ID=$(extract_json "$response" "id")
|
||||
log_success "Owner created: $OWNER_ID"
|
||||
|
||||
# Другой пользователь
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$OTHER_EMAIL\",\"password\":\"$OTHER_PASS\"}" "")
|
||||
OTHER_TOKEN=$(extract_json "$response" "token")
|
||||
OTHER_ID=$(extract_json "$response" "id")
|
||||
log_success "Other user created: $OTHER_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 1: Create calendar"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/calendars" "{\"title\":\"My Personal Calendar\",\"description\":\"Test description\"}" "$OWNER_TOKEN")
|
||||
CALENDAR_ID=$(extract_json "$response" "id")
|
||||
|
||||
if [ -n "$CALENDAR_ID" ]; then
|
||||
log_success "Calendar created: $CALENDAR_ID"
|
||||
else
|
||||
log_error "Calendar creation failed: $response"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 2: Create commercial calendar"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/calendars" "{\"title\":\"Commercial Calendar\",\"type\":\"commercial\"}" "$OWNER_TOKEN")
|
||||
COMMERCIAL_ID=$(extract_json "$response" "id")
|
||||
log_success "Commercial calendar created: $COMMERCIAL_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 3: List calendars (owner)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars" "$OWNER_TOKEN")
|
||||
COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
|
||||
log_success "Owner sees $COUNT calendars"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 4: List calendars (other user - empty)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars" "$OTHER_TOKEN")
|
||||
COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
|
||||
log_success "Other user sees $COUNT calendars"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 5: Get calendar by ID (owner)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars/$CALENDAR_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "My Personal Calendar"; then
|
||||
log_success "Owner can access personal calendar"
|
||||
else
|
||||
log_error "Owner cannot access calendar: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 6: Get personal calendar (other user - denied)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars/$CALENDAR_ID" "$OTHER_TOKEN")
|
||||
if echo "$response" | grep -q "Access denied"; then
|
||||
log_success "Other user correctly denied access to personal calendar"
|
||||
else
|
||||
log_error "Access control failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 7: Get commercial calendar (other user - allowed)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars/$COMMERCIAL_ID" "$OTHER_TOKEN")
|
||||
if echo "$response" | grep -q "Commercial Calendar"; then
|
||||
log_success "Other user can access commercial calendar"
|
||||
else
|
||||
log_error "Other user cannot access commercial calendar: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 8: Update calendar (owner)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_put "$BASE_URL/v1/calendars/$CALENDAR_ID" "{\"title\":\"Updated Calendar\"}" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "Updated Calendar"; then
|
||||
log_success "Calendar updated successfully"
|
||||
else
|
||||
log_error "Calendar update failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 9: Update calendar (other user - denied)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_put "$BASE_URL/v1/calendars/$CALENDAR_ID" "{\"title\":\"Hacked\"}" "$OTHER_TOKEN")
|
||||
if echo "$response" | grep -q "Access denied"; then
|
||||
log_success "Other user correctly denied update"
|
||||
else
|
||||
log_error "Access control failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 10: Delete calendar (owner)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_delete "$BASE_URL/v1/calendars/$CALENDAR_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "deleted"; then
|
||||
log_success "Calendar deleted"
|
||||
else
|
||||
log_error "Calendar deletion failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 11: Get deleted calendar (should be denied)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars/$CALENDAR_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "Access denied"; then
|
||||
log_success "Deleted calendar not accessible"
|
||||
else
|
||||
log_error "Deleted calendar still accessible: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
log_success "CALENDAR API TESTS COMPLETED!"
|
||||
echo "============================================================"
|
||||
212
test/scripts/test_event_api.sh
Normal file
212
test/scripts/test_event_api.sh
Normal file
@@ -0,0 +1,212 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:8080"
|
||||
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
extract_json() {
|
||||
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
|
||||
}
|
||||
|
||||
http_post() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
else
|
||||
curl -s -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
http_get() {
|
||||
local url=$1
|
||||
local token=$2
|
||||
|
||||
if [ -n "$token" ]; then
|
||||
curl -s -X GET "$url" \
|
||||
-H "Authorization: Bearer $token"
|
||||
else
|
||||
curl -s -X GET "$url"
|
||||
fi
|
||||
}
|
||||
|
||||
http_put() {
|
||||
local url=$1
|
||||
local data=$2
|
||||
local token=$3
|
||||
|
||||
curl -s -X PUT "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$data"
|
||||
}
|
||||
|
||||
http_delete() {
|
||||
local url=$1; local token=$2
|
||||
curl -s -X DELETE "$url" -H "Authorization: Bearer $token"
|
||||
}
|
||||
|
||||
echo "============================================================"
|
||||
echo " EVENTHUB EVENT API TEST SCRIPT"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
log_info "Setting up test users and calendar..."
|
||||
|
||||
OWNER_EMAIL="event_owner_$(date +%s)@example.com"
|
||||
OWNER_PASS="owner123"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$OWNER_EMAIL\",\"password\":\"$OWNER_PASS\"}" "")
|
||||
OWNER_TOKEN=$(extract_json "$response" "token")
|
||||
OWNER_ID=$(extract_json "$response" "id")
|
||||
log_success "Owner created"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/calendars" "{\"title\":\"Test Calendar\"}" "$OWNER_TOKEN")
|
||||
CALENDAR_ID=$(extract_json "$response" "id")
|
||||
log_success "Calendar created: $CALENDAR_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 1: Create single event"
|
||||
log_info "============================================================"
|
||||
|
||||
EVENT_START="2026-06-01T10:00:00Z"
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$CALENDAR_ID/events" \
|
||||
"{\"title\":\"Single Event\",\"start_time\":\"$EVENT_START\",\"duration\":60}" "$OWNER_TOKEN")
|
||||
EVENT_ID=$(extract_json "$response" "id")
|
||||
|
||||
if [ -n "$EVENT_ID" ]; then
|
||||
log_success "Single event created: $EVENT_ID"
|
||||
else
|
||||
log_error "Event creation failed: $response"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 2: Create event with capacity"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$CALENDAR_ID/events" \
|
||||
"{\"title\":\"Capacity Event\",\"start_time\":\"$EVENT_START\",\"duration\":60,\"capacity\":10}" "$OWNER_TOKEN")
|
||||
CAPACITY_EVENT_ID=$(extract_json "$response" "id")
|
||||
log_success "Event with capacity created: $CAPACITY_EVENT_ID"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 3: Create event in past (should fail)"
|
||||
log_info "============================================================"
|
||||
|
||||
PAST_START="2020-01-01T10:00:00Z"
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$CALENDAR_ID/events" \
|
||||
"{\"title\":\"Past Event\",\"start_time\":\"$PAST_START\",\"duration\":60}" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "past"; then
|
||||
log_success "Past event correctly rejected"
|
||||
else
|
||||
log_error "Past event not rejected: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 4: List events"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/calendars/$CALENDAR_ID/events" "$OWNER_TOKEN")
|
||||
COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
|
||||
log_success "Found $COUNT events"
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 5: Get event by ID"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/events/$EVENT_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "Single Event"; then
|
||||
log_success "Event retrieved successfully"
|
||||
else
|
||||
log_error "Event retrieval failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 6: Update event"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_put "$BASE_URL/v1/events/$EVENT_ID" "{\"title\":\"Updated Event\"}" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "Updated Event"; then
|
||||
log_success "Event updated"
|
||||
else
|
||||
log_error "Event update failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 7: Delete event"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_delete "$BASE_URL/v1/events/$EVENT_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "deleted"; then
|
||||
log_success "Event deleted"
|
||||
else
|
||||
log_error "Event deletion failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 8: Get deleted event (should fail)"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_get "$BASE_URL/v1/events/$EVENT_ID" "$OWNER_TOKEN")
|
||||
if echo "$response" | grep -q "not found"; then
|
||||
log_success "Deleted event not found"
|
||||
else
|
||||
log_error "Deleted event still accessible: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 9: Create recurring event"
|
||||
log_info "============================================================"
|
||||
|
||||
response=$(http_post "$BASE_URL/v1/calendars/$CALENDAR_ID/events" \
|
||||
"{\"title\":\"Weekly Meeting\",\"start_time\":\"$EVENT_START\",\"duration\":60,\"recurrence\":{\"freq\":\"WEEKLY\",\"interval\":1}}" "$OWNER_TOKEN")
|
||||
RECURRING_ID=$(extract_json "$response" "id")
|
||||
|
||||
if [ -n "$RECURRING_ID" ]; then
|
||||
log_success "Recurring event created: $RECURRING_ID"
|
||||
else
|
||||
log_error "Recurring event creation failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_info "============================================================"
|
||||
log_info "TEST 10: Get occurrences"
|
||||
log_info "============================================================"
|
||||
|
||||
FROM="2026-06-01T00:00:00Z"
|
||||
TO="2026-06-30T00:00:00Z"
|
||||
response=$(http_get "$BASE_URL/v1/events/$RECURRING_ID/occurrences?from=$FROM&to=$TO" "$OWNER_TOKEN")
|
||||
if [ -n "$response" ] && [ "$response" != "[]" ]; then
|
||||
log_success "Occurrences retrieved"
|
||||
else
|
||||
log_error "Occurrences retrieval failed: $response"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
log_success "EVENT API TESTS COMPLETED!"
|
||||
echo "============================================================"
|
||||
Reference in New Issue
Block a user