Initial commit: API Wipay dengan fix CORS untuk GET request
This commit is contained in:
92
test_api.sh
Normal file
92
test_api.sh
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script untuk test API Timo Wipay
|
||||
# Usage: ./test_api.sh
|
||||
|
||||
BASE_URL="http://localhost:8000"
|
||||
COLOR_GREEN='\033[0;32m'
|
||||
COLOR_RED='\033[0;31m'
|
||||
COLOR_YELLOW='\033[1;33m'
|
||||
COLOR_NC='\033[0m' # No Color
|
||||
|
||||
echo "=========================================="
|
||||
echo " Timo Wipay API Testing Script"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Test Health Check
|
||||
echo -e "${COLOR_YELLOW}1. Testing Health Check...${COLOR_NC}"
|
||||
HEALTH_RESPONSE=$(curl -s "$BASE_URL/health")
|
||||
if [ "$HEALTH_RESPONSE" == "OK" ]; then
|
||||
echo -e "${COLOR_GREEN}✓ Health Check: OK${COLOR_NC}"
|
||||
else
|
||||
echo -e "${COLOR_RED}✗ Health Check: FAILED${COLOR_NC}"
|
||||
echo "Response: $HEALTH_RESPONSE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test Root Endpoint
|
||||
echo -e "${COLOR_YELLOW}2. Testing Root Endpoint...${COLOR_NC}"
|
||||
ROOT_RESPONSE=$(curl -s "$BASE_URL/")
|
||||
if [[ "$ROOT_RESPONSE" == *"Welcome"* ]]; then
|
||||
echo -e "${COLOR_GREEN}✓ Root Endpoint: OK${COLOR_NC}"
|
||||
else
|
||||
echo -e "${COLOR_RED}✗ Root Endpoint: FAILED${COLOR_NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test Login (dengan data dummy)
|
||||
echo -e "${COLOR_YELLOW}3. Testing Login Endpoint...${COLOR_NC}"
|
||||
LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/timo/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"test","password":"test"}')
|
||||
|
||||
if echo "$LOGIN_RESPONSE" | grep -q '"status"'; then
|
||||
echo -e "${COLOR_GREEN}✓ Login Endpoint: Response format OK${COLOR_NC}"
|
||||
echo "Response: $LOGIN_RESPONSE" | head -c 200
|
||||
echo "..."
|
||||
else
|
||||
echo -e "${COLOR_RED}✗ Login Endpoint: Invalid response${COLOR_NC}"
|
||||
echo "Response: $LOGIN_RESPONSE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test Cek SL (dengan data dummy)
|
||||
echo -e "${COLOR_YELLOW}4. Testing Cek SL Endpoint...${COLOR_NC}"
|
||||
CEK_SL_RESPONSE=$(curl -s -X POST "$BASE_URL/timo/cek_sl" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"token":"1","no_sl":"123456"}')
|
||||
|
||||
if echo "$CEK_SL_RESPONSE" | grep -q '"status"'; then
|
||||
echo -e "${COLOR_GREEN}✓ Cek SL Endpoint: Response format OK${COLOR_NC}"
|
||||
echo "Response: $CEK_SL_RESPONSE" | head -c 200
|
||||
echo "..."
|
||||
else
|
||||
echo -e "${COLOR_RED}✗ Cek SL Endpoint: Invalid response${COLOR_NC}"
|
||||
echo "Response: $CEK_SL_RESPONSE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test Jenis Laporan (tidak perlu token)
|
||||
echo -e "${COLOR_YELLOW}5. Testing Jenis Laporan Endpoint...${COLOR_NC}"
|
||||
JENIS_LAPORAN_RESPONSE=$(curl -s -X POST "$BASE_URL/timo/jenis_laporan" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}')
|
||||
|
||||
if echo "$JENIS_LAPORAN_RESPONSE" | grep -q '"status"'; then
|
||||
echo -e "${COLOR_GREEN}✓ Jenis Laporan Endpoint: Response format OK${COLOR_NC}"
|
||||
echo "Response: $JENIS_LAPORAN_RESPONSE" | head -c 200
|
||||
echo "..."
|
||||
else
|
||||
echo -e "${COLOR_RED}✗ Jenis Laporan Endpoint: Invalid response${COLOR_NC}"
|
||||
echo "Response: $JENIS_LAPORAN_RESPONSE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo " Testing Complete!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Note: Untuk test lengkap dengan data real,"
|
||||
echo " gunakan Postman atau aplikasi mobile"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user