Add comprehensive tests for CMS, Gacha, Hackathon, IAM, and User Management endpoints

- Implemented tests for Events and Testimonials endpoints in `test-cms.sh`
- Added common functions and variables for API testing in `test-common.sh`
- Created tests for Mentor endpoints in `test-mentors.sh`
- Developed tests for Gacha endpoints in `test-gacha.sh`
- Established tests for Hackathon endpoints in `test-hackathon.sh`
- Implemented tests for Authentication endpoints in `test-auth.sh`
- Added tests for Roles and Permissions endpoints in `test-roles-permissions.sh`
- Created tests for Teams endpoints in `test-teams.sh`
- Developed tests for User Management endpoints in `test-users.sh`
This commit is contained in:
MythEclipse
2025-10-24 10:38:21 +07:00
parent 3fcfb3709e
commit 1ca6d8f47c
15 changed files with 1990 additions and 1596 deletions
+97
View File
@@ -0,0 +1,97 @@
#!/bin/bash
# ==============================================================================
# CMS Tests - Events and Testimonials Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_events_endpoints() {
printf "\n${CYAN}=== Testing Events Endpoints ===${NC}\n"
# Public endpoints
test_api_endpoint "GET Events List" "GET" "/v1/cms/landing/events" 200 "" false
test_api_endpoint "GET Events (Paginated)" "GET" "/v1/cms/landing/events?page=1&limit=10" 200 "" false
test_api_endpoint "GET Events (Search)" "GET" "/v1/cms/landing/events?search=test" 200 "" false
test_api_endpoint "GET Events (Filter Online)" "GET" "/v1/cms/landing/events?filter=online" 200 "" false
# Get event by ID - use correct endpoint /detail/{id}
local events_response=$(curl -s "$BASE_URL/v1/cms/landing/events")
local test_event_id=$(echo "$events_response" | jq -r '.data[0].id // empty')
if [ -n "$test_event_id" ]; then
test_api_endpoint "GET Event By ID" "GET" "/v1/cms/landing/events/detail/$test_event_id" 200 "" false
fi
# Create event (protected) - use correct field name
local create_event_data=$(jq -n '{
name: "Test Event '$(date +%s)'",
description: "Auto-generated test event",
start_date: "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
end_date: "'$(date -u -d '+2 hours' +%Y-%m-%dT%H:%M:%SZ)'",
detail_link: "https://example.com/event",
price: 0,
is_online: true
}')
local create_event_response=$(test_api_endpoint "POST Create Event" "POST" "/v1/cms/landing/events/create" 201 "$create_event_data" true)
local created_event_id=$(echo "$create_event_response" | jq -r '.data.id // empty')
if [ -n "$created_event_id" ]; then
# Update event - use correct endpoint /update/{id} with PATCH
local update_event_data=$(jq -n '{
name: "Updated Test Event",
description: "Updated description",
is_online: false
}')
test_api_endpoint "PATCH Update Event" "PATCH" "/v1/cms/landing/events/update/$created_event_id" 200 "$update_event_data" true
# Delete event - use correct endpoint /delete/{id}
test_api_endpoint "DELETE Event" "DELETE" "/v1/cms/landing/events/delete/$created_event_id" 200 "" true
fi
}
test_testimonials_endpoints() {
printf "\n${CYAN}=== Testing Testimonials Endpoints ===${NC}\n"
# Public endpoints
test_api_endpoint "GET Testimonials List" "GET" "/v1/cms/landing/testimonials" 200 "" false
test_api_endpoint "GET Testimonials (Paginated)" "GET" "/v1/cms/landing/testimonials?page=1&limit=10" 200 "" false
test_api_endpoint "GET Testimonials (Search)" "GET" "/v1/cms/landing/testimonials?search=test" 200 "" false
# Get testimonial by ID - use correct endpoint /detail/{id}
local testimonials_response=$(curl -s "$BASE_URL/v1/cms/landing/testimonials")
local test_testimonial_id=$(echo "$testimonials_response" | jq -r '.data[0].id // empty')
if [ -n "$test_testimonial_id" ]; then
test_api_endpoint "GET Testimonial By ID" "GET" "/v1/cms/landing/testimonials/detail/$test_testimonial_id" 200 "" false
fi
# Create testimonial (protected)
local create_testimonial_data=$(jq -n '{
role: "Student",
content: "This is a test testimonial created at '$(date +%s)'"
}')
local create_testimonial_response=$(test_api_endpoint "POST Create Testimonial" "POST" "/v1/cms/landing/testimonials/create" 201 "$create_testimonial_data" true)
local created_testimonial_id=$(echo "$create_testimonial_response" | jq -r '.data.id // empty')
if [ -n "$created_testimonial_id" ]; then
# Update testimonial - use correct endpoint /update/{id} with PATCH
local update_testimonial_data=$(jq -n '{
role: "Alumni",
content: "Updated testimonial content"
}')
test_api_endpoint "PATCH Update Testimonial" "PATCH" "/v1/cms/landing/testimonials/update/$created_testimonial_id" 200 "$update_testimonial_data" true
# Delete testimonial - use correct endpoint /delete/{id}
test_api_endpoint "DELETE Testimonial" "DELETE" "/v1/cms/landing/testimonials/delete/$created_testimonial_id" 200 "" true
fi
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_events_endpoints
test_testimonials_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+176
View File
@@ -0,0 +1,176 @@
#!/bin/bash
# ==============================================================================
# Common Functions and Variables for IMPHNEN API Tests
# ==============================================================================
#!/bin/bash
# Common configuration and functions for API testing
# Colors for output
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export YELLOW='\033[1;33m'
export NC='\033[0m' # No Color
# Base configuration
export BASE_URL="${BASE_URL:-http://127.0.0.1:4099}"
export TEST_USER_EMAIL="${TEST_USER_EMAIL:-admin@example.com}"
export TEST_USER_PASSWORD="${TEST_USER_PASSWORD:-Admin@123}"
# Global variables for auth
export AUTH_TOKEN=""
export AUTH_USER_ID=""
TEST_RESULTS=()
FAILED_TESTS_SUMMARY=()
PASS_COUNT=0
FAIL_COUNT=0
# Colors
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
write_test_log() {
local level=$1
local message=$2
local color=$NC
case $level in
"SUCCESS") color=$GREEN ;;
"ERROR") color=$RED ;;
"WARN") color=$YELLOW ;;
"INFO") color=$CYAN ;;
esac
if [[ "$VERBOSE" = true || "$level" != "INFO" ]]; then
printf "[$(date +'%H:%M:%S')] [${color}%-7s${NC}] %s\n" "$level" "$message" >&2
fi
}
test_api_endpoint() {
local test_name=$1
local method=$2
local endpoint=$3
local expected_status=$4
local body=$5
local require_auth=$6
local headers=(-H "Content-Type: application/json")
if [[ "$require_auth" = true && -n "$AUTH_TOKEN" ]]; then
headers+=(-H "Authorization: Bearer $AUTH_TOKEN")
elif [[ "$require_auth" = true && -z "$AUTH_TOKEN" ]]; then
write_test_log "WARN" "$test_name - Dilewati: token autentikasi tidak tersedia"
return
fi
local start_req_time=$(date +%s%3N)
local temp_file=$(mktemp)
local status_file=$(mktemp)
curl -s -X "$method" "${headers[@]}" -d "$body" "$BASE_URL$endpoint" \
-D "$status_file" -o "$temp_file"
response_body=$(cat "$temp_file")
http_status=$(head -n 1 "$status_file" | cut -d' ' -f2)
rm -f "$temp_file" "$status_file"
local end_req_time=$(date +%s%3N)
local duration=$((end_req_time - start_req_time))
local status="FAIL"
local error_msg=""
if [[ "$http_status" =~ ^[0-9]+$ ]] && [ "$http_status" -eq "$expected_status" ]; then
status="PASS"
((PASS_COUNT++))
write_test_log "SUCCESS" "$test_name - Sukses (Status: $http_status, Waktu: ${duration}ms)"
else
status="FAIL"
((FAIL_COUNT++))
write_test_log "ERROR" " Request Body: $body"
write_test_log "ERROR" " Response Body: $response_body"
if [[ ! "$http_status" =~ ^[0-9]+$ ]]; then
error_msg="Failed to get valid HTTP status code (got: $http_status)"
else
error_msg="Status yang diharapkan $expected_status, tetapi mendapat $http_status."
fi
write_test_log "ERROR" "$test_name - Gagal: $error_msg"
FAILED_TESTS_SUMMARY+=("$test_name - $error_msg")
fi
result_json=$(jq -n --arg name "$test_name" --arg ep "$endpoint" --arg meth "$method" \
--arg stat "$status" --arg code "$http_status" --arg dur "$duration" \
--arg err "$error_msg" \
'{TestName: $name, Endpoint: $ep, Method: $meth, Status: $stat, StatusCode: $code, ResponseTimeMs: $dur, Error: $err}')
TEST_RESULTS+=("$result_json")
printf "%s" "$response_body"
}
get_auth_token() {
write_test_log "INFO" "Mengautentikasi test user..."
local login_data
login_data=$(jq -n --arg email "${TEST_EMAIL:-admin@example.com}" --arg pass "${TEST_PASSWORD:-password}" '{email: $email, password: $pass}')
local temp_file=$(mktemp)
local status_file=$(mktemp)
curl -s -X "POST" -H "Content-Type: application/json" -d "$login_data" "$BASE_URL/v1/auth/login" \
-D "$status_file" -o "$temp_file"
local response_body=$(cat "$temp_file")
local http_status=$(head -n 1 "$status_file" | cut -d' ' -f2)
rm -f "$temp_file" "$status_file"
if [[ "$http_status" =~ ^[0-9]+$ ]] && [ "$http_status" -eq 200 ]; then
if echo "$response_body" | jq . > /dev/null 2>&1; then
AUTH_TOKEN=$(echo "$response_body" | jq -r '.data.token.access_token // empty')
AUTH_USER_ID=$(echo "$response_body" | jq -r '.data.user.id // empty')
if [[ -n "$AUTH_TOKEN" && "$AUTH_TOKEN" != "null" ]]; then
write_test_log "SUCCESS" "Autentikasi berhasil"
((PASS_COUNT++))
else
write_test_log "ERROR" "Autentikasi gagal - token tidak ditemukan dalam response"
AUTH_TOKEN=""
((FAIL_COUNT++))
fi
else
write_test_log "ERROR" "Autentikasi gagal - response bukan JSON valid"
AUTH_TOKEN=""
((FAIL_COUNT++))
fi
else
write_test_log "ERROR" "Login gagal dengan status: $http_status"
AUTH_TOKEN=""
((FAIL_COUNT++))
fi
}
print_test_summary() {
local total_tests=$((PASS_COUNT + FAIL_COUNT))
local success_rate=0
if [ "$total_tests" -gt 0 ]; then
success_rate=$(( (PASS_COUNT * 100) / total_tests ))
fi
printf "\n${CYAN}=== Test Summary ===${NC}\n"
printf "Total Tests: %d\n" "$total_tests"
printf "${GREEN}Passed: %d${NC}\n" "$PASS_COUNT"
printf "${RED}Failed: %d${NC}\n" "$FAIL_COUNT"
printf "Success Rate: %d%%\n\n" "$success_rate"
if [ "$FAIL_COUNT" -gt 0 ]; then
printf "${RED}Failed Tests:${NC}\n"
for summary in "${FAILED_TESTS_SUMMARY[@]}"; do
printf " %s\n" "$summary"
done
printf "\n"
fi
}
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# ==============================================================================
# Dimentorin Tests - Mentors Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_mentor_endpoints() {
printf "\n${CYAN}=== Testing Mentor Endpoints ===${NC}\n"
# Get mentors list
test_api_endpoint "GET Mentors List" "GET" "/v1/mentors" 200 "" true
test_api_endpoint "GET Mentors (Paginated)" "GET" "/v1/mentors?page=1&limit=10" 200 "" true
test_api_endpoint "GET Mentors (Search)" "GET" "/v1/mentors?search=mentor" 200 "" true
# Get mentor by ID - use correct endpoint /detail/{id}
local mentors_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/mentors")
local test_mentor_id=$(echo "$mentors_response" | jq -r '.data[0].id // empty')
if [ -n "$test_mentor_id" ]; then
test_api_endpoint "GET Mentor By ID" "GET" "/v1/mentors/detail/$test_mentor_id" 200 "" true
# Verify mentor (admin only) - use correct endpoint /verify/{id}
local verify_data=$(jq -n '{status: "verified"}')
test_api_endpoint "PUT Verify Mentor" "PUT" "/v1/mentors/verify/$test_mentor_id" 200 "$verify_data" true
# Update mentor (admin) - use correct endpoint /update/{id}
local update_mentor_data=$(jq -n '{
expertise: ["Rust", "Backend", "DevOps"],
bio: "This is an updated mentor bio with sufficient length to meet the 50 character minimum requirement for validation"
}')
test_api_endpoint "PUT Update Mentor" "PUT" "/v1/mentors/update/$test_mentor_id" 200 "$update_mentor_data" true
fi
# Note: Mentor Me and Mentor Status endpoints require mentor-specific token
# test_api_endpoint "GET Mentor Me" "GET" "/v1/mentors/me" 200 "" true
# test_api_endpoint "GET Mentor Status" "GET" "/v1/mentors/status" 200 "" true
# Delete mentor (admin)
# test_api_endpoint "DELETE Mentor" "DELETE" "/v1/mentors/$test_mentor_id" 200 "" true
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_mentor_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+89
View File
@@ -0,0 +1,89 @@
#!/bin/bash
# Get directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common/test-common.sh"
test_gacha_endpoints() {
echo ""
echo "=== Testing Gacha Endpoints ==="
# Gacha Items - use correct endpoints /create, /detail/{id}, /update/{id}, /delete/{id}
test_api_endpoint "GET Gacha Items" "GET" "/v1/gacha/items?page=1&per_page=10" 200 "" true
test_api_endpoint "GET Gacha Items (Paginated)" "GET" "/v1/gacha/items?page=1&per_page=5" 200 "" true
# Get first gacha item ID to test detail endpoint
local items_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/gacha/items?page=1&per_page=1")
local test_item_id=$(echo "$items_response" | jq -r '.data[0].id // empty')
if [ -n "$test_item_id" ]; then
# Get item detail - use correct endpoint /detail/{id}
test_api_endpoint "GET Gacha Item By ID" "GET" "/v1/gacha/items/detail/$test_item_id" 200 "" true
fi
# Create gacha item - use correct endpoint /create
local create_item_data=$(jq -n '{
name: "Test Item '$EPOCHSECONDS'",
description: "Test gacha item",
image_url: "https://example.com/gacha-item.png",
rarity: "COMMON",
weight: 100
}')
test_api_endpoint "POST Create Gacha Item" "POST" "/v1/gacha/items/create" 201 "$create_item_data" true
# Get created item ID from response
local create_response=$(curl -s -X POST -H "Authorization: Bearer $AUTH_TOKEN" -H "Content-Type: application/json" -d "$create_item_data" "$BASE_URL/v1/gacha/items/create")
local created_item_id=$(echo "$create_response" | jq -r '.data.id // empty')
if [ -n "$created_item_id" ]; then
# Update gacha item - use correct endpoint /update/{id}
local update_item_data=$(jq -n '{
name: "Updated Test Item",
description: "Updated description",
image_url: "https://example.com/updated-gacha-item.png",
rarity: "RARE",
weight: 50
}')
test_api_endpoint "PUT Update Gacha Item" "PUT" "/v1/gacha/items/update/$created_item_id" 200 "$update_item_data" true
# Delete gacha item - use correct endpoint /delete/{id}
test_api_endpoint "DELETE Gacha Item" "DELETE" "/v1/gacha/items/delete/$created_item_id" 200 "" true
fi
# Gacha Rolls - need to get an existing item first
local items_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/gacha/items?page=1&per_page=1")
local test_item_id=$(echo "$items_response" | jq -r '.data[0].id // empty')
if [ -n "$test_item_id" ]; then
# Create gacha roll with item_id - use correct endpoint /create
local create_roll_data=$(jq -n --arg item_id "$test_item_id" '{item_id: $item_id, weight: 1.0, quantity: 1}')
test_api_endpoint "POST Create Gacha Roll" "POST" "/v1/gacha/rolls/create" 201 "$create_roll_data" true
# Get roll ID to execute it
local create_roll_response=$(curl -s -X POST -H "Authorization: Bearer $AUTH_TOKEN" -H "Content-Type: application/json" -d "$create_roll_data" "$BASE_URL/v1/gacha/rolls/create")
local roll_id=$(echo "$create_roll_response" | jq -r '.data.id // empty')
if [ -n "$roll_id" ]; then
test_api_endpoint "POST Execute Gacha Roll" "POST" "/v1/gacha/rolls/execute" 200 "{\"roll_id\": \"$roll_id\"}" true
fi
fi
# Gacha Credits
# Note: These endpoints may require special permissions or internal access
# test_api_endpoint "GET User Credits" "GET" "/v1/gacha/credits" 200 "" true
# local add_credits_data=$(jq -n '{amount: 100}')
# test_api_endpoint "POST Add Credits" "POST" "/v1/gacha/credits/add" 200 "$add_credits_data" true
# local consume_credits_data=$(jq -n '{amount: 1}')
# test_api_endpoint "POST Consume Credits" "POST" "/v1/gacha/credits/consume" 200 "$consume_credits_data" true
# Gacha Claims
# test_api_endpoint "POST Create Gacha Claim" "POST" "/v1/gacha/claims" 201 "{}" true
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_gacha_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+116
View File
@@ -0,0 +1,116 @@
#!/bin/bash
# ==============================================================================
# Hackathon Tests - Comprehensive Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_hackathon_endpoints() {
printf "\n${CYAN}=== Testing Hackathon Endpoints ===${NC}\n"
# Get hackathons
test_api_endpoint "GET Hackathons" "GET" "/v1/hackathons" 200 "" false
test_api_endpoint "GET Hackathons (Paginated)" "GET" "/v1/hackathons?page=1&limit=10" 200 "" false
# Create hackathon - add organizers field (required)
local create_hackathon_data=$(jq -n --arg user_id "$AUTH_USER_ID" '{
name: "Test Hackathon '$(date +%s)'",
description: "Auto-generated test hackathon",
start_date: "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
end_date: "'$(date -u -d '+7 days' +%Y-%m-%dT%H:%M:%SZ)'",
registration_deadline: "'$(date -u -d '+1 day' +%Y-%m-%dT%H:%M:%SZ)'",
max_participants: 100,
theme: "Technology",
rules: "Follow the rules",
prizes: [
{position: 1, title: "Grand Prize", description: "First place", value: "$1000"},
{position: 2, title: "Runner Up", description: "Second place", value: "$500"}
],
organizers: [$user_id]
}')
local create_hackathon_response=$(test_api_endpoint "POST Create Hackathon" "POST" "/v1/hackathons" 201 "$create_hackathon_data" true)
local created_hackathon_id=$(echo "$create_hackathon_response" | jq -r '.data.id // empty')
if [ -n "$created_hackathon_id" ]; then
# Get hackathon by ID
test_api_endpoint "GET Hackathon By ID" "GET" "/v1/hackathons/$created_hackathon_id" 200 "" false
# Update hackathon
local update_hackathon_data=$(jq -n '{
title: "Updated Test Hackathon",
description: "Updated description",
max_teams: 150
}')
test_api_endpoint "PUT Update Hackathon" "PUT" "/v1/hackathons/$created_hackathon_id" 200 "$update_hackathon_data" true
# === Hackathon Events ===
local create_event_data=$(jq -n --arg hackathon_id "$created_hackathon_id" '{
hackathon_id: $hackathon_id,
title: "Kickoff Meeting",
description: "Opening ceremony and team formation",
event_date: "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
location: "Online - Zoom",
is_mandatory: true
}')
local create_event_response=$(test_api_endpoint "POST Create Hackathon Event" "POST" "/v1/hackathons/$created_hackathon_id/events" 201 "$create_event_data" true)
local created_event_id=$(echo "$create_event_response" | jq -r '.data.id // empty')
if [ -n "$created_event_id" ]; then
# Update event
local update_event_data=$(jq -n '{
title: "Updated Kickoff Meeting",
description: "Updated description",
is_mandatory: false
}')
test_api_endpoint "PUT Update Hackathon Event" "PUT" "/v1/hackathons/events/$created_event_id" 200 "$update_event_data" true
# Delete event
test_api_endpoint "DELETE Hackathon Event" "DELETE" "/v1/hackathons/events/$created_event_id" 200 "" true
fi
# === Hackathon Timeline ===
local create_timeline_data=$(jq -n --arg hackathon_id "$created_hackathon_id" '{
hackathon_id: $hackathon_id,
phase_name: "Registration Phase",
description: "Team registration and formation",
start_date: "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
end_date: "'$(date -u -d '+2 days' +%Y-%m-%dT%H:%M:%SZ)'",
allowed_operations: ["REGISTER", "FORM_TEAM"]
}')
local create_timeline_response=$(test_api_endpoint "POST Create Timeline" "POST" "/v1/hackathons/$created_hackathon_id/timeline" 201 "$create_timeline_data" true)
local created_timeline_id=$(echo "$create_timeline_response" | jq -r '.data.id // empty')
if [ -n "$created_timeline_id" ]; then
# Update timeline
local update_timeline_data=$(jq -n '{
phase_name: "Updated Registration Phase",
description: "Updated description"
}')
test_api_endpoint "PUT Update Timeline" "PUT" "/v1/hackathons/timeline/$created_timeline_id" 200 "$update_timeline_data" true
# Delete timeline
test_api_endpoint "DELETE Timeline" "DELETE" "/v1/hackathons/timeline/$created_timeline_id" 200 "" true
fi
# === Hackathon Submissions ===
# Note: Submissions require team participation
# test_api_endpoint "GET Hackathon Submissions" "GET" "/v1/hackathons/$created_hackathon_id/submissions" 200 "" true
# test_api_endpoint "GET My Submissions" "GET" "/v1/hackathons/submissions/me" 200 "" true
# === Hackathon Results ===
# test_api_endpoint "GET Admin Results" "GET" "/v1/hackathons/$created_hackathon_id/results" 200 "" true
# test_api_endpoint "GET Public Results" "GET" "/v1/hackathons/$created_hackathon_id/results/public" 200 "" false
# Delete hackathon
test_api_endpoint "DELETE Hackathon" "DELETE" "/v1/hackathons/$created_hackathon_id" 200 "" true
fi
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_hackathon_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash
# ==============================================================================
# IAM Tests - Authentication Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_authentication_endpoints() {
printf "\n${CYAN}=== Testing Authentication Endpoints ===${NC}\n"
# Valid login
get_auth_token
# Invalid login
local invalid_login
invalid_login=$(jq -n '{email: "invalid@example.com", password: "wrongpassword"}')
test_api_endpoint "Invalid Login Test" "POST" "/v1/auth/login" 401 "$invalid_login"
# Mentor login
local mentor_login=$(jq -n '{email: "mentor@example.com", password: "password"}')
test_api_endpoint "Mentor Login" "POST" "/v1/auth/login-mentor" 200 "$mentor_login" false
# Forgot password
local forgot_password_data
forgot_password_data=$(jq -n --arg email "admin@example.com" '{email: $email}')
test_api_endpoint "Forgot Password Test" "POST" "/v1/auth/forgot" 200 "$forgot_password_data"
# Invalid new password (invalid token)
local new_password_data
new_password_data=$(jq -n --arg token "some_reset_token" --arg pass "newpassword123!A" '{token: $token, password: $pass}')
test_api_endpoint "New Password Test (Invalid Token)" "POST" "/v1/auth/new-password" 400 "$new_password_data"
# Refresh token
local refresh_token=$(curl -s -X POST -H "Content-Type: application/json" \
-d "$(jq -n '{email: "admin@example.com", password: "password"}')" \
"$BASE_URL/v1/auth/login" | jq -r '.data.token.refresh_token // empty')
if [ -n "$refresh_token" ]; then
local refresh_data
refresh_data=$(jq -n --arg token "$refresh_token" '{refresh_token: $token}')
test_api_endpoint "Refresh Token Test" "POST" "/v1/auth/refresh" 200 "$refresh_data"
else
write_test_log "WARN" "✗ Refresh Token Test - Dilewati: Refresh token tidak tersedia dari login"
fi
# Resend OTP
local resend_data=$(jq -n '{email: "admin@example.com"}')
test_api_endpoint "Resend OTP" "POST" "/v1/auth/send-otp" 200 "$resend_data" false
# Logout (skip - endpoint may not exist)
# test_api_endpoint "Logout" "POST" "/v1/auth/logout" 200 "" true
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_authentication_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+77
View File
@@ -0,0 +1,77 @@
#!/bin/bash
# ==============================================================================
# IAM Tests - Roles and Permissions Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_roles_and_permissions() {
printf "\n${CYAN}=== Testing Roles and Permissions Endpoints ===${NC}\n"
# Roles
test_api_endpoint "GET Roles List" "GET" "/v1/roles" 200 "" true
test_api_endpoint "GET Roles (Paginated)" "GET" "/v1/roles?page=1&limit=10" 200 "" true
# Get role by ID - use correct endpoint /detail/{id}
local test_role_id="5713cb37-dc02-4e87-8048-d7a41d352059"
test_api_endpoint "GET Role By ID" "GET" "/v1/roles/detail/$test_role_id" 200 "" true
# Create role - use correct endpoint /create
local create_role_data=$(jq -n '{
name: "Test Role '$(date +%s)'",
description: "Auto-generated test role",
permissions: []
}')
local create_role_response=$(test_api_endpoint "POST Create Role" "POST" "/v1/roles/create" 201 "$create_role_data" true)
local created_role_id=$(echo "$create_role_response" | jq -r '.data.id // empty')
if [ -n "$created_role_id" ]; then
# Update role - use correct endpoint /update/{id}
local update_role_data=$(jq -n --arg ts "$EPOCHSECONDS" '{
name: ("Updated Test Role " + $ts),
description: "Updated description",
permissions: []
}')
test_api_endpoint "PUT Update Role" "PUT" "/v1/roles/update/$created_role_id" 200 "$update_role_data" true
# Delete role - use correct endpoint /delete/{id}
test_api_endpoint "DELETE Role" "DELETE" "/v1/roles/delete/$created_role_id" 200 "" true
fi
# Permissions
test_api_endpoint "GET Permissions List" "GET" "/v1/permissions" 200 "" true
test_api_endpoint "GET Permissions (Paginated)" "GET" "/v1/permissions?page=1&limit=10" 200 "" true
# Get permission by ID - use correct endpoint /detail/{id}
local test_perm_id="023e2dfe-93c3-4008-94a8-b5dff403f73b"
test_api_endpoint "GET Permission By ID" "GET" "/v1/permissions/detail/$test_perm_id" 200 "" true
# Create permission - use correct endpoint /create
local create_perm_data=$(jq -n '{
name: "Test Permission '$(date +%s)'",
description: "Auto-generated test permission"
}')
local create_perm_response=$(test_api_endpoint "POST Create Permission" "POST" "/v1/permissions/create" 201 "$create_perm_data" true)
local created_perm_id=$(echo "$create_perm_response" | jq -r '.data.id // empty')
if [ -n "$created_perm_id" ]; then
# Update permission - use correct endpoint /update/{id}
local update_perm_data=$(jq -n '{
name: "Updated Test Permission",
description: "Updated description"
}')
test_api_endpoint "PUT Update Permission" "PUT" "/v1/permissions/update/$created_perm_id" 200 "$update_perm_data" true
# Delete permission - use correct endpoint /delete/{id}
test_api_endpoint "DELETE Permission" "DELETE" "/v1/permissions/delete/$created_perm_id" 200 "" true
fi
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_roles_and_permissions
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+73
View File
@@ -0,0 +1,73 @@
#!/bin/bash
# ==============================================================================
# IAM Tests - Teams Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_team_endpoints() {
printf "\n${CYAN}=== Testing Team Endpoints ===${NC}\n"
# Public endpoints (skip - may require auth)
# test_api_endpoint "GET Public Teams" "GET" "/v1/teams" 200 "" false
# test_api_endpoint "GET Public Teams (Search)" "GET" "/v1/teams?search=dev" 200 "" false
# test_api_endpoint "GET Teams Search" "GET" "/v1/teams/search?query=development" 200 "" false
# Admin endpoints
test_api_endpoint "GET Admin Teams" "GET" "/v1/teams/admin" 200 "" true
test_api_endpoint "GET Admin Teams (Paginated)" "GET" "/v1/teams/admin?page=1&limit=10" 200 "" true
# Get team by ID (skip - test team may not exist)
# local test_team_id="team-001"
# test_api_endpoint "GET Team By ID" "GET" "/v1/teams/admin/$test_team_id" 200 "" true
# Test with dynamic team from list
local teams_response=$(curl -s -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/v1/teams/admin")
local test_team_id=$(echo "$teams_response" | jq -r '.data[0].id // empty')
if [ -n "$test_team_id" ]; then
test_api_endpoint "GET Team By ID" "GET" "/v1/teams/admin/$test_team_id" 200 "" true
test_api_endpoint "GET Team Members" "GET" "/v1/teams/admin/$test_team_id/members" 200 "" true
fi
# Create team
local create_team_data=$(jq -n '{
name: "Test Team '$(date +%s)'",
description: "Auto-generated test team",
is_open: true,
max_members: 5,
skills_required: ["Rust", "Testing"],
location: "Remote"
}')
local create_team_response=$(test_api_endpoint "POST Create Team" "POST" "/v1/teams/admin" 201 "$create_team_data" true)
local created_team_id=$(echo "$create_team_response" | jq -r '.data.id // empty')
if [ -n "$created_team_id" ]; then
# Update team
local update_team_data=$(jq -n '{
name: "Updated Test Team",
description: "Updated description",
is_open: false,
max_members: 10
}')
test_api_endpoint "PUT Update Team" "PUT" "/v1/teams/admin/$created_team_id" 200 "$update_team_data" true
# Invite members
local invite_data=$(jq -n '{
user_ids: ["c3b1d6a8-8d4f-4b36-b789-2e532ec7a7b2"]
}')
test_api_endpoint "POST Invite Members" "POST" "/v1/teams/admin/$created_team_id/invite" 200 "$invite_data" true
# Delete team
test_api_endpoint "DELETE Team" "DELETE" "/v1/teams/admin/$created_team_id" 200 "" true
fi
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_team_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi
+90
View File
@@ -0,0 +1,90 @@
#!/bin/bash
# ==============================================================================
# IAM Tests - User Management Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_user_management_endpoints() {
printf "\n${CYAN}=== Testing User Management Endpoints ===${NC}\n"
# Get users list
test_api_endpoint "GET Users List" "GET" "/v1/users" 200 "" true
test_api_endpoint "GET Users (Paginated)" "GET" "/v1/users?page=1&limit=10" 200 "" true
test_api_endpoint "GET Users (Search)" "GET" "/v1/users?search=admin" 200 "" true
test_api_endpoint "GET Users (Sorted)" "GET" "/v1/users?sort_by=created_at&order=DESC" 200 "" true
# Get user me
test_api_endpoint "GET User Me" "GET" "/v1/users/me" 200 "" true
# Update user me - use correct endpoint /update/me
local update_me_data=$(jq -n '{
fullname: "Updated Admin User",
phone_number: "081234567890",
gender: "male",
birthdate: "1990-01-01"
}')
test_api_endpoint "PUT User Me" "PUT" "/v1/users/update/me" 200 "$update_me_data" true
# Get user by ID
local test_user_id="c3b1d6a8-8d4f-4b36-b789-2e532ec7a7b2"
test_api_endpoint "GET User By ID" "GET" "/v1/users/detail/$test_user_id" 200 "" true
# Create new user
local new_user_email="test_user_$(date +%s)@example.com"
local create_user_data=$(jq -n \
--arg email "$new_user_email" \
--arg pass "TestPassword123!" \
--arg fullname "Test User $(date +%s)" \
--arg phone "089876543211" \
'{
email: $email,
password: $pass,
fullname: $fullname,
phone_number: $phone,
is_active: true,
role_id: "5713cb37-dc02-4e87-8048-d7a41d352059"
}')
local create_response=$(test_api_endpoint "POST Create User" "POST" "/v1/users/create" 201 "$create_user_data" true)
local created_user_id=$(echo "$create_response" | jq -r '.data.id // empty')
if [ -n "$created_user_id" ]; then
# Update user
local update_user_data=$(jq -n \
--arg email "updated_$new_user_email" \
--arg fullname "Updated Test User" \
'{
email: $email,
fullname: $fullname,
phone_number: "089876543212",
is_active: true,
gender: "Female",
birthdate: "1995-05-15",
role_id: "5713cb37-dc02-4e87-8048-d7a41d352059"
}')
test_api_endpoint "PUT Update User" "PUT" "/v1/users/update/$created_user_id" 200 "$update_user_data" true
# Deactivate user - endpoint uses PUT, not PATCH
local deactivate_data=$(jq -n '{is_active: false}')
test_api_endpoint "PUT Deactivate User" "PUT" "/v1/users/activate/$created_user_id" 200 "$deactivate_data" true
# Reactivate user - endpoint uses PUT, not PATCH
local reactivate_data=$(jq -n '{is_active: true}')
test_api_endpoint "PUT Reactivate User" "PUT" "/v1/users/activate/$created_user_id" 200 "$reactivate_data" true
# Delete user
test_api_endpoint "DELETE User" "DELETE" "/v1/users/delete/$created_user_id" 200 "" true
else
write_test_log "WARN" "Skipping user update/delete tests - failed to create user"
fi
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_user_management_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi