-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gamifier-app.sh
More file actions
executable file
Β·906 lines (741 loc) Β· 28.8 KB
/
test-gamifier-app.sh
File metadata and controls
executable file
Β·906 lines (741 loc) Β· 28.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
#!/bin/bash
# =============================================================================
# Starfleet Gamifier Application Testing Script
# =============================================================================
# This script tests the complete Starfleet Gamifier application including
# frontend Angular components and backend Spring Boot API endpoints.
#
# Prerequisites:
# - Angular CLI installed (npm install -g @angular/cli)
# - Node.js and npm installed
# - Java 17+ and Maven installed
# - MongoDB running (or MongoDB Atlas connection)
# - Chrome/Chromium browser with DevTools support
#
# Usage:
# chmod +x test-gamifier-app.sh
# ./test-gamifier-app.sh
# =============================================================================
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
FRONTEND_URL="http://localhost:4200"
BACKEND_URL="http://localhost:9080"
FRONTEND_DIR="frontend/gamifier-ui"
BACKEND_PORT=9080
FRONTEND_PORT=4200
# Logging
LOG_FILE="test-results-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$LOG_FILE")
exec 2>&1
echo -e "${CYAN}==============================================================================${NC}"
echo -e "${CYAN}π STARFLEET GAMIFIER APPLICATION TESTING SCRIPT${NC}"
echo -e "${CYAN}==============================================================================${NC}"
echo "Test started at: $(date)"
echo "Logging to: $LOG_FILE"
echo ""
# =============================================================================
# Helper Functions
# =============================================================================
print_section() {
echo -e "\n${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}π $1${NC}"
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
}
print_test() {
echo -e "${PURPLE}π Testing: $1${NC}"
}
print_success() {
echo -e "${GREEN}β
PASS: $1${NC}"
}
print_failure() {
echo -e "${RED}β FAIL: $1${NC}"
}
print_warning() {
echo -e "${YELLOW}β οΈ WARN: $1${NC}"
}
print_info() {
echo -e "${CYAN}βΉοΈ INFO: $1${NC}"
}
check_url_accessible() {
local url=$1
local description=$2
local timeout=${3:-10}
print_test "$description"
if curl -s --connect-timeout $timeout --max-time $timeout "$url" > /dev/null 2>&1; then
print_success "$description is accessible"
return 0
else
print_failure "$description is not accessible at $url"
return 1
fi
}
check_api_endpoint() {
local endpoint=$1
local description=$2
local expected_status=${3:-200}
print_test "$description"
local response=$(curl -s -w "%{http_code}" -o /tmp/api_response.json "$BACKEND_URL$endpoint" 2>/dev/null)
local status_code=$(echo "$response" | tail -n1)
if [ "$status_code" = "$expected_status" ]; then
print_success "$description (HTTP $status_code)"
if [ -f /tmp/api_response.json ]; then
echo "Response preview: $(head -c 200 /tmp/api_response.json)..."
fi
return 0
else
print_failure "$description (Expected HTTP $expected_status, got HTTP $status_code)"
return 1
fi
}
check_process_running() {
local process_name=$1
local port=$2
if lsof -i :$port > /dev/null 2>&1; then
print_success "$process_name is running on port $port"
return 0
else
print_failure "$process_name is not running on port $port"
return 1
fi
}
# =============================================================================
# Test Results Tracking
# =============================================================================
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
record_test_result() {
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if [ $1 -eq 0 ]; then
PASSED_TESTS=$((PASSED_TESTS + 1))
else
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
}
# =============================================================================
# Pre-flight Checks
# =============================================================================
print_section "PRE-FLIGHT SYSTEM CHECKS"
# Check required tools
print_test "Checking required tools"
missing_tools=()
if ! command -v node &> /dev/null; then
missing_tools+=("node")
fi
if ! command -v npm &> /dev/null; then
missing_tools+=("npm")
fi
if ! command -v ng &> /dev/null; then
missing_tools+=("@angular/cli")
fi
if ! command -v java &> /dev/null; then
missing_tools+=("java")
fi
if ! command -v mvn &> /dev/null; then
missing_tools+=("maven")
fi
if ! command -v curl &> /dev/null; then
missing_tools+=("curl")
fi
if [ ${#missing_tools[@]} -eq 0 ]; then
print_success "All required tools are installed"
record_test_result 0
else
print_failure "Missing tools: ${missing_tools[*]}"
print_info "Please install missing tools and try again"
record_test_result 1
fi
# Check versions
print_info "Node.js version: $(node --version)"
print_info "npm version: $(npm --version)"
print_info "Angular CLI version: $(ng version --version 2>/dev/null || echo 'Not available')"
print_info "Java version: $(java -version 2>&1 | head -n1)"
print_info "Maven version: $(mvn --version 2>/dev/null | head -n1)"
# =============================================================================
# Application Status Checks
# =============================================================================
print_section "APPLICATION STATUS CHECKS"
# Check if processes are running
check_process_running "Frontend (Angular)" $FRONTEND_PORT
record_test_result $?
check_process_running "Backend (Spring Boot)" $BACKEND_PORT
record_test_result $?
# Check application accessibility
check_url_accessible "$FRONTEND_URL" "Frontend application"
record_test_result $?
check_url_accessible "$BACKEND_URL/actuator/health" "Backend health endpoint"
record_test_result $?
# =============================================================================
# Backend API Testing
# =============================================================================
print_section "BACKEND API ENDPOINT TESTING"
# Test core API endpoints
check_api_endpoint "/api/users" "Users API endpoint"
record_test_result $?
check_api_endpoint "/api/users/current" "Current user endpoint" 404
record_test_result $?
check_api_endpoint "/api/actions" "Actions API endpoint"
record_test_result $?
check_api_endpoint "/api/organization" "Organization API endpoint"
record_test_result $?
check_api_endpoint "/api/leaderboard" "Leaderboard API endpoint"
record_test_result $?
# Test actuator endpoints
check_api_endpoint "/actuator/health" "Health check endpoint"
record_test_result $?
check_api_endpoint "/actuator/info" "Info endpoint"
record_test_result $?
# =============================================================================
# Frontend Component Testing
# =============================================================================
print_section "FRONTEND COMPONENT TESTING"
# Test if we can reach different routes (basic connectivity test)
frontend_routes=(
"" # Dashboard
"/actions" # Actions
"/missions" # Missions
"/leaderboards" # Leaderboards
"/admin/organization" # Admin Organization
"/admin/users" # Admin Users
"/admin/reports" # Admin Reports
)
for route in "${frontend_routes[@]}"; do
route_name=$(echo "$route" | sed 's|^/||' | sed 's|/| |g' | tr '[:lower:]' '[:upper:]')
if [ -z "$route_name" ]; then
route_name="DASHBOARD"
fi
check_url_accessible "${FRONTEND_URL}${route}" "Frontend route: $route_name"
record_test_result $?
done
# =============================================================================
# Integration Testing
# =============================================================================
print_section "INTEGRATION TESTING"
print_test "Testing API integration with CORS"
if curl -s -H "Origin: $FRONTEND_URL" \
-H "Access-Control-Request-Method: GET" \
-H "Access-Control-Request-Headers: Content-Type" \
-X OPTIONS "$BACKEND_URL/api/users" | grep -q "Access-Control-Allow-Origin"; then
print_success "CORS is properly configured"
record_test_result 0
else
print_warning "CORS configuration may need attention"
record_test_result 1
fi
print_test "Testing MongoDB connection through API"
response=$(curl -s "$BACKEND_URL/api/organization")
if echo "$response" | grep -q "id\|name\|federationId"; then
print_success "MongoDB connection is working (organization data found)"
record_test_result 0
else
print_failure "MongoDB connection may be failing (no organization data)"
record_test_result 1
fi
# =============================================================================
# Security Testing
# =============================================================================
print_section "BASIC SECURITY TESTING"
print_test "Testing for sensitive information exposure"
sensitive_endpoints=(
"/actuator/env"
"/actuator/configprops"
"/actuator/beans"
)
for endpoint in "${sensitive_endpoints[@]}"; do
response_code=$(curl -s -w "%{http_code}" -o /dev/null "$BACKEND_URL$endpoint")
if [ "$response_code" = "404" ] || [ "$response_code" = "401" ] || [ "$response_code" = "403" ]; then
print_success "Sensitive endpoint $endpoint is protected (HTTP $response_code)"
record_test_result 0
else
print_warning "Sensitive endpoint $endpoint may be exposed (HTTP $response_code)"
record_test_result 1
fi
done
# =============================================================================
# Performance Testing
# =============================================================================
print_section "BASIC PERFORMANCE TESTING"
print_test "Testing frontend load time"
start_time=$(date +%s%N)
curl -s "$FRONTEND_URL" > /dev/null
end_time=$(date +%s%N)
load_time=$(( (end_time - start_time) / 1000000 ))
if [ $load_time -lt 2000 ]; then
print_success "Frontend loads quickly (${load_time}ms)"
record_test_result 0
elif [ $load_time -lt 5000 ]; then
print_warning "Frontend load time is acceptable (${load_time}ms)"
record_test_result 0
else
print_failure "Frontend load time is slow (${load_time}ms)"
record_test_result 1
fi
print_test "Testing API response time"
start_time=$(date +%s%N)
curl -s "$BACKEND_URL/api/users" > /dev/null
end_time=$(date +%s%N)
api_time=$(( (end_time - start_time) / 1000000 ))
if [ $api_time -lt 1000 ]; then
print_success "API responds quickly (${api_time}ms)"
record_test_result 0
elif [ $api_time -lt 3000 ]; then
print_warning "API response time is acceptable (${api_time}ms)"
record_test_result 0
else
print_failure "API response time is slow (${api_time}ms)"
record_test_result 1
fi
# =============================================================================
# Browser Testing Commands
# =============================================================================
print_section "BROWSER TESTING COMMANDS"
print_info "To test the application manually in your browser:"
echo ""
echo -e "${CYAN}Frontend URLs to test:${NC}"
echo " π Dashboard: $FRONTEND_URL"
echo " β‘ Actions: $FRONTEND_URL/actions"
echo " π― Missions: $FRONTEND_URL/missions"
echo " π Leaderboards: $FRONTEND_URL/leaderboards"
echo " π§ Admin Organization: $FRONTEND_URL/admin/organization"
echo " π₯ Admin Users: $FRONTEND_URL/admin/users"
echo " π Admin Reports: $FRONTEND_URL/admin/reports"
echo ""
echo -e "${CYAN}Backend API URLs to test:${NC}"
echo " π Users API: $BACKEND_URL/api/users"
echo " β‘ Actions API: $BACKEND_URL/api/actions"
echo " π’ Organization API: $BACKEND_URL/api/organization"
echo " π Leaderboard API: $BACKEND_URL/api/leaderboard"
echo " π Health Check: $BACKEND_URL/actuator/health"
echo ""
# =============================================================================
# Browser Console Error Check Script
# =============================================================================
cat > browser-console-check.js << 'EOF'
// Starfleet Gamifier Browser Console Error Check
// Run this script in your browser's DevTools console to check for errors
console.log('π Starting Starfleet Gamifier Browser Console Check...');
// Store original console methods
const originalError = console.error;
const originalWarn = console.warn;
// Track errors and warnings
let errors = [];
let warnings = [];
// Override console methods to capture logs
console.error = function(...args) {
errors.push({
timestamp: new Date().toISOString(),
message: args.join(' '),
stack: new Error().stack
});
originalError.apply(console, args);
};
console.warn = function(...args) {
warnings.push({
timestamp: new Date().toISOString(),
message: args.join(' ')
});
originalWarn.apply(console, args);
};
// Test navigation to all routes
const routes = [
'',
'/actions',
'/missions',
'/leaderboards',
'/admin/organization',
'/admin/users',
'/admin/reports'
];
let currentRouteIndex = 0;
function testNextRoute() {
if (currentRouteIndex >= routes.length) {
showResults();
return;
}
const route = routes[currentRouteIndex];
console.log(`π Testing route: ${route || '/dashboard'}`);
// Navigate to route
window.location.hash = route;
setTimeout(() => {
currentRouteIndex++;
testNextRoute();
}, 2000); // Wait 2 seconds between route changes
}
function showResults() {
console.log('\nπ BROWSER CONSOLE TEST RESULTS');
console.log('================================');
if (errors.length === 0) {
console.log('β
No console errors detected!');
} else {
console.log(`β Found ${errors.length} console errors:`);
errors.forEach((error, index) => {
console.log(` ${index + 1}. [${error.timestamp}] ${error.message}`);
});
}
if (warnings.length === 0) {
console.log('β
No console warnings detected!');
} else {
console.log(`β οΈ Found ${warnings.length} console warnings:`);
warnings.forEach((warning, index) => {
console.log(` ${index + 1}. [${warning.timestamp}] ${warning.message}`);
});
}
// Restore original console methods
console.error = originalError;
console.warn = originalWarn;
console.log('\nπ Browser console check completed!');
}
// Start the test
console.log('Starting route navigation test in 3 seconds...');
setTimeout(testNextRoute, 3000);
EOF
print_info "Browser console error checking script created: browser-console-check.js"
print_info "To use it:"
echo " 1. Open your browser and navigate to $FRONTEND_URL"
echo " 2. Open DevTools (F12)"
echo " 3. Go to the Console tab"
echo " 4. Copy and paste the contents of browser-console-check.js"
echo " 5. Press Enter to run the automated console error check"
# =============================================================================
# Application Startup Script
# =============================================================================
cat > start-gamifier-dev.sh << 'EOF'
#!/bin/bash
# Starfleet Gamifier Development Startup Script
echo "π Starting Starfleet Gamifier Development Environment..."
# Function to check if port is in use
check_port() {
if lsof -Pi :$1 -sTCP:LISTEN -t >/dev/null ; then
echo "β οΈ Port $1 is already in use"
return 1
else
echo "β
Port $1 is available"
return 0
fi
}
# Check ports
echo "π Checking required ports..."
check_port 4200 # Angular dev server
check_port 9080 # Spring Boot backend
echo ""
echo "π¦ Starting backend (Spring Boot)..."
gnome-terminal --tab --title="Backend" -- bash -c "cd $(pwd) && mvn spring-boot:run; exec bash" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)' && mvn spring-boot:run"' 2>/dev/null || \
(echo "Starting backend in current terminal..." && mvn spring-boot:run &)
echo "β³ Waiting for backend to start..."
sleep 10
echo "π¨ Starting frontend (Angular)..."
gnome-terminal --tab --title="Frontend" -- bash -c "cd $(pwd)/frontend/gamifier-ui && npm start; exec bash" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)/frontend/gamifier-ui' && npm start"' 2>/dev/null || \
(echo "Starting frontend in current terminal..." && cd frontend/gamifier-ui && npm start &)
echo ""
echo "π Starfleet Gamifier is starting up!"
echo "π± Frontend will be available at: http://localhost:4200"
echo "π§ Backend will be available at: http://localhost:9080"
echo ""
echo "β³ Please wait a few moments for both services to fully start..."
echo "π Run ./test-gamifier-app.sh to verify everything is working"
EOF
chmod +x start-gamifier-dev.sh
print_info "Development startup script created: start-gamifier-dev.sh"
# =============================================================================
# Test Summary
# =============================================================================
print_section "TEST SUMMARY"
echo ""
echo -e "${CYAN}π STARFLEET GAMIFIER TEST RESULTS${NC}"
echo -e "${CYAN}=================================${NC}"
echo -e "Total Tests Run: ${BLUE}$TOTAL_TESTS${NC}"
echo -e "Tests Passed: ${GREEN}$PASSED_TESTS${NC}"
echo -e "Tests Failed: ${RED}$FAILED_TESTS${NC}"
if [ $FAILED_TESTS -eq 0 ]; then
echo -e "\n${GREEN}π ALL TESTS PASSED! The Starfleet Gamifier is ready for action!${NC}"
echo -e "${GREEN}π Live long and prosper, Captain!${NC}"
exit_code=0
elif [ $FAILED_TESTS -le 2 ]; then
echo -e "\n${YELLOW}β οΈ Most tests passed with minor issues. Review failures above.${NC}"
exit_code=1
else
echo -e "\n${RED}β Multiple test failures detected. Please review and fix issues.${NC}"
exit_code=2
fi
echo ""
echo -e "${CYAN}π NEXT STEPS:${NC}"
echo "1. Review any failed tests above"
echo "2. Open $FRONTEND_URL in your browser"
echo "3. Test each component manually"
echo "4. Run the browser console check script"
echo "5. Monitor application logs for any errors"
echo ""
echo "π Test log saved to: $LOG_FILE"
echo "π Test completed at: $(date)"
# =============================================================================
# Cleanup
# =============================================================================
# Clean up temporary files
rm -f /tmp/api_response.json
exit $exit_code
EOF
<parameter name="record_test_result 1
fi
done
print_test "Testing MongoDB connection through API"
response=$(curl -s "$BACKEND_URL/api/organization")
if echo "$response" | grep -q "id\|name\|federationId"; then
print_success "MongoDB connection is working (organization data found)"
record_test_result 0
else
print_failure "MongoDB connection may be failing (no organization data)"
record_test_result 1
fi
# =============================================================================
# Security Testing
# =============================================================================
print_section "BASIC SECURITY TESTING"
print_test "Testing for sensitive information exposure"
sensitive_endpoints=(
"/actuator/env"
"/actuator/configprops"
"/actuator/beans"
)
for endpoint in "${sensitive_endpoints[@]}"; do
response_code=$(curl -s -w "%{http_code}" -o /dev/null "$BACKEND_URL$endpoint")
if [ "$response_code" = "404" ] || [ "$response_code" = "401" ] || [ "$response_code" = "403" ]; then
print_success "Sensitive endpoint $endpoint is protected (HTTP $response_code)"
record_test_result 0
else
print_warning "Sensitive endpoint $endpoint may be exposed (HTTP $response_code)"
record_test_result 1
fi
done
# =============================================================================
# Performance Testing
# =============================================================================
print_section "BASIC PERFORMANCE TESTING"
print_test "Testing frontend load time"
start_time=$(date +%s%N)
curl -s "$FRONTEND_URL" > /dev/null
end_time=$(date +%s%N)
load_time=$(( (end_time - start_time) / 1000000 ))
if [ $load_time -lt 2000 ]; then
print_success "Frontend loads quickly (${load_time}ms)"
record_test_result 0
elif [ $load_time -lt 5000 ]; then
print_warning "Frontend load time is acceptable (${load_time}ms)"
record_test_result 0
else
print_failure "Frontend load time is slow (${load_time}ms)"
record_test_result 1
fi
print_test "Testing API response time"
start_time=$(date +%s%N)
curl -s "$BACKEND_URL/api/users" > /dev/null
end_time=$(date +%s%N)
api_time=$(( (end_time - start_time) / 1000000 ))
if [ $api_time -lt 1000 ]; then
print_success "API responds quickly (${api_time}ms)"
record_test_result 0
elif [ $api_time -lt 3000 ]; then
print_warning "API response time is acceptable (${api_time}ms)"
record_test_result 0
else
print_failure "API response time is slow (${api_time}ms)"
record_test_result 1
fi
# =============================================================================
# Browser Testing Commands
# =============================================================================
print_section "BROWSER TESTING COMMANDS"
print_info "To test the application manually in your browser:"
echo ""
echo -e "${CYAN}Frontend URLs to test:${NC}"
echo " π Dashboard: $FRONTEND_URL"
echo " β‘ Actions: $FRONTEND_URL/actions"
echo " π― Missions: $FRONTEND_URL/missions"
echo " π Leaderboards: $FRONTEND_URL/leaderboards"
echo " π§ Admin Organization: $FRONTEND_URL/admin/organization"
echo " π₯ Admin Users: $FRONTEND_URL/admin/users"
echo " π Admin Reports: $FRONTEND_URL/admin/reports"
echo ""
echo -e "${CYAN}Backend API URLs to test:${NC}"
echo " π Users API: $BACKEND_URL/api/users"
echo " β‘ Actions API: $BACKEND_URL/api/actions"
echo " π’ Organization API: $BACKEND_URL/api/organization"
echo " π Leaderboard API: $BACKEND_URL/api/leaderboard"
echo " π Health Check: $BACKEND_URL/actuator/health"
echo ""
# =============================================================================
# Browser Console Error Check Script
# =============================================================================
cat > browser-console-check.js << 'EOF'
// Starfleet Gamifier Browser Console Error Check
// Run this script in your browser's DevTools console to check for errors
console.log('π Starting Starfleet Gamifier Browser Console Check...');
// Store original console methods
const originalError = console.error;
const originalWarn = console.warn;
// Track errors and warnings
let errors = [];
let warnings = [];
// Override console methods to capture logs
console.error = function(...args) {
errors.push({
timestamp: new Date().toISOString(),
message: args.join(' '),
stack: new Error().stack
});
originalError.apply(console, args);
};
console.warn = function(...args) {
warnings.push({
timestamp: new Date().toISOString(),
message: args.join(' ')
});
originalWarn.apply(console, args);
};
// Test navigation to all routes
const routes = [
'',
'/actions',
'/missions',
'/leaderboards',
'/admin/organization',
'/admin/users',
'/admin/reports'
];
let currentRouteIndex = 0;
function testNextRoute() {
if (currentRouteIndex >= routes.length) {
showResults();
return;
}
const route = routes[currentRouteIndex];
console.log(`π Testing route: ${route || '/dashboard'}`);
// Navigate to route
window.location.hash = route;
setTimeout(() => {
currentRouteIndex++;
testNextRoute();
}, 2000); // Wait 2 seconds between route changes
}
function showResults() {
console.log('\nπ BROWSER CONSOLE TEST RESULTS');
console.log('================================');
if (errors.length === 0) {
console.log('β
No console errors detected!');
} else {
console.log(`β Found ${errors.length} console errors:`);
errors.forEach((error, index) => {
console.log(` ${index + 1}. [${error.timestamp}] ${error.message}`);
});
}
if (warnings.length === 0) {
console.log('β
No console warnings detected!');
} else {
console.log(`β οΈ Found ${warnings.length} console warnings:`);
warnings.forEach((warning, index) => {
console.log(` ${index + 1}. [${warning.timestamp}] ${warning.message}`);
});
}
// Restore original console methods
console.error = originalError;
console.warn = originalWarn;
console.log('\nπ Browser console check completed!');
}
// Start the test
console.log('Starting route navigation test in 3 seconds...');
setTimeout(testNextRoute, 3000);
EOF
print_info "Browser console error checking script created: browser-console-check.js"
print_info "To use it:"
echo " 1. Open your browser and navigate to $FRONTEND_URL"
echo " 2. Open DevTools (F12)"
echo " 3. Go to the Console tab"
echo " 4. Copy and paste the contents of browser-console-check.js"
echo " 5. Press Enter to run the automated console error check"
# =============================================================================
# Application Startup Script
# =============================================================================
cat > start-gamifier-dev.sh << 'EOF'
#!/bin/bash
# Starfleet Gamifier Development Startup Script
echo "π Starting Starfleet Gamifier Development Environment..."
# Function to check if port is in use
check_port() {
if lsof -Pi :$1 -sTCP:LISTEN -t >/dev/null ; then
echo "β οΈ Port $1 is already in use"
return 1
else
echo "β
Port $1 is available"
return 0
fi
}
# Check ports
echo "π Checking required ports..."
check_port 4200 # Angular dev server
check_port 9080 # Spring Boot backend
echo ""
echo "π¦ Starting backend (Spring Boot)..."
gnome-terminal --tab --title="Backend" -- bash -c "cd $(pwd) && mvn spring-boot:run; exec bash" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)' && mvn spring-boot:run"' 2>/dev/null || \
(echo "Starting backend in current terminal..." && mvn spring-boot:run &)
echo "β³ Waiting for backend to start..."
sleep 10
echo "π¨ Starting frontend (Angular)..."
gnome-terminal --tab --title="Frontend" -- bash -c "cd $(pwd)/frontend/gamifier-ui && npm start; exec bash" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)/frontend/gamifier-ui' && npm start"' 2>/dev/null || \
(echo "Starting frontend in current terminal..." && cd frontend/gamifier-ui && npm start &)
echo ""
echo "π Starfleet Gamifier is starting up!"
echo "π± Frontend will be available at: http://localhost:4200"
echo "π§ Backend will be available at: http://localhost:9080"
echo ""
echo "β³ Please wait a few moments for both services to fully start..."
echo "π Run ./test-gamifier-app.sh to verify everything is working"
EOF
chmod +x start-gamifier-dev.sh
print_info "Development startup script created: start-gamifier-dev.sh"
# =============================================================================
# Test Summary
# =============================================================================
print_section "TEST SUMMARY"
echo ""
echo -e "${CYAN}π STARFLEET GAMIFIER TEST RESULTS${NC}"
echo -e "${CYAN}=================================${NC}"
echo -e "Total Tests Run: ${BLUE}$TOTAL_TESTS${NC}"
echo -e "Tests Passed: ${GREEN}$PASSED_TESTS${NC}"
echo -e "Tests Failed: ${RED}$FAILED_TESTS${NC}"
if [ $FAILED_TESTS -eq 0 ]; then
echo -e "\n${GREEN}π ALL TESTS PASSED! The Starfleet Gamifier is ready for action!${NC}"
echo -e "${GREEN}π Live long and prosper, Captain!${NC}"
exit_code=0
elif [ $FAILED_TESTS -le 2 ]; then
echo -e "\n${YELLOW}β οΈ Most tests passed with minor issues. Review failures above.${NC}"
exit_code=1
else
echo -e "\n${RED}β Multiple test failures detected. Please review and fix issues.${NC}"
exit_code=2
fi
echo ""
echo -e "${CYAN}π NEXT STEPS:${NC}"
echo "1. Review any failed tests above"
echo "2. Open $FRONTEND_URL in your browser"
echo "3. Test each component manually"
echo "4. Run the browser console check script"
echo "5. Monitor application logs for any errors"
echo ""
echo "π Test log saved to: $LOG_FILE"
echo "π Test completed at: $(date)"
# =============================================================================
# Cleanup
# =============================================================================
# Clean up temporary files
rm -f /tmp/api_response.json
exit $exit_code