forked from Aakvatech-Limited/stock-take-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_endpoints.dart
More file actions
197 lines (176 loc) · 6.56 KB
/
test_api_endpoints.dart
File metadata and controls
197 lines (176 loc) · 6.56 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
// Test script to validate the new API endpoint calls
// This helps verify that all endpoints are correctly formatted before server installation
import 'package:flutter/material.dart';
import 'package:stock_count/hr/services/attendance_service.dart';
import 'package:stock_count/hr/services/leaves_service.dart';
import 'package:stock_count/hr/services/claims_service.dart';
import 'package:stock_count/hr/services/approvals_service.dart';
class ApiEndpointTest {
static void printEndpointSummary() {
print('=== API Endpoint Summary ===');
print('');
print('ATTENDANCE ENDPOINTS:');
print(' • nex_bridge.api.hrms.attendance.checkin');
print(' • nex_bridge.api.hrms.attendance.checkout');
print(' • nex_bridge.api.hrms.attendance.get_attendance_history');
print(' • nex_bridge.api.hrms.attendance.get_attendance_requests');
print(' • nex_bridge.api.hrms.attendance.get_shifts');
print(' • nex_bridge.api.hrms.attendance.get_shift_types');
print('');
print('LEAVES ENDPOINTS:');
print(' • nex_bridge.api.hrms.leaves.get_leave_applications');
print(' • nex_bridge.api.hrms.leaves.get_leave_balance_map');
print(' • nex_bridge.api.hrms.leaves.get_leave_types');
print(' • nex_bridge.api.hrms.leaves.submit_leave_application');
print('');
print('CLAIMS ENDPOINTS:');
print(' • nex_bridge.api.hrms.claims.get_expense_claim_summary');
print(' • nex_bridge.api.hrms.claims.get_expense_claims');
print(' • nex_bridge.api.hrms.claims.get_expense_claim_types');
print(' • nex_bridge.api.hrms.claims.submit_expense_claim');
print('');
print('APPROVALS ENDPOINTS:');
print(' • nex_bridge.api.hrms.approvals.pending_approvals');
print(' • nex_bridge.api.hrms.approvals.my_approvals');
print(' • nex_bridge.api.hrms.approvals.team_members');
print(' • nex_bridge.api.hrms.approvals.approvals_stats');
print(' • nex_bridge.api.hrms.approvals.approve_request');
print(' • nex_bridge.api.hrms.approvals.reject_request');
print('');
print('NEXT STEPS:');
print('1. Install the Nex Bridge API files on your Frappe server');
print('2. Test each endpoint individually');
print('3. Configure employee user linking');
print('4. Set up leave types and expense claim types');
print('5. Test the mobile app with real data');
print('');
print('=== Current Status ===');
print('✅ Mobile app services updated to use Nex Bridge APIs');
print('⏳ Server APIs need to be installed (see INSTALLATION.md)');
print('⏳ Employee user linking needs configuration');
print('⏳ Leave types and expense types need setup');
}
static Future<void> testEndpointConnectivity() async {
print('=== Testing API Connectivity ===');
print('');
// Test attendance endpoints
print('Testing Attendance APIs...');
try {
await AttendanceService.myAttendanceHistory();
print(' ✅ Attendance history endpoint accessible');
} catch (e) {
print(' ❌ Attendance history endpoint error: $e');
}
try {
await AttendanceService.shiftTypes();
print(' ✅ Shift types endpoint accessible');
} catch (e) {
print(' ❌ Shift types endpoint error: $e');
}
// Test leaves endpoints
print('');
print('Testing Leaves APIs...');
try {
await LeavesService.myLeaves();
print(' ✅ My leaves endpoint accessible');
} catch (e) {
print(' ❌ My leaves endpoint error: $e');
}
try {
await LeavesService.leaveBalance();
print(' ✅ Leave balance endpoint accessible');
} catch (e) {
print(' ❌ Leave balance endpoint error: $e');
}
try {
await LeavesService.leaveTypes();
print(' ✅ Leave types endpoint accessible');
} catch (e) {
print(' ❌ Leave types endpoint error: $e');
}
// Test claims endpoints
print('');
print('Testing Claims APIs...');
try {
await ClaimsService.myClaims();
print(' ✅ My claims endpoint accessible');
} catch (e) {
print(' ❌ My claims endpoint error: $e');
}
try {
await ClaimsService.claimTypes();
print(' ✅ Claim types endpoint accessible');
} catch (e) {
print(' ❌ Claim types endpoint error: $e');
}
// Test approvals endpoints
print('');
print('Testing Approvals APIs...');
try {
await ApprovalsService.pendingApprovals();
print(' ✅ Pending approvals endpoint accessible');
} catch (e) {
print(' ❌ Pending approvals endpoint error: $e');
}
try {
await ApprovalsService.approvalsStats();
print(' ✅ Approvals stats endpoint accessible');
} catch (e) {
print(' ❌ Approvals stats endpoint error: $e');
}
print('');
print('=== Test Complete ===');
print(
'If you see ❌ errors, it means the Nex Bridge APIs are not installed on your server yet.');
print('Install them following the INSTALLATION.md guide, then re-test.');
}
}
class ApiTestWidget extends StatelessWidget {
const ApiTestWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('API Endpoint Test'),
backgroundColor: Colors.teal,
foregroundColor: Colors.white,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'API Endpoint Testing',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
const Text(
'This screen helps test the new Nex Bridge HRMS API endpoints.',
style: TextStyle(fontSize: 16),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {
ApiEndpointTest.printEndpointSummary();
},
child: const Text('Print Endpoint Summary'),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () async {
await ApiEndpointTest.testEndpointConnectivity();
},
child: const Text('Test API Connectivity'),
),
const SizedBox(height: 24),
const Text(
'Check your debug console for test results.',
style: TextStyle(fontSize: 14, fontStyle: FontStyle.italic),
),
],
),
),
);
}
}