-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.html
More file actions
144 lines (134 loc) · 5.15 KB
/
test-api.html
File metadata and controls
144 lines (134 loc) · 5.15 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
<!DOCTYPE html>
<html>
<head>
<title>Lingoville API Test</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 2rem;
background: #f5f5f5;
max-width: 1200px;
margin: 0 auto;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
}
h2 {
color: #007bff;
margin-top: 20px;
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px 5px 5px 0;
}
button:hover {
background: #0056b3;
}
.success {
color: #28a745;
font-weight: bold;
}
.error {
color: #dc3545;
font-weight: bold;
}
.loading {
color: #ffc107;
font-weight: bold;
}
pre {
background: #f0f0f0;
padding: 1rem;
border-radius: 4px;
overflow-x: auto;
border-left: 4px solid #007bff;
}
.test-section {
margin: 20px 0;
padding: 15px;
background: #f9f9f9;
border-left: 4px solid #007bff;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>🧪 Lingoville Dashboard - API Test</h1>
<div class="test-section">
<h2>Endpoints to Test</h2>
<button onclick="testStudents()">Test Students</button>
<button onclick="testGroups()">Test Groups</button>
<button onclick="testPayments()">Test Payments</button>
<button onclick="testAttendance()">Test Attendance</button>
<button onclick="testContacts()">Test Contacts</button>
<button onclick="testEvents()">Test Events</button>
<button onclick="testAll()">Test All</button>
<button onclick="clearResults()">Clear</button>
</div>
<h2>Results:</h2>
<div id="results"></div>
</div>
<script type="module">
import api from './services/api.js';
const resultsDiv = document.getElementById('results');
async function testEndpoint(name, resource, action) {
try {
resultsDiv.innerHTML += `<p class="loading">⏳ Testing ${name}...</p>`;
const response = await api.request(`?resource=${resource}&action=${action}`, {
method: 'GET'
});
if (response.ok && response.data) {
const count = Array.isArray(response.data) ? response.data.length : 1;
resultsDiv.innerHTML += `<p class="success">✅ ${name}: ${count} records found</p>`;
resultsDiv.innerHTML += '<pre>' + JSON.stringify(response.data.slice(0, 2), null, 2) + '</pre>';
} else if (response.ok) {
resultsDiv.innerHTML += `<p class="success">✅ ${name}: Success</p>`;
} else {
resultsDiv.innerHTML += `<p class="error">❌ ${name}: ${response.error || 'Unknown error'}</p>`;
}
} catch (err) {
resultsDiv.innerHTML += `<p class="error">❌ ${name} failed: ${err.message}</p>`;
}
}
window.testStudents = () => testEndpoint('Students', 'students', 'list');
window.testGroups = () => testEndpoint('Groups', 'groups', 'list');
window.testPayments = () => testEndpoint('Payments', 'payments', 'list');
window.testAttendance = () => testEndpoint('Attendance', 'attendance', 'list');
window.testContacts = () => testEndpoint('Contacts', 'contacts', 'list');
window.testEvents = () => testEndpoint('Events', 'events', 'list');
window.clearResults = () => {
resultsDiv.innerHTML = '';
};
window.testAll = async () => {
clearResults();
resultsDiv.innerHTML += '<p><strong>Running all tests...</strong></p>';
await testEndpoint('Students', 'students', 'list');
await new Promise(r => setTimeout(r, 500));
await testEndpoint('Groups', 'groups', 'list');
await new Promise(r => setTimeout(r, 500));
await testEndpoint('Payments', 'payments', 'list');
await new Promise(r => setTimeout(r, 500));
await testEndpoint('Attendance', 'attendance', 'list');
await new Promise(r => setTimeout(r, 500));
await testEndpoint('Contacts', 'contacts', 'list');
await new Promise(r => setTimeout(r, 500));
await testEndpoint('Events', 'events', 'list');
resultsDiv.innerHTML += '<p><strong>✅ All tests complete!</strong></p>';
};
</script>
</body>
</html>