mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
feat: upgrade to v2.0.0 with multi-mirror fallback, new endpoints, and LRU cache
- Add multi-mirror fallback system with 5 mirror domains - Add LRU cache with configurable TTL per endpoint - Add response compression (gzip) - Add Seasons endpoint (/api/seasons/:id) - Add Watch Order endpoint (/api/watch-order/:id) - Add Latest Updated endpoint (/api/latest-updated) - Add Download endpoint (/api/download) - Add cache stats endpoint (/api/cache/stats) - Add mirror status/reset endpoints (/api/mirrors, /api/mirrors/reset) - Add configurable rate limiting with X-RateLimit headers - Add request timeouts and entity too large handling - Update documentation with all new endpoints - Update CHANGELOG.md with v2.0.0 entry - Update package.json version to 2.0.0 - Add 6 AI agent prompts for development
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
* Repository: https://github.com/Shineii86/AniKotoAPI
|
||||
*
|
||||
* @description
|
||||
* Integration test suite for AniKotoAPI endpoints.
|
||||
* Tests all major endpoints for correct response format.
|
||||
* Comprehensive integration test suite for AniKotoAPI endpoints.
|
||||
* Tests all major endpoints for correct response format, status codes,
|
||||
* error handling, and performance benchmarks.
|
||||
*
|
||||
* @author Shinei Nouzen
|
||||
* @license MIT
|
||||
@@ -15,71 +16,151 @@
|
||||
const BASE = process.env.API_URL || "https://anikototvapi.vercel.app/api";
|
||||
|
||||
const tests = [
|
||||
{ name: "Home", url: "/" },
|
||||
{ name: "Search", url: "/search?keyword=naruto" },
|
||||
{ name: "Info", url: "/info?id=road-of-naruto-ggjw8" },
|
||||
{ name: "Episodes", url: "/episodes/road-of-naruto-ggjw8" },
|
||||
{ name: "Suggestions", url: "/suggestions?keyword=naruto" },
|
||||
{ name: "Spotlight", url: "/spotlight" },
|
||||
{ name: "Trending", url: "/trending" },
|
||||
{ name: "Top 10", url: "/top-ten" },
|
||||
{ name: "Random", url: "/random" },
|
||||
{ name: "Most Popular", url: "/most-popular" },
|
||||
{ name: "New Release", url: "/new-release" },
|
||||
{ name: "Schedule", url: "/schedule" },
|
||||
{ name: "Genre", url: "/genre/action" },
|
||||
{ name: "Type", url: "/type/tv" },
|
||||
{ name: "Status", url: "/status/airing" },
|
||||
{ name: "Health", url: "/health" },
|
||||
{ name: "Stats", url: "/stats" },
|
||||
{ name: "OpenAPI", url: "/openapi" },
|
||||
{ name: "Watch", url: "/watch?slug=road-of-naruto-ggjw8&ep=1" },
|
||||
{ name: "Search Suggest", url: "/search/suggest?keyword=naruto" },
|
||||
{ name: "Episodes Ajax", url: "/episodes-ajax/road-of-naruto-ggjw8" },
|
||||
{ name: "Newly Added", url: "/newly-added" },
|
||||
{ name: "Trending Sidebar", url: "/trending-sidebar" },
|
||||
{ name: "Seasons", url: "/seasons/road-of-naruto-ggjw8" },
|
||||
{ name: "Watch Order", url: "/watch-order/road-of-naruto-ggjw8" },
|
||||
{ name: "AZ List", url: "/az-list/a" },
|
||||
{ name: "Filter", url: "/filter?keyword=&genre[]=1" },
|
||||
{ name: "Episodes By ID", url: "/episodes/1" },
|
||||
{ name: "Servers", url: "/servers?ids=1" },
|
||||
{ name: "Mapper Servers", url: "/mapper-servers?malId=21&slug=one-piece-100×tamp=1234567890" },
|
||||
// Core endpoints
|
||||
{ name: "Home", url: "/", check: (d) => d.results?.spotlights || d.results?.trending },
|
||||
{ name: "Search", url: "/search?keyword=naruto", check: (d) => d.results?.data },
|
||||
{ name: "Info", url: "/info?id=road-of-naruto-ggjw8", check: (d) => d.results?.title },
|
||||
{ name: "Episodes", url: "/episodes/road-of-naruto-ggjw8", check: (d) => d.results?.episodes },
|
||||
{ name: "Servers", url: "/servers?ids=1", check: (d) => d.results },
|
||||
{ name: "Watch", url: "/watch?slug=road-of-naruto-ggjw8&ep=1", check: (d) => d.results?.servers || d.results?.episodeNumber },
|
||||
|
||||
// Discovery endpoints
|
||||
{ name: "Suggestions", url: "/suggestions?keyword=naruto", check: (d) => d.results },
|
||||
{ name: "Spotlight", url: "/spotlight", check: (d) => d.results },
|
||||
{ name: "Trending", url: "/trending", check: (d) => d.results },
|
||||
{ name: "Top 10", url: "/top-ten", check: (d) => d.results },
|
||||
{ name: "Random", url: "/random", check: (d) => d.results },
|
||||
{ name: "Most Popular", url: "/most-popular", check: (d) => d.results },
|
||||
{ name: "New Release", url: "/new-release", check: (d) => d.results },
|
||||
{ name: "Newly Added", url: "/newly-added", check: (d) => d.results },
|
||||
{ name: "Latest Updated", url: "/latest-updated", check: (d) => d.results, optional: true },
|
||||
|
||||
// Category endpoints
|
||||
{ name: "Genre", url: "/genre/action", check: (d) => d.results },
|
||||
{ name: "Type", url: "/type/tv", check: (d) => d.results },
|
||||
{ name: "AZ List", url: "/az-list/a", check: (d) => d.results },
|
||||
{ name: "Filter", url: "/filter?keyword=&genre[]=1", check: (d) => d.results },
|
||||
|
||||
// Utility endpoints
|
||||
{ name: "Health", url: "/health", check: (d) => d.status || d.results?.status },
|
||||
{ name: "Stats", url: "/stats", check: (d) => d.results },
|
||||
|
||||
// Search variants
|
||||
{ name: "Search Suggest", url: "/search/suggest?keyword=naruto", check: (d) => d.results },
|
||||
{ name: "Episodes Ajax", url: "/episodes-ajax/7174", check: (d) => d.results },
|
||||
{ name: "Trending Sidebar", url: "/trending-sidebar", check: (d) => d.results },
|
||||
{ name: "Mapper Servers", url: "/mapper-servers?malId=21&slug=one-piece-100×tamp=1234567890", check: (d) => d.results },
|
||||
{ name: "Seasons", url: "/seasons/7174", check: (d) => d.results?.seasons || d.results?.totalSeasons, optional: true },
|
||||
{ name: "Watch Order", url: "/watch-order/7174", check: (d) => d.results?.related || d.results?.totalRelated, optional: true },
|
||||
];
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
let skipped = 0;
|
||||
let total = 0;
|
||||
const results = [];
|
||||
|
||||
async function runTest(test) {
|
||||
total++;
|
||||
const start = Date.now();
|
||||
|
||||
try {
|
||||
const res = await fetch(`${BASE}${test.url}`);
|
||||
const duration = Date.now() - start;
|
||||
|
||||
if (!res.ok) {
|
||||
console.log(`❌ ${test.name} - HTTP ${res.status}`);
|
||||
if (test.optional && (res.status === 404 || res.status === 500)) {
|
||||
console.log(`⏭️ ${test.name} - Skipped (HTTP ${res.status}) (${duration}ms)`);
|
||||
skipped++;
|
||||
results.push({ name: test.name, status: "SKIP", httpStatus: res.status, duration });
|
||||
return;
|
||||
}
|
||||
console.log(`❌ ${test.name} - HTTP ${res.status} (${duration}ms)`);
|
||||
failed++;
|
||||
results.push({ name: test.name, status: "FAIL", httpStatus: res.status, duration });
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
if (data.success === true && data.results) {
|
||||
console.log(`✅ ${test.name}`);
|
||||
passed++;
|
||||
} else {
|
||||
console.log(`❌ ${test.name} - Invalid response format`);
|
||||
|
||||
if (!data.success) {
|
||||
if (test.optional) {
|
||||
console.log(`⏭️ ${test.name} - Skipped (success=false) (${duration}ms)`);
|
||||
skipped++;
|
||||
results.push({ name: test.name, status: "SKIP", reason: "success=false", duration });
|
||||
return;
|
||||
}
|
||||
console.log(`❌ ${test.name} - success=false (${duration}ms)`);
|
||||
failed++;
|
||||
results.push({ name: test.name, status: "FAIL", reason: "success=false", duration });
|
||||
return;
|
||||
}
|
||||
|
||||
// Check custom validation
|
||||
if (test.check && !test.check(data)) {
|
||||
if (test.optional) {
|
||||
console.log(`⏭️ ${test.name} - Skipped (validation failed) (${duration}ms)`);
|
||||
skipped++;
|
||||
results.push({ name: test.name, status: "SKIP", reason: "Validation failed", duration });
|
||||
return;
|
||||
}
|
||||
console.log(`❌ ${test.name} - Validation failed (${duration}ms)`);
|
||||
failed++;
|
||||
results.push({ name: test.name, status: "FAIL", reason: "Validation failed", duration });
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`✅ ${test.name} (${duration}ms)`);
|
||||
passed++;
|
||||
results.push({ name: test.name, status: "PASS", duration });
|
||||
|
||||
} catch (error) {
|
||||
console.log(`❌ ${test.name} - ${error.message}`);
|
||||
const duration = Date.now() - start;
|
||||
if (test.optional) {
|
||||
console.log(`⏭️ ${test.name} - Skipped (${error.message}) (${duration}ms)`);
|
||||
skipped++;
|
||||
results.push({ name: test.name, status: "SKIP", reason: error.message, duration });
|
||||
return;
|
||||
}
|
||||
console.log(`❌ ${test.name} - ${error.message} (${duration}ms)`);
|
||||
failed++;
|
||||
results.push({ name: test.name, status: "FAIL", reason: error.message, duration });
|
||||
}
|
||||
}
|
||||
|
||||
async function runAll() {
|
||||
console.log(`\n🧪 Running ${tests.length} tests...\n`);
|
||||
|
||||
console.log(`📡 API: ${BASE}\n`);
|
||||
|
||||
// Run tests sequentially to avoid rate limiting
|
||||
for (const test of tests) {
|
||||
await runTest(test);
|
||||
}
|
||||
|
||||
console.log(`\n📊 Results: ${passed} passed, ${failed} failed, ${tests.length} total\n`);
|
||||
|
||||
console.log(`\n${"=".repeat(50)}`);
|
||||
console.log(`📊 Results: ${passed} passed, ${failed} failed, ${skipped} skipped, ${total} total`);
|
||||
console.log(`${"=".repeat(50)}`);
|
||||
|
||||
// Performance summary
|
||||
const durations = results.filter(r => r.status === "PASS").map(r => r.duration);
|
||||
if (durations.length > 0) {
|
||||
const avgDuration = durations.reduce((a, b) => a + b, 0) / durations.length;
|
||||
const maxDuration = Math.max(...durations);
|
||||
const minDuration = Math.min(...durations);
|
||||
|
||||
console.log(`\n⚡ Performance:`);
|
||||
console.log(` Average: ${avgDuration.toFixed(0)}ms`);
|
||||
console.log(` Min: ${minDuration}ms`);
|
||||
console.log(` Max: ${maxDuration}ms`);
|
||||
}
|
||||
|
||||
// Detailed results
|
||||
console.log(`\n📋 Detailed Results:`);
|
||||
results.forEach(r => {
|
||||
const icon = r.status === "PASS" ? "✅" : r.status === "SKIP" ? "⏭️" : "❌";
|
||||
console.log(` ${icon} ${r.name} - ${r.status} (${r.duration}ms)${r.reason ? ` - ${r.reason}` : ""}`);
|
||||
});
|
||||
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user