tahamajs/IE / Projects /scripts /test-api.sh
tahamajs's picture
download
raw
4.17 kB
#!/bin/bash
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
BOLD='\033[1m'
BASE_URL="http://localhost:9092/api"
echo -e "${BOLD}${GREEN}════════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD}${GREEN} IE Research Platform - API Test Suite${NC}"
echo -e "${BOLD}${GREEN}════════════════════════════════════════════════════════════${NC}\n"
# 1. Register new user
echo -e "${BLUE}📝 1. Registering new user...${NC}"
REGISTER_RESPONSE=$(curl -s -X POST "$BASE_URL/auth/register" \
-H "Content-Type: application/json" \
-d '{"username":"apitest","password":"apitest123","email":"apitest@example.com"}')
echo "$REGISTER_RESPONSE" | jq '.'
echo ""
# 2. Login
echo -e "${BLUE}🔐 2. Logging in...${NC}"
LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"apitest","password":"apitest123"}')
echo "$LOGIN_RESPONSE" | jq '.'
TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.token')
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo -e "${YELLOW}⚠️ Login failed, trying with existing user...${NC}"
LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"newuser123","password":"password123"}')
TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.token')
fi
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then
echo -e "${GREEN}✅ Login successful!${NC}\n"
# 3. Get collections
echo -e "${BLUE}📁 3. Getting collections...${NC}"
curl -s -X GET "$BASE_URL/collections" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '.'
echo ""
# 4. Create collection
echo -e "${BLUE}➕ 4. Creating new collection...${NC}"
curl -s -X POST "$BASE_URL/collections" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"My Research Papers","description":"Important research papers","isPublic":false}' | jq '.'
echo ""
# 5. Get all collections again
echo -e "${BLUE}📁 5. Getting updated collections...${NC}"
curl -s -X GET "$BASE_URL/collections" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '.'
echo ""
# 6. Get articles
echo -e "${BLUE}📄 6. Getting articles...${NC}"
curl -s -X GET "$BASE_URL/articles" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '.[] | {id, title, authorUsername, likesCount}'
echo ""
# 7. Get single article
echo -e "${BLUE}📖 7. Getting single article (ID: 5)...${NC}"
curl -s -X GET "$BASE_URL/articles/5" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '{id, title, authorUsername, body: .body[0:100]}'
echo ""
# 8. Get user profile
echo -e "${BLUE}👤 8. Getting user profile...${NC}"
curl -s -X GET "$BASE_URL/auth/me" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '.'
echo ""
# 9. Get trending tags
echo -e "${BLUE}🏷️ 9. Getting trending tags...${NC}"
curl -s -X GET "$BASE_URL/tags/trending" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" 2>/dev/null | jq '.' || echo "Not implemented yet"
echo ""
else
echo -e "${YELLOW}❌ Could not authenticate${NC}"
fi
echo -e "${BOLD}${GREEN}════════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD}${GREEN} Test Completed!${NC}"
echo -e "${BOLD}${GREEN}════════════════════════════════════════════════════════════${NC}"

Xet Storage Details

Size:
4.17 kB
·
Xet hash:
be1711f9a26ebda2afe3a45046c29299a3dc656eb940b3356f6e849529ebfc27

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.