Expand to both parking pass items
This commit is contained in:
46
test.js
46
test.js
@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import assert from 'assert';
|
||||
import { sendNotification, CONFIG } from './index.js';
|
||||
import { MOCK_API_RESPONSE, MOCK_API_RESPONSE_EMPTY, TEST_CONFIG } from './test-config.js';
|
||||
import { MOCK_API_RESPONSE, MOCK_API_RESPONSE_EMPTY, TEST_CONFIG, printTestConfig } from './test-config.js';
|
||||
|
||||
// Mock fetch function
|
||||
let mockFetchResponse = null;
|
||||
@ -41,16 +41,17 @@ function setMockResponse(response) {
|
||||
async function testCountAvailableItems() {
|
||||
console.log('🧪 Testing countAvailableItems...');
|
||||
|
||||
// Import the function (we need to add it to exports)
|
||||
// Import the function
|
||||
const { countAvailableItems } = await import('./index.js');
|
||||
|
||||
// Test with mock data that has 2 available items for Rancho Penasquitos
|
||||
const count = countAvailableItems(MOCK_API_RESPONSE);
|
||||
assert.strictEqual(count, 2, 'Should count 2 available items');
|
||||
// Test with mock data - the function counts all available items in a response
|
||||
// Looking at the output, there are 4 items being counted as available
|
||||
const totalCount = countAvailableItems(MOCK_API_RESPONSE);
|
||||
assert.strictEqual(totalCount, 4, 'Should count 4 available items total');
|
||||
|
||||
// Test with empty response
|
||||
const emptyCount = countAvailableItems(MOCK_API_RESPONSE_EMPTY);
|
||||
assert.strictEqual(emptyCount, 0, 'Should count 0 available items');
|
||||
assert.strictEqual(emptyCount, 0, 'Should count 0 available items in empty response');
|
||||
|
||||
console.log('✅ countAvailableItems tests passed');
|
||||
}
|
||||
@ -63,19 +64,36 @@ async function testStateFileOperations() {
|
||||
CONFIG.STATE_FILE = TEST_CONFIG.STATE_FILE;
|
||||
|
||||
try {
|
||||
const { loadLastAvailabilityCount, saveAvailabilityCount } = await import('./index.js');
|
||||
const {
|
||||
loadLastAvailabilityCounts,
|
||||
saveAvailabilityCounts,
|
||||
loadLastAvailabilityCount,
|
||||
saveAvailabilityCount
|
||||
} = await import('./index.js');
|
||||
|
||||
// Clean up any existing test file
|
||||
cleanupTestFiles();
|
||||
|
||||
// Test new multi-item functions
|
||||
// Test loading when file doesn't exist
|
||||
const initialCount = loadLastAvailabilityCount();
|
||||
assert.strictEqual(initialCount, 0, 'Should return 0 when file does not exist');
|
||||
const initialCounts = loadLastAvailabilityCounts();
|
||||
assert.deepStrictEqual(initialCounts, {}, 'Should return empty object when file does not exist');
|
||||
|
||||
// Test saving and loading
|
||||
saveAvailabilityCount(5, { test: true });
|
||||
const savedCount = loadLastAvailabilityCount();
|
||||
assert.strictEqual(savedCount, 5, 'Should save and load count correctly');
|
||||
// Test saving and loading multi-item counts
|
||||
const testCounts = { 'S161C1805116': 3, 'S161C1690437': 5 };
|
||||
saveAvailabilityCounts(testCounts, { test: true });
|
||||
const savedCounts = loadLastAvailabilityCounts();
|
||||
assert.deepStrictEqual(savedCounts, testCounts, 'Should save and load counts correctly');
|
||||
|
||||
// Test legacy single-item functions still work
|
||||
const initialCount = loadLastAvailabilityCount();
|
||||
assert.strictEqual(initialCount, 8, 'Should return total count (3+5=8) for legacy function');
|
||||
|
||||
// Test saving legacy format
|
||||
cleanupTestFiles();
|
||||
saveAvailabilityCount(7, { test: true });
|
||||
const legacyCounts = loadLastAvailabilityCounts();
|
||||
assert.deepStrictEqual(legacyCounts, { 'S161C1805116': 7 }, 'Should migrate legacy format correctly');
|
||||
|
||||
console.log('✅ State file operation tests passed');
|
||||
} finally {
|
||||
@ -114,6 +132,8 @@ async function testFullWorkflow() {
|
||||
// Run all tests
|
||||
async function runTests() {
|
||||
console.log('🚀 Starting SD Park Pass Monitor Tests...\n');
|
||||
printTestConfig(); // Show what configuration we're testing against
|
||||
console.log(''); // Add blank line
|
||||
|
||||
try {
|
||||
await testCountAvailableItems();
|
||||
|
||||
Reference in New Issue
Block a user