← back to Wine Finder
test-setup.js
116 lines
#!/usr/bin/env node
/**
* Red Thunder Wine Tracker - Setup Verification Script
* This script checks if all required configurations are in place
*/
require('dotenv').config();
const fs = require('fs');
const path = require('path');
console.log('\n🍷 Red Thunder Wine Tracker - Setup Verification\n');
console.log('='.repeat(50));
let allGood = true;
// Check 1: Node version
console.log('\n1. Checking Node.js version...');
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
if (majorVersion >= 16) {
console.log(` ✅ Node.js ${nodeVersion} (OK)`);
} else {
console.log(` ❌ Node.js ${nodeVersion} (Need v16 or higher)`);
allGood = false;
}
// Check 2: .env file
console.log('\n2. Checking .env file...');
if (fs.existsSync('.env')) {
console.log(' ✅ .env file exists');
} else {
console.log(' ❌ .env file missing');
allGood = false;
}
// Check 3: Environment variables
console.log('\n3. Checking environment variables...');
const requiredVars = [
'PORT',
'ADMIN_USER',
'ADMIN_PASS',
'GOOGLE_SHEET_ID',
'SLACK_WEBHOOK_URL'
];
requiredVars.forEach(varName => {
const value = process.env[varName];
if (value && !value.includes('your-') && !value.includes('YOUR')) {
console.log(` ✅ ${varName} is set`);
} else {
console.log(` ❌ ${varName} is not configured`);
allGood = false;
}
});
// Check 4: Google credentials file
console.log('\n4. Checking Google credentials...');
const credsPath = process.env.GOOGLE_APPLICATION_CREDENTIALS || './google-credentials.json';
if (fs.existsSync(credsPath)) {
console.log(` ✅ Google credentials file exists at ${credsPath}`);
try {
const creds = JSON.parse(fs.readFileSync(credsPath, 'utf8'));
if (creds.client_email) {
console.log(` ℹ️ Service account email: ${creds.client_email}`);
console.log(` ℹ️ Make sure your Google Sheet is shared with this email!`);
}
} catch (err) {
console.log(` ⚠️ Could not parse credentials file: ${err.message}`);
}
} else {
console.log(` ❌ Google credentials file not found at ${credsPath}`);
console.log(' → Download from Google Cloud Console and save as google-credentials.json');
allGood = false;
}
// Check 5: Dependencies
console.log('\n5. Checking dependencies...');
if (fs.existsSync('node_modules')) {
console.log(' ✅ node_modules exists');
} else {
console.log(' ❌ node_modules missing - run: npm install');
allGood = false;
}
// Check 6: Port availability
console.log('\n6. Checking port configuration...');
const port = process.env.PORT || 9222;
console.log(` ℹ️ Application will run on port ${port}`);
console.log(` ℹ️ Make sure to open firewall: sudo ufw allow ${port}/tcp`);
// Check 7: Slack webhook
console.log('\n7. Checking Slack webhook...');
const slackWebhook = process.env.SLACK_WEBHOOK_URL;
if (slackWebhook && slackWebhook.startsWith('https://hooks.slack.com/services/')) {
console.log(' ✅ Slack webhook URL looks valid');
} else {
console.log(' ❌ Slack webhook URL is not configured properly');
allGood = false;
}
// Summary
console.log('\n' + '='.repeat(50));
if (allGood) {
console.log('\n✅ All checks passed! You can start the application with:');
console.log(' npm start\n');
console.log(`📊 Access at: http://localhost:${port}`);
console.log(`🔐 Login: ${process.env.ADMIN_USER} / ${process.env.ADMIN_PASS}\n`);
} else {
console.log('\n❌ Some checks failed. Please fix the issues above before starting.\n');
console.log('📖 See SETUP.md for detailed setup instructions\n');
process.exit(1);
}