119 lines
4.3 KiB
JavaScript
119 lines
4.3 KiB
JavaScript
import mongoose from "mongoose";
|
|
import dotenv from "dotenv";
|
|
|
|
dotenv.config();
|
|
|
|
const MONGODB_URI =
|
|
process.env.MONGODB_URI || "mongodb://localhost:27017/turbotrades";
|
|
|
|
console.log("\n╔═══════════════════════════════════════════════╗");
|
|
console.log("║ Test Item Price Lookup Script ║");
|
|
console.log("╚═══════════════════════════════════════════════╝\n");
|
|
|
|
async function testPrices() {
|
|
try {
|
|
// Connect to MongoDB
|
|
console.log("🔌 Connecting to MongoDB...");
|
|
await mongoose.connect(MONGODB_URI);
|
|
console.log("✅ Connected to database\n");
|
|
|
|
const MarketPrice = (await import("./models/MarketPrice.js")).default;
|
|
|
|
// Test items - common CS2 items
|
|
const testItems = [
|
|
"AK-47 | Redline (Field-Tested)",
|
|
"AWP | Asiimov (Field-Tested)",
|
|
"M4A4 | Howl (Factory New)",
|
|
"Desert Eagle | Blaze (Factory New)",
|
|
"Glock-18 | Fade (Factory New)",
|
|
"Karambit | Fade (Factory New)",
|
|
"AK-47 | Fire Serpent (Minimal Wear)",
|
|
"AWP | Dragon Lore (Factory New)",
|
|
];
|
|
|
|
console.log("🔍 Testing common item names...\n");
|
|
console.log("─────────────────────────────────────────────────\n");
|
|
|
|
for (const itemName of testItems) {
|
|
const result = await MarketPrice.findOne({
|
|
$or: [
|
|
{ name: itemName },
|
|
{ marketHashName: itemName },
|
|
{ name: { $regex: itemName.split("(")[0].trim(), $options: "i" } },
|
|
],
|
|
game: "cs2",
|
|
});
|
|
|
|
if (result) {
|
|
console.log(`✅ FOUND: ${itemName}`);
|
|
console.log(` Price: $${result.price.toFixed(2)}`);
|
|
console.log(` DB Name: ${result.name}`);
|
|
console.log(` Hash: ${result.marketHashName}`);
|
|
} else {
|
|
console.log(`❌ NOT FOUND: ${itemName}`);
|
|
}
|
|
console.log();
|
|
}
|
|
|
|
console.log("─────────────────────────────────────────────────\n");
|
|
|
|
// Search for partial matches
|
|
console.log("🔍 Searching for 'AK-47' items in database...\n");
|
|
const ak47Items = await MarketPrice.find({
|
|
name: { $regex: "AK-47", $options: "i" },
|
|
game: "cs2",
|
|
})
|
|
.limit(5)
|
|
.sort({ price: -1 });
|
|
|
|
ak47Items.forEach((item, i) => {
|
|
console.log(`${i + 1}. ${item.name}`);
|
|
console.log(` Price: $${item.price.toFixed(2)}`);
|
|
console.log(` Market Hash: ${item.marketHashName}\n`);
|
|
});
|
|
|
|
console.log("─────────────────────────────────────────────────\n");
|
|
|
|
// Get total count
|
|
const totalCS2 = await MarketPrice.countDocuments({ game: "cs2" });
|
|
const totalRust = await MarketPrice.countDocuments({ game: "rust" });
|
|
|
|
console.log("📊 Database Statistics:\n");
|
|
console.log(` CS2 Items: ${totalCS2}`);
|
|
console.log(` Rust Items: ${totalRust}`);
|
|
console.log(` Total: ${totalCS2 + totalRust}\n`);
|
|
|
|
// Sample some items from DB
|
|
console.log("─────────────────────────────────────────────────\n");
|
|
console.log("💎 Sample items from database (highest priced):\n");
|
|
|
|
const topItems = await MarketPrice.find({ game: "cs2" })
|
|
.sort({ price: -1 })
|
|
.limit(10);
|
|
|
|
topItems.forEach((item, i) => {
|
|
console.log(`${i + 1}. ${item.name}`);
|
|
console.log(` $${item.price.toFixed(2)}\n`);
|
|
});
|
|
|
|
console.log("═════════════════════════════════════════════════\n");
|
|
console.log("✅ Test complete!\n");
|
|
|
|
await mongoose.disconnect();
|
|
console.log("👋 Disconnected from database\n");
|
|
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error("\n❌ ERROR:", error.message);
|
|
console.error(error.stack);
|
|
|
|
if (mongoose.connection.readyState === 1) {
|
|
await mongoose.disconnect();
|
|
}
|
|
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
testPrices();
|