This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
771 lines (670 loc) · 23.5 KB
/
test.mjs
File metadata and controls
771 lines (670 loc) · 23.5 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
#!/usr/bin/env node
import { handler } from './index.mjs';
import { config } from 'dotenv';
import axios from 'axios';
import semver from 'semver';
// Load environment variables from .env file
config();
function createTestEvent(queryParams = {}, pathParam = null) {
return {
resource: '/{proxy+}',
path: pathParam ? `/${pathParam}` : '/',
httpMethod: 'GET',
headers: {
'Host': 'localhost:3000',
'User-Agent': 'test-client'
},
multiValueHeaders: {},
pathParameters: pathParam ? { proxy: pathParam } : null,
queryStringParameters: queryParams,
multiValueQueryStringParameters: Object.fromEntries(
Object.entries(queryParams).map(([k, v]) => [k, [v]])
),
stageVariables: null,
requestContext: {
resourceId: 'test',
resourcePath: '/{proxy+}',
httpMethod: 'GET',
extendedRequestId: 'test',
requestTime: new Date().toISOString(),
path: '/test',
accountId: 'test',
protocol: 'HTTP/1.1',
stage: 'test',
domainPrefix: 'test',
requestTimeEpoch: Date.now(),
requestId: 'test',
identity: { sourceIp: '127.0.0.1' },
domainName: 'localhost',
apiId: 'test'
},
body: null,
isBase64Encoded: false
};
}
function validateShieldsSchema(data) {
const errors = [];
// Required fields
if (typeof data.schemaVersion !== 'number' || data.schemaVersion !== 1) {
errors.push('schemaVersion must be number 1');
}
if (typeof data.label !== 'string' || data.label.length === 0) {
errors.push('label must be non-empty string');
}
if (typeof data.message !== 'string' || data.message.length === 0) {
errors.push('message must be non-empty string');
}
if (typeof data.color !== 'string' || data.color.length === 0) {
errors.push('color must be non-empty string');
}
// Optional fields validation
if (data.namedLogo !== undefined && typeof data.namedLogo !== 'string') {
errors.push('namedLogo must be string if present');
}
// Color validation (basic check for known values or hex)
const validColors = ['blue', 'orange', 'lightgrey', 'green', 'red', 'yellow', 'purple', 'pink'];
const isHexColor = /^#[0-9A-Fa-f]{6}$/.test(data.color);
if (!validColors.includes(data.color) && !isHexColor) {
errors.push(`color '${data.color}' should be valid color name or hex`);
}
return errors;
}
// Real API validation helpers
async function fetchNuGetVersions(packageName) {
try {
const url = `https://api.nuget.org/v3-flatcontainer/${encodeURIComponent(packageName)}/index.json`;
const { data } = await axios.get(url);
return data.versions;
} catch (error) {
return null;
}
}
async function fetchGitHubVersions(org, packageName) {
if (!process.env.GITHUB_TOKEN) {
return null;
}
try {
// GitHub Packages API endpoint for versions
const url = `https://api.github.com/orgs/${org}/packages/nuget/${packageName}/versions`;
const { data } = await axios.get(url, {
headers: {
'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
'Accept': 'application/vnd.github.v3+json'
}
});
return data.map(version => version.name);
} catch (error) {
console.log(` ⚠️ GitHub API error: ${error.response?.status} ${error.response?.statusText}`);
return null;
}
}
async function validateVersionAgainstRealAPI(packageName, source, resultVersion, params = {}) {
console.log(` 🔍 Validating against real ${source.toUpperCase()} API...`);
let actualVersions = null;
if (source === 'nuget') {
actualVersions = await fetchNuGetVersions(packageName);
} else if (source === 'github') {
actualVersions = await fetchGitHubVersions('localstack', packageName);
}
if (!actualVersions) {
console.log(` ⚠️ Could not fetch real API data for validation`);
return true; // Can't validate, assume OK
}
if (resultVersion === 'not found') {
// For "not found" results, verify no matching versions exist
const hasMatchingVersions = actualVersions.some(v => {
if (params.track && !v.startsWith(params.track.replace('v', '') + '.')) return false;
if (!params['include-prerelease'] && semver.prerelease(v)) return false;
return true;
});
if (hasMatchingVersions) {
console.log(` ❌ API returned "not found" but matching versions exist in real API`);
return false;
} else {
console.log(` ✅ "not found" result validated - no matching versions in real API`);
return true;
}
}
// For actual versions, verify they exist in the real API
if (!actualVersions.includes(resultVersion)) {
console.log(` ❌ Version ${resultVersion} not found in real ${source.toUpperCase()} API`);
console.log(` 📋 Available versions: ${actualVersions.slice(0, 5).join(', ')}${actualVersions.length > 5 ? '...' : ''}`);
return false;
}
console.log(` ✅ Version ${resultVersion} confirmed in real ${source.toUpperCase()} API`);
return true;
}
function validateExpectedContent(data, expectedValues = {}) {
const errors = [];
if (expectedValues.messagePattern && !expectedValues.messagePattern.test(data.message)) {
errors.push(`message '${data.message}' doesn't match expected pattern`);
}
if (expectedValues.color && data.color !== expectedValues.color) {
errors.push(`expected color '${expectedValues.color}', got '${data.color}'`);
}
if (expectedValues.logo && data.namedLogo !== expectedValues.logo) {
errors.push(`expected logo '${expectedValues.logo}', got '${data.namedLogo}'`);
}
if (expectedValues.labelContains && !data.label.includes(expectedValues.labelContains)) {
errors.push(`label '${data.label}' should contain '${expectedValues.labelContains}'`);
}
return errors;
}
async function runTest(testName, queryParams = {}, pathParam = null, expectedStatus = 200, validation = {}, validateAPI = false) {
console.log(`\n🧪 ${testName}`);
console.log(`📋 Query Params: ${JSON.stringify(queryParams)}`);
if (pathParam) console.log(`🛤️ Path Param: ${pathParam}`);
console.log('─'.repeat(70));
try {
const event = createTestEvent(queryParams, pathParam);
const result = await handler(event);
const statusIcon = result.statusCode === expectedStatus ? '✅' : '❌';
console.log(`${statusIcon} Status: ${result.statusCode} (expected: ${expectedStatus})`);
if (result.statusCode === 200) {
const data = JSON.parse(result.body);
// Validate shields.io schema
const schemaErrors = validateShieldsSchema(data);
if (schemaErrors.length === 0) {
console.log(`✅ Schema: Valid shields.io endpoint badge format`);
} else {
console.log(`❌ Schema Errors:`);
schemaErrors.forEach(error => console.log(` • ${error}`));
}
// Validate expected content
const contentErrors = validateExpectedContent(data, validation);
if (contentErrors.length === 0 && Object.keys(validation).length > 0) {
console.log(`✅ Content: Matches expectations`);
} else if (contentErrors.length > 0) {
console.log(`❌ Content Errors:`);
contentErrors.forEach(error => console.log(` • ${error}`));
}
// Show response summary
console.log(`📊 Response:`);
console.log(` Label: "${data.label}"`);
console.log(` Message: "${data.message}"`);
console.log(` Color: ${data.color}`);
if (data.namedLogo) console.log(` Logo: ${data.namedLogo}`);
// Real API validation if requested
let apiValidation = true;
if (validateAPI && (queryParams.source === 'nuget' || queryParams.source === 'github')) {
const packageName = queryParams.package || pathParam;
if (packageName) {
apiValidation = await validateVersionAgainstRealAPI(
packageName,
queryParams.source,
data.message,
queryParams
);
}
}
return {
success: result.statusCode === expectedStatus && schemaErrors.length === 0 && contentErrors.length === 0 && apiValidation,
data
};
} else {
const error = JSON.parse(result.body);
console.log(`❌ Error: ${error.error || 'Unknown error'}`);
return { success: result.statusCode === expectedStatus, data: error };
}
} catch (error) {
console.log(`💥 Exception: ${error.message}`);
return { success: false, error: error.message };
}
}
async function main() {
console.log('🚀 COMPREHENSIVE BADGE API TESTS');
console.log('='.repeat(70));
console.log(`🔑 GitHub Token: ${process.env.GITHUB_TOKEN ? '✅ Set' : '❌ Not Set'}`);
console.log(`🎯 Two-Track Strategy: LocalStack.Client v1.x (maintenance) & v2.x (future)`);
console.log('='.repeat(70));
const tests = [
// === BASIC FUNCTIONALITY TESTS ===
{
name: '🔵 Basic NuGet Package',
params: { package: 'Newtonsoft.Json', source: 'nuget' },
expectedStatus: 200,
validation: {
messagePattern: /^\d+\.\d+\.\d+$/, // Semver format
color: 'blue', // Should be stable
logo: 'nuget',
labelContains: 'newtonsoft.json'
},
validateAPI: true
},
{
name: '🔄 Include Prereleases',
params: { package: 'Microsoft.EntityFrameworkCore', source: 'nuget', 'include-prerelease': 'true' },
expectedStatus: 200,
validation: {
logo: 'nuget',
labelContains: 'microsoft'
},
validateAPI: true
},
// === VERSION TRACKING TESTS ===
{
name: '🎯 Track v2 Only (ASP.NET Core)',
params: { package: 'Microsoft.AspNetCore.App', source: 'nuget', track: '2' },
expectedStatus: 200,
validation: {
messagePattern: /^2\.\d+\.\d+$/, // Should start with 2.x
color: 'blue',
logo: 'nuget'
},
validateAPI: true
},
{
name: '🎯 Track v1 (LocalStack - should work for v1.x)',
params: { package: 'localstack.client', source: 'nuget', track: '1' },
expectedStatus: 200,
validation: {
logo: 'nuget'
},
validateAPI: true
},
{
name: '🎯 Track v1 Format Flexibility (accepts "v1")',
params: { package: 'localstack.client', source: 'nuget', track: 'v1' },
expectedStatus: 200,
validation: {
logo: 'nuget'
},
validateAPI: true
},
// === TWO-TRACK STRATEGY DEMONSTRATION ===
{
name: '🛡️ Two-Track: v1.x Maintenance (LocalStack.Client)',
params: { package: 'localstack.client', source: 'nuget', track: '1' },
expectedStatus: 200,
validation: {
messagePattern: /^1\.\d+\.\d+$/, // Should be 1.x version
logo: 'nuget'
},
validateAPI: true
},
{
name: '🚀 Two-Track: v2.x Future (LocalStack.Client)',
params: { package: 'localstack.client', source: 'nuget', track: '2', 'include-prerelease': 'true' },
expectedStatus: 200,
validation: {
messagePattern: /^2\.\d+\.\d+/, // Should be 2.x version (may have prerelease suffix)
logo: 'nuget'
},
validateAPI: true
},
// === PARAMETER PARSING TESTS ===
{
name: '� Parameter Variant: includePrerelease (camelCase)',
params: { package: 'Microsoft.EntityFrameworkCore', source: 'nuget', includePrerelease: 'true' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
{
name: '🔧 Parameter Variant: includeprerelease (lowercase)',
params: { package: 'Microsoft.EntityFrameworkCore', source: 'nuget', includeprerelease: 'true' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
// === SEMVER RANGE FILTERING TESTS ===
{
name: '📊 Semver Range: gte Only',
params: { package: 'Microsoft.AspNetCore.App', source: 'nuget', gte: '2.0.0' },
expectedStatus: 200,
validation: { logo: 'nuget' },
validateAPI: true
},
{
name: '📊 Semver Range: Combined (gte + lt)',
params: { package: 'Microsoft.AspNetCore.App', source: 'nuget', gte: '2.0.0', lt: '3.0.0' },
expectedStatus: 200,
validation: {
messagePattern: /^2\.\d+\.\d+$/, // Should be 2.x version
logo: 'nuget'
},
validateAPI: true
},
{
name: '📊 Semver Range: Partial Version Coercion',
params: { package: 'Microsoft.AspNetCore.App', source: 'nuget', gte: '2.0', lt: '3.0' },
expectedStatus: 200,
validation: {
messagePattern: /^2\.\d+\.\d+$/, // Should work with partial versions
logo: 'nuget'
}
},
// === CUSTOM STYLING TESTS ===
{
name: '🎨 Custom Label and Color',
params: { package: 'Newtonsoft.Json', source: 'nuget', label: 'JSON.NET', color: 'purple' },
expectedStatus: 200,
validation: {
color: 'purple',
labelContains: 'JSON.NET'
}
},
{
name: '🎨 Custom Hex Color',
params: { package: 'Newtonsoft.Json', source: 'nuget', color: '#ff6b35' },
expectedStatus: 200,
validation: {
color: '#ff6b35'
}
},
// === EXPLICIT ROUTE TESTS ===
{
name: '🛤️ Explicit Package Route',
params: { source: 'nuget', track: '2' },
pathParam: 'badge/packages/Microsoft.AspNetCore.App',
expectedStatus: 200,
validation: { logo: 'nuget' }
},
// === GITHUB PACKAGES TESTS ===
...(process.env.GITHUB_TOKEN ? [
{
name: '🐙 GitHub Package: Basic',
params: { package: 'localstack.client', source: 'github' },
expectedStatus: 200,
validation: {
logo: 'github',
labelContains: 'localstack.client'
},
validateAPI: true
},
{
name: '🐙 GitHub Package: With Prereleases',
params: { package: 'localstack.client', source: 'github', 'include-prerelease': 'true' },
expectedStatus: 200,
validation: {
logo: 'github',
labelContains: 'localstack.client'
},
validateAPI: true
},
{
name: '🧹 GitHub Package: Prefer Clean (avoid timestamped builds)',
params: { package: 'localstack.client', source: 'github', 'include-prerelease': 'true', 'prefer-clean': 'true' },
expectedStatus: 200,
validation: {
logo: 'github',
labelContains: 'localstack.client'
},
validateAPI: true
},
{
name: '🔧 GitHub Package: preferClean Parameter Variant',
params: { package: 'localstack.client', source: 'github', 'include-prerelease': 'true', preferClean: 'true' },
expectedStatus: 200,
validation: { logo: 'github' }
}
] : []),
// === ERROR HANDLING TESTS ===
{
name: '❌ Non-existent Package',
params: { package: 'definitely-does-not-exist-12345', source: 'nuget' },
expectedStatus: 200, // Should return "not found" badge, not error
validation: {
messagePattern: /^not found$/,
color: 'lightgrey'
}
},
{
name: '❌ Invalid Package Name (special characters)',
params: { package: 'invalid/package/name!', source: 'nuget' },
expectedStatus: 400
},
{
name: '❌ Missing Package Parameter',
params: { source: 'nuget' },
expectedStatus: 400
},
{
name: '❌ Invalid Source',
params: { package: 'test.package', source: 'invalid-source' },
expectedStatus: 400 // Changed from 500 to 400 - this is client error, not server error
},
// === EDGE CASES ===
{
name: '⚠️ Impossible Range Filter (should return not found)',
params: { package: 'Newtonsoft.Json', source: 'nuget', gt: '99.0.0' },
expectedStatus: 200,
validation: {
messagePattern: /^not found$/,
color: 'lightgrey'
}
},
{
name: '⚠️ Track Non-existent Major Version',
params: { package: 'Newtonsoft.Json', source: 'nuget', track: '99' },
expectedStatus: 200,
validation: {
messagePattern: /^not found$/,
color: 'lightgrey'
}
},
// === MALFORMED PARAMETER TESTS ===
{
name: '🔧 Malformed Boolean: include-prerelease',
params: { package: 'Newtonsoft.Json', source: 'nuget', 'include-prerelease': 'invalid' },
expectedStatus: 200, // Should treat as false
validation: { logo: 'nuget' }
},
{
name: '🔧 Malformed Semver Range',
params: { package: 'Newtonsoft.Json', source: 'nuget', gte: 'not-a-version' },
expectedStatus: 400 // Should return error for invalid semver
},
// === COMPREHENSIVE VALIDATION TESTS ===
{
name: '❌ Empty Package Name',
params: { package: '', source: 'nuget' },
expectedStatus: 400
},
{
name: '❌ Package Name with Spaces',
params: { package: 'invalid package name', source: 'nuget' },
expectedStatus: 400
},
{
name: '❌ Package Name with Invalid Characters (@)',
params: { package: 'package@name', source: 'nuget' },
expectedStatus: 400
},
{
name: '❌ Package Name with Invalid Characters (%)',
params: { package: 'package%name', source: 'nuget' },
expectedStatus: 400
},
{
name: '✅ Package Name with Valid Characters (dots, hyphens, underscores)',
params: { package: 'valid.package-name_123', source: 'nuget' },
expectedStatus: 200,
validation: {
messagePattern: /^not found$/, // Will be not found, but package name is valid
color: 'lightgrey'
}
},
{
name: '❌ Invalid Track Parameter (negative number)',
params: { package: 'Newtonsoft.Json', source: 'nuget', track: '-1' },
expectedStatus: 400
},
{
name: '❌ Invalid Track Parameter (non-numeric)',
params: { package: 'Newtonsoft.Json', source: 'nuget', track: 'invalid' },
expectedStatus: 400
},
{
name: '❌ Invalid Track Parameter (decimal)',
params: { package: 'Newtonsoft.Json', source: 'nuget', track: '1.5' },
expectedStatus: 400
},
{
name: '✅ Valid Track Parameter (zero)',
params: { package: 'Newtonsoft.Json', source: 'nuget', track: '0' },
expectedStatus: 200,
validation: {
messagePattern: /^not found$/, // No v0.x versions exist
color: 'lightgrey'
}
},
{
name: '❌ Invalid Semver: gt parameter',
params: { package: 'Newtonsoft.Json', source: 'nuget', gt: 'invalid-version' },
expectedStatus: 400
},
{
name: '❌ Invalid Semver: gte parameter',
params: { package: 'Newtonsoft.Json', source: 'nuget', gte: '1.2.invalid' },
expectedStatus: 400
},
{
name: '❌ Invalid Semver: lt parameter',
params: { package: 'Newtonsoft.Json', source: 'nuget', lt: 'not.a.version' },
expectedStatus: 400
},
{
name: '❌ Invalid Semver: lte parameter',
params: { package: 'Newtonsoft.Json', source: 'nuget', lte: 'xyz' },
expectedStatus: 400
},
{
name: '❌ Invalid Semver: eq parameter',
params: { package: 'Newtonsoft.Json', source: 'nuget', eq: '1.2.3.4.5' },
expectedStatus: 400
},
{
name: '✅ Valid Semver Coercion: Partial versions',
params: { package: 'Newtonsoft.Json', source: 'nuget', gte: '1', lt: '2' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
{
name: '✅ Valid Semver Coercion: Two-part versions',
params: { package: 'Newtonsoft.Json', source: 'nuget', gte: '1.0', lt: '2.0' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
{
name: '❌ Invalid Source: Empty string',
params: { package: 'test.package', source: '' },
expectedStatus: 400
},
{
name: '❌ Invalid Source: Mixed case not matching enum',
params: { package: 'test.package', source: 'NuGet' },
expectedStatus: 400
},
{
name: '❌ Invalid Source: Multiple values',
params: { package: 'test.package', source: 'nuget,github' },
expectedStatus: 400
},
{
name: '✅ Valid Source: GitHub lowercase',
params: { package: 'localstack.client', source: 'github', 'include-prerelease': 'true' },
expectedStatus: 200,
validation: { logo: 'github' }
},
{
name: '❌ Missing Package with Path Parameter (empty path)',
params: { source: 'nuget' },
pathParam: '',
expectedStatus: 400
},
{
name: '❌ Missing Package with Path Parameter (whitespace only)',
params: { source: 'nuget' },
pathParam: ' ',
expectedStatus: 400
},
{
name: '✅ Boolean Parameter: prefer-clean with various values',
params: { package: 'localstack.client', source: 'github', 'include-prerelease': 'true', 'prefer-clean': 'false' },
expectedStatus: 200,
validation: { logo: 'github' }
},
{
name: '✅ Boolean Parameter: log parameter acceptance',
params: { package: 'Newtonsoft.Json', source: 'nuget', log: 'true' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
{
name: '✅ Boolean Parameter: log parameter with false',
params: { package: 'Newtonsoft.Json', source: 'nuget', log: 'false' },
expectedStatus: 200,
validation: { logo: 'nuget' }
},
{
name: '✅ Custom Label: Special characters allowed',
params: { package: 'Newtonsoft.Json', source: 'nuget', label: 'My Custom Label 123!@#' },
expectedStatus: 200,
validation: {
labelContains: 'My Custom Label 123!@#'
}
},
{
name: '✅ Custom Color: Hex color validation',
params: { package: 'Newtonsoft.Json', source: 'nuget', color: '#FF5733' },
expectedStatus: 200,
validation: {
color: '#FF5733'
}
},
{
name: '✅ Multiple Parameter Variants: All at once',
params: {
package: 'Microsoft.EntityFrameworkCore',
source: 'nuget',
includePrerelease: 'true', // camelCase
'prefer-clean': 'true', // kebab-case
gt: '1.0', // partial semver
track: 'v8' // v-prefixed track
},
expectedStatus: 200,
validation: { logo: 'nuget' }
}
];
// Run all tests
let passed = 0;
let failed = 0;
for (let i = 0; i < tests.length; i++) {
const test = tests[i];
console.log(`\n[${i + 1}/${tests.length}]`);
const result = await runTest(
test.name,
test.params,
test.pathParam,
test.expectedStatus,
test.validation || {},
test.validateAPI || false
);
if (result.success) {
passed++;
} else {
failed++;
}
// Small delay between tests
await new Promise(resolve => setTimeout(resolve, 250));
}
// Summary
console.log('\n' + '='.repeat(70));
console.log('📋 TEST SUMMARY');
console.log('='.repeat(70));
console.log(`✅ Passed: ${passed}`);
console.log(`❌ Failed: ${failed}`);
console.log(`📊 Total: ${tests.length}`);
console.log(`🎯 Success Rate: ${Math.round((passed / tests.length) * 100)}%`);
if (!process.env.GITHUB_TOKEN) {
console.log('\n💡 GitHub tests skipped - set GITHUB_TOKEN in .env file to test GitHub Packages');
}
if (failed === 0) {
console.log('\n🎉 All tests passed! The API is working correctly.');
} else {
console.log('\n⚠️ Some tests failed. Check the output above for details.');
}
console.log('\n🏁 Testing completed!');
// Exit with appropriate code
process.exit(failed === 0 ? 0 : 1);
}
main().catch(console.error);