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
+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