64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Test script to validate parsing against real API response
|
|
import fs from 'fs';
|
|
import { countAvailableItems, CONFIG } from './index.js';
|
|
|
|
console.log('🧪 Testing against real API response example...\n');
|
|
|
|
try {
|
|
// Read the example response
|
|
const exampleData = JSON.parse(fs.readFileSync('./example-response.json', 'utf8'));
|
|
|
|
console.log('📄 Loaded example-response.json');
|
|
console.log(`📊 Total bibItems in response: ${Object.keys(exampleData.entities.bibItems).length}`);
|
|
|
|
// Count available items
|
|
const availableCount = countAvailableItems(exampleData);
|
|
|
|
console.log(`\n🎯 Results:`);
|
|
console.log(` Available items at ${CONFIG.BRANCH_NAME}: ${availableCount}`);
|
|
|
|
// Show some details about Rancho Penasquitos items
|
|
console.log(`\n📋 Rancho Penasquitos items in response:`);
|
|
let totalRanchoPenasquitos = 0;
|
|
let availableRP = 0;
|
|
let checkedOutRP = 0;
|
|
|
|
const bibItems = exampleData.entities.bibItems;
|
|
for (const itemId in bibItems) {
|
|
const item = bibItems[itemId];
|
|
if (item.branchName?.includes(CONFIG.BRANCH_NAME)) {
|
|
totalRanchoPenasquitos++;
|
|
if (item.availability?.statusType !== 'UNAVAILABLE') {
|
|
availableRP++;
|
|
console.log(` ✅ ${itemId}: ${item.availability.statusType} (${item.availability.libraryStatus})`);
|
|
} else {
|
|
checkedOutRP++;
|
|
if (checkedOutRP <= 3) { // Only show first 3 to avoid spam
|
|
console.log(` ❌ ${itemId}: CHECKED OUT (due: ${item.dueDate || 'N/A'})`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (checkedOutRP > 3) {
|
|
console.log(` ... and ${checkedOutRP - 3} more checked out items`);
|
|
}
|
|
|
|
console.log(`\n📈 Summary:`);
|
|
console.log(` Total items at ${CONFIG.BRANCH_NAME}: ${totalRanchoPenasquitos}`);
|
|
console.log(` Available: ${availableRP}`);
|
|
console.log(` Checked out: ${checkedOutRP}`);
|
|
|
|
if (availableCount !== availableRP) {
|
|
console.log(`\n⚠️ Warning: Count mismatch! Function returned ${availableCount} but manual count is ${availableRP}`);
|
|
} else {
|
|
console.log(`\n✅ Count validation passed!`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
process.exit(1);
|
|
}
|