This repository was archived by the owner on Nov 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-time-tracking.sh
More file actions
executable file
·222 lines (180 loc) · 6.83 KB
/
test-time-tracking.sh
File metadata and controls
executable file
·222 lines (180 loc) · 6.83 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
#!/bin/bash
# Time Tracking Integration Test Script
# Tests Clock In/Out functionality with Time Logging Service
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
APPOINTMENT_SERVICE_URL="http://localhost:8083"
TIME_LOGGING_SERVICE_URL="http://localhost:8085"
EMPLOYEE_ID="emp-test-001"
APPOINTMENT_ID="test-appointment-001"
# Get JWT token (you'll need to implement this based on your auth service)
# For now, using a placeholder
JWT_TOKEN="your-jwt-token-here"
echo -e "${YELLOW}========================================${NC}"
echo -e "${YELLOW}Time Tracking Integration Test${NC}"
echo -e "${YELLOW}========================================${NC}"
echo ""
# Test 1: Clock In
echo -e "${YELLOW}Test 1: Clock In${NC}"
echo "POST ${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/clock-in"
echo ""
CLOCK_IN_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X POST "${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/clock-in" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}" \
-H "Content-Type: application/json")
HTTP_STATUS=$(echo "$CLOCK_IN_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2)
RESPONSE_BODY=$(echo "$CLOCK_IN_RESPONSE" | sed '/HTTP_STATUS/d')
if [ "$HTTP_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Clock In Successful${NC}"
echo "$RESPONSE_BODY" | jq '.'
# Extract timeLogId from response
TIME_SESSION_ID=$(echo "$RESPONSE_BODY" | jq -r '.id')
TIME_LOG_ID=$(echo "$RESPONSE_BODY" | jq -r '.timeLogId // empty')
echo ""
echo "Time Session ID: $TIME_SESSION_ID"
if [ -n "$TIME_LOG_ID" ]; then
echo "Time Log ID: $TIME_LOG_ID"
fi
else
echo -e "${RED}✗ Clock In Failed (HTTP $HTTP_STATUS)${NC}"
echo "$RESPONSE_BODY"
fi
echo ""
echo "---"
echo ""
# Test 2: Get Active Time Session
echo -e "${YELLOW}Test 2: Get Active Time Session${NC}"
echo "GET ${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/time-session"
echo ""
sleep 2 # Wait 2 seconds to show elapsed time
SESSION_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X GET "${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/time-session" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}")
HTTP_STATUS=$(echo "$SESSION_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2)
RESPONSE_BODY=$(echo "$SESSION_RESPONSE" | sed '/HTTP_STATUS/d')
if [ "$HTTP_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Active Session Found${NC}"
echo "$RESPONSE_BODY" | jq '.'
ELAPSED_SECONDS=$(echo "$RESPONSE_BODY" | jq -r '.elapsedSeconds')
echo ""
echo "Elapsed Time: ${ELAPSED_SECONDS} seconds"
else
echo -e "${RED}✗ Failed to Get Session (HTTP $HTTP_STATUS)${NC}"
echo "$RESPONSE_BODY"
fi
echo ""
echo "---"
echo ""
# Test 3: Wait and show timer
echo -e "${YELLOW}Test 3: Live Timer Simulation${NC}"
echo "Waiting 5 seconds to simulate work..."
echo ""
for i in {1..5}; do
sleep 1
# Poll for updated elapsed time
SESSION_RESPONSE=$(curl -s \
-X GET "${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/time-session" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}")
ELAPSED=$(echo "$SESSION_RESPONSE" | jq -r '.elapsedSeconds // 0')
HOURS=$((ELAPSED / 3600))
MINUTES=$(((ELAPSED % 3600) / 60))
SECONDS=$((ELAPSED % 60))
printf "Timer: %02d:%02d:%02d\r" $HOURS $MINUTES $SECONDS
done
echo ""
echo ""
echo "---"
echo ""
# Test 4: Clock Out
echo -e "${YELLOW}Test 4: Clock Out${NC}"
echo "POST ${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/clock-out"
echo ""
CLOCK_OUT_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X POST "${APPOINTMENT_SERVICE_URL}/appointments/${APPOINTMENT_ID}/clock-out" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}" \
-H "Content-Type: application/json")
HTTP_STATUS=$(echo "$CLOCK_OUT_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2)
RESPONSE_BODY=$(echo "$CLOCK_OUT_RESPONSE" | sed '/HTTP_STATUS/d')
if [ "$HTTP_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Clock Out Successful${NC}"
echo "$RESPONSE_BODY" | jq '.'
HOURS_WORKED=$(echo "$RESPONSE_BODY" | jq -r '.hoursWorked')
echo ""
echo "Total Hours Worked: $HOURS_WORKED"
else
echo -e "${RED}✗ Clock Out Failed (HTTP $HTTP_STATUS)${NC}"
echo "$RESPONSE_BODY"
fi
echo ""
echo "---"
echo ""
# Test 5: Verify Time Log in Time Logging Service
if [ -n "$TIME_LOG_ID" ]; then
echo -e "${YELLOW}Test 5: Verify Time Log in Time Logging Service${NC}"
echo "GET ${TIME_LOGGING_SERVICE_URL}/time-logs/${TIME_LOG_ID}"
echo ""
TIME_LOG_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X GET "${TIME_LOGGING_SERVICE_URL}/time-logs/${TIME_LOG_ID}" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}")
HTTP_STATUS=$(echo "$TIME_LOG_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2)
RESPONSE_BODY=$(echo "$TIME_LOG_RESPONSE" | sed '/HTTP_STATUS/d')
if [ "$HTTP_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Time Log Found${NC}"
echo "$RESPONSE_BODY" | jq '.'
else
echo -e "${RED}✗ Time Log Not Found (HTTP $HTTP_STATUS)${NC}"
echo "$RESPONSE_BODY"
fi
fi
echo ""
echo "---"
echo ""
# Test 6: Get Summary Stats
echo -e "${YELLOW}Test 6: Get Employee Time Summary${NC}"
echo "GET ${TIME_LOGGING_SERVICE_URL}/time-logs/summary?period=daily&date=$(date +%Y-%m-%d)"
echo ""
SUMMARY_RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X GET "${TIME_LOGGING_SERVICE_URL}/time-logs/summary?period=daily&date=$(date +%Y-%m-%d)" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-User-Subject: ${EMPLOYEE_ID}")
HTTP_STATUS=$(echo "$SUMMARY_RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2)
RESPONSE_BODY=$(echo "$SUMMARY_RESPONSE" | sed '/HTTP_STATUS/d')
if [ "$HTTP_STATUS" == "200" ]; then
echo -e "${GREEN}✓ Summary Retrieved${NC}"
echo "$RESPONSE_BODY" | jq '.'
else
echo -e "${RED}✗ Summary Failed (HTTP $HTTP_STATUS)${NC}"
echo "$RESPONSE_BODY"
fi
echo ""
echo -e "${YELLOW}========================================${NC}"
echo -e "${YELLOW}Test Complete${NC}"
echo -e "${YELLOW}========================================${NC}"
echo ""
# Checklist
echo "Verification Checklist:"
echo ""
echo "[ ] Clock in created time log with 0 hours"
echo "[ ] Clock in changed appointment status to IN_PROGRESS"
echo "[ ] Active session returns current elapsed time"
echo "[ ] Timer increments every second"
echo "[ ] Clock out calculated correct hours"
echo "[ ] Clock out updated time log with actual hours"
echo "[ ] Clock out changed appointment status to COMPLETED"
echo "[ ] Summary shows today's total hours"
echo ""
echo "Next Steps:"
echo "1. Update JWT_TOKEN in this script with real token"
echo "2. Create a test appointment with valid ID"
echo "3. Run this script to test the full flow"
echo "4. Check database for TimeSession and TimeLog entries"
echo "5. Implement frontend UI components"