feat: add integration and setup tests and complete code review fixes
This commit is contained in:
+231
@@ -0,0 +1,231 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { spawn } = require("child_process");
|
||||
const path = require("path");
|
||||
|
||||
// ANSI color codes for better output
|
||||
const colors = {
|
||||
reset: "\x1b[0m",
|
||||
bright: "\x1b[1m",
|
||||
red: "\x1b[31m",
|
||||
green: "\x1b[32m",
|
||||
yellow: "\x1b[33m",
|
||||
blue: "\x1b[34m",
|
||||
magenta: "\x1b[35m",
|
||||
cyan: "\x1b[36m",
|
||||
};
|
||||
|
||||
function log(message, color = "reset") {
|
||||
console.log(`${colors[color]}${message}${colors.reset}`);
|
||||
}
|
||||
|
||||
function logHeader(message) {
|
||||
console.log("\n" + "=".repeat(60));
|
||||
log(` ${message}`, "bright");
|
||||
console.log("=".repeat(60));
|
||||
}
|
||||
|
||||
function runCommand(command, args = [], description = "") {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (description) {
|
||||
log(`\n🚀 ${description}`, "cyan");
|
||||
log(` Command: ${command} ${args.join(" ")}`, "yellow");
|
||||
}
|
||||
|
||||
const child = spawn(command, args, {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
});
|
||||
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
if (description) {
|
||||
log(`✅ ${description} completed successfully`, "green");
|
||||
}
|
||||
resolve();
|
||||
} else {
|
||||
if (description) {
|
||||
log(`❌ ${description} failed with code ${code}`, "red");
|
||||
}
|
||||
reject(new Error(`Command failed with code ${code}`));
|
||||
}
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
log(`❌ Error running ${description}: ${error.message}`, "red");
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function runTestSuite() {
|
||||
const args = process.argv.slice(2);
|
||||
const command = args[0];
|
||||
|
||||
logHeader("Ticket Microservice Test Runner");
|
||||
log("Comprehensive testing suite for the ticket microservice", "blue");
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
case "all":
|
||||
logHeader("Running Complete Test Suite");
|
||||
await runCommand("npm", ["test"], "Complete test suite");
|
||||
break;
|
||||
|
||||
case "unit":
|
||||
logHeader("Running Unit Tests");
|
||||
await runCommand("npm", ["run", "test:unit"], "Unit tests");
|
||||
break;
|
||||
|
||||
case "integration":
|
||||
logHeader("Running Integration Tests");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:integration"],
|
||||
"Integration tests"
|
||||
);
|
||||
break;
|
||||
|
||||
case "performance":
|
||||
logHeader("Running Performance Tests");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:performance"],
|
||||
"Performance tests"
|
||||
);
|
||||
break;
|
||||
|
||||
case "duplicate":
|
||||
logHeader("Running Critical Duplicate Prevention Tests");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:duplicate-prevention"],
|
||||
"Duplicate prevention tests"
|
||||
);
|
||||
break;
|
||||
|
||||
case "api":
|
||||
logHeader("Running API Endpoint Tests");
|
||||
await runCommand("npm", ["run", "test:api"], "API endpoint tests");
|
||||
break;
|
||||
|
||||
case "security":
|
||||
logHeader("Running Security Tests");
|
||||
await runCommand("npm", ["run", "test:security"], "Security tests");
|
||||
break;
|
||||
|
||||
case "fallback":
|
||||
logHeader("Running Fallback Store Tests");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:fallback"],
|
||||
"Fallback store tests"
|
||||
);
|
||||
break;
|
||||
|
||||
case "coverage":
|
||||
logHeader("Running Tests with Coverage Report");
|
||||
await runCommand("npm", ["run", "test:coverage"], "Coverage tests");
|
||||
break;
|
||||
|
||||
case "load":
|
||||
logHeader("Running Load Tests");
|
||||
await runCommand("npm", ["run", "test:load"], "Load tests");
|
||||
break;
|
||||
|
||||
case "quick":
|
||||
logHeader("Running Quick Test Suite (Critical Paths Only)");
|
||||
log("Running duplicate prevention tests...", "yellow");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:duplicate-prevention"],
|
||||
"Duplicate prevention tests"
|
||||
);
|
||||
log("Running API endpoint tests...", "yellow");
|
||||
await runCommand("npm", ["run", "test:api"], "API endpoint tests");
|
||||
log("Running security tests...", "yellow");
|
||||
await runCommand("npm", ["run", "test:security"], "Security tests");
|
||||
break;
|
||||
|
||||
case "validate":
|
||||
logHeader("Running Validation Tests (Core Requirements)");
|
||||
log("1. Duplicate Prevention Tests", "cyan");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:duplicate-prevention"],
|
||||
"Duplicate prevention validation"
|
||||
);
|
||||
log("2. High Concurrency Tests", "cyan");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:load-performance"],
|
||||
"High concurrency validation"
|
||||
);
|
||||
log("3. API Endpoint Tests", "cyan");
|
||||
await runCommand("npm", ["run", "test:api"], "API endpoint validation");
|
||||
log("4. Security Tests", "cyan");
|
||||
await runCommand(
|
||||
"npm",
|
||||
["run", "test:security"],
|
||||
"Security validation"
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
logHeader("Available Test Commands");
|
||||
log("Usage: node run-tests.js <command>", "bright");
|
||||
console.log("");
|
||||
log("Commands:", "bright");
|
||||
log(" all - Run complete test suite", "green");
|
||||
log(" unit - Run unit tests only", "green");
|
||||
log(" integration- Run integration tests only", "green");
|
||||
log(" performance- Run performance tests only", "green");
|
||||
log(" duplicate - Run duplicate prevention tests", "green");
|
||||
log(" api - Run API endpoint tests", "green");
|
||||
log(" security - Run security tests", "green");
|
||||
log(" fallback - Run fallback store tests", "green");
|
||||
log(" coverage - Run tests with coverage report", "green");
|
||||
log(" load - Run load tests", "green");
|
||||
log(" quick - Run quick test suite (critical paths)", "green");
|
||||
log(" validate - Run validation tests (core requirements)", "green");
|
||||
console.log("");
|
||||
log("Examples:", "bright");
|
||||
log(" node run-tests.js all", "yellow");
|
||||
log(" node run-tests.js duplicate", "yellow");
|
||||
log(" node run-tests.js validate", "yellow");
|
||||
console.log("");
|
||||
log(
|
||||
"Note: Make sure Redis is running and the application is properly configured.",
|
||||
"cyan"
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (command && command !== "help") {
|
||||
logHeader("Test Suite Completed Successfully");
|
||||
log("🎉 All tests passed! The system is working correctly.", "green");
|
||||
}
|
||||
} catch (error) {
|
||||
logHeader("Test Suite Failed");
|
||||
log(`❌ Error: ${error.message}`, "red");
|
||||
log("Please check the test output above for details.", "yellow");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle process termination
|
||||
process.on("SIGINT", () => {
|
||||
log("\n\n⚠️ Test execution interrupted by user", "yellow");
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", () => {
|
||||
log("\n\n⚠️ Test execution terminated", "yellow");
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Run the test suite
|
||||
runTestSuite().catch((error) => {
|
||||
log(`\n💥 Fatal error: ${error.message}`, "red");
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user