Files
kitchen-agent/test-utils.js
2025-10-23 19:02:56 -04:00

185 lines
4.7 KiB
JavaScript

/**
* Test utilities for Kitchen Agent
* Use these functions to manually test the system
*/
const database = require('./database');
// Initialize database first
database.init();
/**
* Insert a mock order for testing UI
*/
function insertMockOrder(orderId = null) {
const id = orderId || Math.floor(Math.random() * 10000);
const now = Math.floor(Date.now() / 1000);
const mockOrder = {
id: id,
botId: 1,
orderStatus: 'new',
order: {
type: Math.random() > 0.5 ? 'delivery' : 'pickup',
items: [
{
id: 1,
itemName: 'Cheeseburger',
qty: 2,
price: 12.99,
addons: [{ name: 'Extra Cheese', price: 1.00 }],
exclude: [{ name: 'Onions', price: 0 }]
},
{
id: 2,
itemName: 'French Fries',
qty: 1,
price: 4.99,
addons: [],
exclude: []
},
{
id: 3,
itemName: 'Coca-Cola',
qty: 2,
price: 2.50,
addons: [],
exclude: []
}
],
amount: 35.97,
taxRate: 8.5,
taxAmount: 3.06,
deliveryFee: 5.00,
totalAmount: 44.03,
deliveryAddress: '123 Main Street, Anytown, USA 12345',
deliveryInstructions: 'Ring doorbell, leave at door',
specialInstructions: 'Extra napkins please, no ketchup',
foodAllergy: Math.random() > 0.7,
foodAllergyNotes: 'Severe peanut allergy - please ensure no cross-contamination'
},
customer: {
id: 1,
name: 'John Doe',
phoneNumber: '+15551234567',
email: 'john.doe@example.com'
},
totalAmount: 44.03,
createdAt: now,
updatedAt: now
};
try {
database.insertOrder(mockOrder);
console.log(`✓ Mock order #${id} inserted successfully`);
return mockOrder;
} catch (error) {
console.error('Failed to insert mock order:', error.message);
return null;
}
}
/**
* Insert multiple mock orders
*/
function insertMultipleMockOrders(count = 5) {
console.log(`Inserting ${count} mock orders...`);
for (let i = 0; i < count; i++) {
const baseId = 10000 + i;
insertMockOrder(baseId);
}
console.log(`${count} mock orders inserted`);
}
/**
* Clear all orders from database (for testing)
*/
function clearAllOrders() {
try {
database.db.exec('DELETE FROM orders');
database.db.exec('DELETE FROM print_queue');
console.log('✓ All orders cleared');
} catch (error) {
console.error('Failed to clear orders:', error.message);
}
}
/**
* View current configuration
*/
function viewConfig() {
const config = database.getConfig();
console.log('\nCurrent Configuration:');
console.log('=====================');
for (const [key, value] of Object.entries(config)) {
if (key === 'authToken' && value) {
console.log(`${key}: [ENCRYPTED]`);
} else {
console.log(`${key}: ${value}`);
}
}
console.log('=====================\n');
}
/**
* View order statistics
*/
function viewStats() {
const stats = database.getOrderStats();
console.log('\nOrder Statistics:');
console.log('=================');
console.log(`Total Today: ${stats.total}`);
console.log(`New: ${stats.new}`);
console.log(`Preparing: ${stats.preparing}`);
console.log(`Ready: ${stats.ready}`);
console.log('=================\n');
}
/**
* List all orders
*/
function listOrders(limit = 10) {
const orders = database.getOrders({ limit });
console.log(`\nRecent Orders (${orders.length}):`);
console.log('===================');
orders.forEach(order => {
console.log(`#${order.id} | ${order.customer.name} | ${order.localStatus} | $${order.totalAmount.toFixed(2)}`);
});
console.log('===================\n');
}
// Export functions
module.exports = {
insertMockOrder,
insertMultipleMockOrders,
clearAllOrders,
viewConfig,
viewStats,
listOrders
};
// If run directly, show help
if (require.main === module) {
console.log('\nKitchen Agent Test Utilities');
console.log('============================\n');
console.log('Usage:');
console.log(' node test-utils.js\n');
console.log('Available in Node REPL:');
console.log(' const test = require("./test-utils");\n');
console.log(' test.insertMockOrder(); // Insert one mock order');
console.log(' test.insertMultipleMockOrders(5); // Insert 5 mock orders');
console.log(' test.listOrders(); // List recent orders');
console.log(' test.viewStats(); // View order statistics');
console.log(' test.viewConfig(); // View configuration');
console.log(' test.clearAllOrders(); // Clear all orders (careful!)\n');
// Show current stats
viewStats();
listOrders(5);
}