#!/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); }