Initial commit
This commit is contained in:
128
test-startup.js
Normal file
128
test-startup.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Kitchen Agent - Startup Test
|
||||
* Tests the complete server startup and shutdown
|
||||
*/
|
||||
|
||||
console.log('Testing Kitchen Agent startup...\n');
|
||||
|
||||
// Load environment
|
||||
require('dotenv').config();
|
||||
|
||||
async function testStartup() {
|
||||
let server = null;
|
||||
|
||||
try {
|
||||
console.log('Step 1: Initializing database...');
|
||||
const database = require('./database');
|
||||
database.init();
|
||||
console.log(' ✓ Database ready\n');
|
||||
|
||||
console.log('Step 2: Loading modules...');
|
||||
const config = require('./config');
|
||||
const apiClient = require('./api-client');
|
||||
const printer = require('./printer');
|
||||
console.log(' ✓ All modules loaded\n');
|
||||
|
||||
console.log('Step 3: Starting Fastify server...');
|
||||
const Fastify = require('fastify');
|
||||
const path = require('path');
|
||||
|
||||
const fastify = Fastify({ logger: false });
|
||||
|
||||
// Register plugins
|
||||
await fastify.register(require('@fastify/view'), {
|
||||
engine: { ejs: require('ejs') },
|
||||
root: path.join(__dirname, 'views')
|
||||
});
|
||||
|
||||
await fastify.register(require('@fastify/static'), {
|
||||
root: path.join(__dirname, 'public'),
|
||||
prefix: '/public/'
|
||||
});
|
||||
|
||||
await fastify.register(require('@fastify/cookie'), {
|
||||
secret: process.env.COOKIE_SECRET || 'test-secret'
|
||||
});
|
||||
|
||||
await fastify.register(require('@fastify/formbody'));
|
||||
|
||||
await fastify.register(require('@fastify/multipart'), {
|
||||
limits: { fileSize: 5 * 1024 * 1024 }
|
||||
});
|
||||
|
||||
console.log(' ✓ Plugins registered\n');
|
||||
|
||||
console.log('Step 4: Registering routes...');
|
||||
await fastify.register(require('./routes/auth'));
|
||||
await fastify.register(require('./routes/dashboard'));
|
||||
await fastify.register(require('./routes/settings'));
|
||||
await fastify.register(require('./routes/orders'));
|
||||
console.log(' ✓ All routes registered\n');
|
||||
|
||||
console.log('Step 5: Starting server on port 3000...');
|
||||
await fastify.listen({ port: 3000, host: '127.0.0.1' });
|
||||
console.log(' ✓ Server started successfully\n');
|
||||
|
||||
server = fastify;
|
||||
|
||||
console.log('Step 6: Testing routes...');
|
||||
|
||||
// Test root route
|
||||
const response = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/'
|
||||
});
|
||||
|
||||
if (response.statusCode === 302) {
|
||||
console.log(' ✓ Root route works (redirects)');
|
||||
} else {
|
||||
console.log(` ✗ Root route returned ${response.statusCode}`);
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
// Test login page
|
||||
const loginResponse = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/login'
|
||||
});
|
||||
|
||||
if (loginResponse.statusCode === 200) {
|
||||
console.log(' ✓ Login page loads');
|
||||
} else {
|
||||
console.log(` ✗ Login page returned ${loginResponse.statusCode}`);
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
console.log('\nStep 7: Shutting down server...');
|
||||
await fastify.close();
|
||||
console.log(' ✓ Server stopped gracefully\n');
|
||||
|
||||
console.log('='.repeat(60));
|
||||
console.log('✅ STARTUP TEST PASSED');
|
||||
console.log('='.repeat(60));
|
||||
console.log('\nThe Kitchen Agent is ready to run!');
|
||||
console.log('Start with: npm start\n');
|
||||
|
||||
database.close();
|
||||
process.exit(0);
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ STARTUP TEST FAILED');
|
||||
console.error('Error:', error.message);
|
||||
console.error('\nStack trace:');
|
||||
console.error(error.stack);
|
||||
|
||||
if (server) {
|
||||
try {
|
||||
await server.close();
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
testStartup();
|
||||
|
||||
Reference in New Issue
Block a user