-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-functional.js
More file actions
292 lines (240 loc) · 7.78 KB
/
test-functional.js
File metadata and controls
292 lines (240 loc) · 7.78 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
#!/usr/bin/env node
/**
* NIL Phase 2 Functional Tests
* Tests application runtime functionality
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const colors = {
reset: '\x1b[0m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[36m',
};
const results = {
passed: 0,
failed: 0,
issues: [],
};
function log(color, symbol, message) {
console.log(`${colors[color]}${symbol} ${message}${colors.reset}`);
}
function testPrismaClient() {
try {
log('blue', '►', 'Testing Prisma client...');
// Check if Prisma client can be imported
const prismaPath = path.join(__dirname, 'lib/generated/prisma/index.d.ts');
if (!fs.existsSync(prismaPath)) {
throw new Error('Prisma client types not generated');
}
log('green', '✓', 'Prisma client ready');
results.passed++;
} catch (error) {
log('red', '✗', `Prisma client failed: ${error.message}`);
results.failed++;
results.issues.push(`Prisma: ${error.message}`);
}
}
function testLoggerModule() {
try {
log('blue', '►', 'Testing logger module...');
const loggerPath = path.join(__dirname, 'lib/utils/logger.ts');
const content = fs.readFileSync(loggerPath, 'utf-8');
// Check for required methods
const requiredMethods = ['debug', 'info', 'warn', 'error', 'startTimer', 'getLogger'];
const missing = [];
requiredMethods.forEach(method => {
if (!content.includes(`${method}(`)) {
missing.push(method);
}
});
if (missing.length > 0) {
throw new Error(`Missing methods: ${missing.join(', ')}`);
}
log('green', '✓', 'Logger module complete');
results.passed++;
} catch (error) {
log('red', '✗', `Logger module failed: ${error.message}`);
results.failed++;
results.issues.push(`Logger: ${error.message}`);
}
}
function testErrorHandler() {
try {
log('blue', '►', 'Testing error handler...');
const errorPath = path.join(__dirname, 'lib/utils/api-error-handler.ts');
const content = fs.readFileSync(errorPath, 'utf-8');
// Check for required error classes
const requiredClasses = [
'ValidationError',
'NotFoundError',
'UnauthorizedError',
'ForbiddenError',
];
const missing = [];
requiredClasses.forEach(cls => {
if (!content.includes(`class ${cls}`)) {
missing.push(cls);
}
});
if (missing.length > 0) {
throw new Error(`Missing error classes: ${missing.join(', ')}`);
}
log('green', '✓', 'Error handler complete');
results.passed++;
} catch (error) {
log('red', '✗', `Error handler failed: ${error.message}`);
results.failed++;
results.issues.push(`Error Handler: ${error.message}`);
}
}
function testVaultService() {
try {
log('blue', '►', 'Testing vault service...');
const servicePath = path.join(__dirname, 'lib/contracts/vault-service.ts');
const content = fs.readFileSync(servicePath, 'utf-8');
// Check for required functions
const requiredFunctions = [
'createVault',
'getVault',
'unlockVault',
'voidVault',
];
const missing = [];
requiredFunctions.forEach(fn => {
if (!content.includes(`export async function ${fn}`)) {
missing.push(fn);
}
});
if (missing.length > 0) {
throw new Error(`Missing functions: ${missing.join(', ')}`);
}
// Check for proper wagmi imports
if (!content.includes('wagmi/actions')) {
throw new Error('Not using proper wagmi/actions imports');
}
log('green', '✓', 'Vault service complete');
results.passed++;
} catch (error) {
log('red', '✗', `Vault service failed: ${error.message}`);
results.failed++;
results.issues.push(`Vault Service: ${error.message}`);
}
}
function testCreateVaultForm() {
try {
log('blue', '►', 'Testing CreateVaultForm component...');
const formPath = path.join(__dirname, 'app/components/CreateVaultForm.tsx');
const content = fs.readFileSync(formPath, 'utf-8');
// Check for required functionality
const required = [
'validateForm',
'handleFileChange',
'handleCreateVault',
'const errors = useState',
];
const missing = [];
required.forEach(item => {
if (!content.includes(item)) {
missing.push(item);
}
});
if (missing.length > 0) {
log('yellow', '⚠', `CreateVaultForm: Some expected items missing: ${missing.join(', ')}`);
results.issues.push(`CreateVaultForm: Missing ${missing.join(', ')}`);
} else {
log('green', '✓', 'CreateVaultForm complete');
results.passed++;
}
} catch (error) {
log('red', '✗', `CreateVaultForm failed: ${error.message}`);
results.failed++;
results.issues.push(`CreateVaultForm: ${error.message}`);
}
}
function testDatabaseSchema() {
try {
log('blue', '►', 'Testing database schema...');
const schemaPath = path.join(__dirname, 'prisma/schema.prisma');
const content = fs.readFileSync(schemaPath, 'utf-8');
// Check for required models
const requiredModels = ['User', 'Vault', 'VaultFile', 'ActivityLog', 'ApiKey'];
const missing = [];
requiredModels.forEach(model => {
if (!content.includes(`model ${model}`)) {
missing.push(model);
}
});
if (missing.length > 0) {
throw new Error(`Missing models: ${missing.join(', ')}`);
}
// Check for indexes
if (!content.includes('@@index')) {
log('yellow', '⚠', 'CreateVaultForm: No database indexes found');
results.issues.push('Database: Missing indexes');
}
log('green', '✓', 'Database schema complete');
results.passed++;
} catch (error) {
log('red', '✗', `Database schema failed: ${error.message}`);
results.failed++;
results.issues.push(`Database: ${error.message}`);
}
}
function testAPIRoutes() {
try {
log('blue', '►', 'Testing API routes...');
const routesDir = path.join(__dirname, 'app/api');
const checkRoute = (name) => {
const routePath = path.join(routesDir, name, 'route.ts');
return fs.existsSync(routePath);
};
const requiredRoutes = [
'vaults',
'auth/[...nextauth]',
];
const missing = [];
requiredRoutes.forEach(route => {
if (!checkRoute(route)) {
missing.push(route);
}
});
if (missing.length > 0) {
throw new Error(`Missing API routes: ${missing.join(', ')}`);
}
log('green', '✓', 'API routes complete');
results.passed++;
} catch (error) {
log('red', '✗', `API routes failed: ${error.message}`);
results.failed++;
results.issues.push(`API Routes: ${error.message}`);
}
}
// Run all tests
console.log(colors.blue + '═'.repeat(60) + colors.reset);
console.log(colors.blue + 'FUNCTIONAL TESTS' + colors.reset);
console.log(colors.blue + '═'.repeat(60) + colors.reset);
testPrismaClient();
testLoggerModule();
testErrorHandler();
testVaultService();
testCreateVaultForm();
testDatabaseSchema();
testAPIRoutes();
// Summary
console.log('\n' + colors.blue + '═'.repeat(60) + colors.reset);
console.log(colors.blue + 'SUMMARY' + colors.reset);
console.log(colors.blue + '─'.repeat(60) + colors.reset);
console.log(`${colors.green}Passed: ${results.passed}${colors.reset} | ${colors.red}Failed: ${results.failed}${colors.reset}`);
if (results.issues.length > 0) {
console.log(colors.blue + '\nISSUES FOUND:' + colors.reset);
results.issues.forEach(issue => {
console.log(` • ${issue}`);
});
}
console.log(colors.blue + '═'.repeat(60) + colors.reset);
process.exit(results.failed > 0 ? 1 : 0);