Files
PriceUpdaterAppv2/test-additional-price-cases.js
Spencer Grimes 1e6881ba86 Initial commit: Complete Shopify Price Updater implementation
- Full Node.js application with Shopify GraphQL API integration
- Compare At price support for promotional pricing
- Comprehensive error handling and retry logic
- Progress tracking with markdown logging
- Complete test suite with unit and integration tests
- Production-ready with proper exit codes and signal handling
2025-08-05 10:05:05 -05:00

62 lines
2.0 KiB
JavaScript

// Additional edge case tests for price utilities
const {
calculateNewPrice,
isValidPrice,
formatPrice,
calculatePercentageChange,
isValidPercentage,
} = require("./src/utils/price.js");
console.log("Testing Additional Edge Cases...\n");
// Test very small prices
console.log("=== Testing Small Prices ===");
console.log("1% increase on $0.01:", calculateNewPrice(0.01, 1)); // Should be 0.01
console.log("50% increase on $0.02:", calculateNewPrice(0.02, 50)); // Should be 0.03
// Test large prices
console.log("\n=== Testing Large Prices ===");
console.log("10% increase on $9999.99:", calculateNewPrice(9999.99, 10)); // Should be 10999.99
// Test decimal percentages
console.log("\n=== Testing Decimal Percentages ===");
console.log("0.5% increase on $100:", calculateNewPrice(100, 0.5)); // Should be 100.50
console.log("2.75% decrease on $80:", calculateNewPrice(80, -2.75)); // Should be 77.80
// Test rounding edge cases
console.log("\n=== Testing Rounding Edge Cases ===");
console.log("33.33% increase on $3:", calculateNewPrice(3, 33.33)); // Should round properly
console.log("Formatting 99.999:", formatPrice(99.999)); // Should be "100.00" due to rounding
// Test invalid inputs
console.log("\n=== Testing Invalid Inputs ===");
try {
calculateNewPrice(null, 10);
} catch (error) {
console.log("✓ Null price error:", error.message);
}
try {
calculateNewPrice(100, null);
} catch (error) {
console.log("✓ Null percentage error:", error.message);
}
try {
calculateNewPrice(100, Infinity);
} catch (error) {
console.log("✓ Infinity percentage handled");
}
// Test percentage change with zero
console.log("\n=== Testing Percentage Change Edge Cases ===");
try {
console.log("Change from $0 to $10:", calculatePercentageChange(0, 10)); // Should be Infinity
} catch (error) {
console.log("Zero base price handled:", error.message);
}
console.log("Change from $10 to $0:", calculatePercentageChange(10, 0)); // Should be -100
console.log("\n✓ Additional edge case tests completed!");