const ProgressService = require("./src/services/progress"); const fs = require("fs").promises; async function testProgressService() { console.log("Testing Progress Service..."); // Use a test file to avoid interfering with actual progress const testFilePath = "test-progress.md"; const progressService = new ProgressService(testFilePath); try { // Clean up any existing test file try { await fs.unlink(testFilePath); } catch (error) { // File doesn't exist, that's fine } // Test 1: Log operation start console.log("✓ Testing operation start logging..."); await progressService.logOperationStart({ targetTag: "test-tag", priceAdjustmentPercentage: 10, }); // Test 2: Log successful product update console.log("✓ Testing product update logging..."); await progressService.logProductUpdate({ productId: "gid://shopify/Product/123", productTitle: "Test Product", variantId: "gid://shopify/ProductVariant/456", oldPrice: 10.0, newPrice: 11.0, }); // Test 3: Log error console.log("✓ Testing error logging..."); await progressService.logError({ productId: "gid://shopify/Product/789", productTitle: "Failed Product", variantId: "gid://shopify/ProductVariant/101", errorMessage: "Invalid price data", }); // Test 4: Log completion summary console.log("✓ Testing completion summary..."); await progressService.logCompletionSummary({ totalProducts: 2, successfulUpdates: 1, failedUpdates: 1, startTime: new Date(Date.now() - 5000), // 5 seconds ago }); // Verify file was created and has content const content = await fs.readFile(testFilePath, "utf8"); console.log("✓ Progress file created successfully"); console.log("✓ File contains:", content.length, "characters"); // Test timestamp formatting const timestamp = progressService.formatTimestamp( new Date("2024-01-01T12:00:00.000Z") ); console.log("✓ Timestamp format test:", timestamp); // Clean up test file await fs.unlink(testFilePath); console.log("✓ Test file cleaned up"); console.log("\n🎉 All Progress Service tests passed!"); } catch (error) { console.error("❌ Test failed:", error.message); // Clean up test file even if tests fail try { await fs.unlink(testFilePath); } catch (cleanupError) { // Ignore cleanup errors } } } testProgressService();