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
This commit is contained in:
2025-08-05 10:05:05 -05:00
commit 1e6881ba86
29 changed files with 10663 additions and 0 deletions

66
test-price-utils.js Normal file
View File

@@ -0,0 +1,66 @@
// Quick test script for price utilities
const {
calculateNewPrice,
isValidPrice,
formatPrice,
calculatePercentageChange,
isValidPercentage,
} = require("./src/utils/price.js");
console.log("Testing Price Utilities...\n");
// Test calculateNewPrice
console.log("=== Testing calculateNewPrice ===");
try {
console.log("10% increase on $100:", calculateNewPrice(100, 10)); // Should be 110
console.log("20% decrease on $50:", calculateNewPrice(50, -20)); // Should be 40
console.log("5.5% increase on $29.99:", calculateNewPrice(29.99, 5.5)); // Should be 31.64
console.log("0% change on $25:", calculateNewPrice(25, 0)); // Should be 25
console.log("Zero price with 10% increase:", calculateNewPrice(0, 10)); // Should be 0
} catch (error) {
console.error("Error:", error.message);
}
// Test edge cases
console.log("\n=== Testing Edge Cases ===");
try {
console.log("Negative price test (should throw error):");
calculateNewPrice(-10, 10);
} catch (error) {
console.log("✓ Correctly caught negative price error:", error.message);
}
try {
console.log("Large decrease test (should throw error):");
calculateNewPrice(10, -150); // 150% decrease would make price negative
} catch (error) {
console.log("✓ Correctly caught negative result error:", error.message);
}
// Test validation functions
console.log("\n=== Testing Validation Functions ===");
console.log("isValidPrice(100):", isValidPrice(100)); // true
console.log("isValidPrice(-10):", isValidPrice(-10)); // false
console.log('isValidPrice("abc"):', isValidPrice("abc")); // false
console.log("isValidPrice(0):", isValidPrice(0)); // true
console.log("isValidPercentage(10):", isValidPercentage(10)); // true
console.log("isValidPercentage(-20):", isValidPercentage(-20)); // true
console.log('isValidPercentage("abc"):', isValidPercentage("abc")); // false
// Test formatting
console.log("\n=== Testing Price Formatting ===");
console.log("formatPrice(29.99):", formatPrice(29.99)); // "29.99"
console.log("formatPrice(100):", formatPrice(100)); // "100.00"
console.log("formatPrice(0):", formatPrice(0)); // "0.00"
// Test percentage change calculation
console.log("\n=== Testing Percentage Change Calculation ===");
console.log("Change from $100 to $110:", calculatePercentageChange(100, 110)); // 10
console.log("Change from $50 to $40:", calculatePercentageChange(50, 40)); // -20
console.log(
"Change from $29.99 to $31.64:",
calculatePercentageChange(29.99, 31.64)
); // ~5.5
console.log("\n✓ All tests completed!");