diff --git a/tests/integration/cleaner.test.ts b/tests/integration/cleaner.test.ts index 71150e3..b8e40af 100644 --- a/tests/integration/cleaner.test.ts +++ b/tests/integration/cleaner.test.ts @@ -21,12 +21,7 @@ describe('Cleaner Service (Integration)', () => { const hasCredentials = !!(config.url && config.username && config.password) describe('Dry-run mode', () => { - it('should initialize with dry-run mode', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should initialize with dry-run mode', async () => { const authService = new ErpAuthService(config) await authService.login() @@ -37,64 +32,58 @@ describe('Cleaner Service (Integration)', () => { await authService.close() }, 30000) - it('should track materials to delete without actually deleting (dry-run)', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } + it.skipIf(!hasCredentials)( + 'should track materials to delete without actually deleting (dry-run)', + async () => { + const authService = new ErpAuthService(config) + await authService.login() - const authService = new ErpAuthService(config) - await authService.login() + // Read test data + const orderContent = await fs.readFile(productionIdFile, 'utf-8') + const orderNumbers = orderContent + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.length > 0) + .slice(0, 2) // Test first 2 orders - // Read test data - const orderContent = await fs.readFile(productionIdFile, 'utf-8') - const orderNumbers = orderContent - .split('\n') - .map((line) => line.trim()) - .filter((line) => line.length > 0) - .slice(0, 2) // Test first 2 orders + const materialContent = await fs.readFile(materialCodeFile, 'utf-8') + const materialCodes = materialContent + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.length > 0) - const materialContent = await fs.readFile(materialCodeFile, 'utf-8') - const materialCodes = materialContent - .split('\n') - .map((line) => line.trim()) - .filter((line) => line.length > 0) + console.log( + `Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes` + ) - console.log( - `Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes` - ) + const cleaner = new CleanerService(authService, { dryRun: true }) - const cleaner = new CleanerService(authService, { dryRun: true }) + const result = await cleaner.clean({ + orderNumbers, + materialCodes, + dryRun: true + }) - const result = await cleaner.clean({ - orderNumbers, - materialCodes, - dryRun: true - }) + // In dry-run mode, materialsDeleted should be tracked but not actually deleted + console.log(`Dry-run result:`, { + ordersProcessed: result.ordersProcessed, + materialsDeleted: result.materialsDeleted, + materialsSkipped: result.materialsSkipped, + errors: result.errors.length + }) - // In dry-run mode, materialsDeleted should be tracked but not actually deleted - console.log(`Dry-run result:`, { - ordersProcessed: result.ordersProcessed, - materialsDeleted: result.materialsDeleted, - materialsSkipped: result.materialsSkipped, - errors: result.errors.length - }) + expect(result.ordersProcessed).toBeGreaterThan(0) + // In dry-run, no actual deletions should happen + expect(result.errors).toHaveLength(0) - expect(result.ordersProcessed).toBeGreaterThan(0) - // In dry-run, no actual deletions should happen - expect(result.errors).toHaveLength(0) - - await authService.close() - }, 120000) + await authService.close() + }, + 120000 + ) }) describe('Order processing', () => { - it('should process single order and return details', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should process single order and return details', async () => { const authService = new ErpAuthService(config) await authService.login() @@ -120,12 +109,7 @@ describe('Cleaner Service (Integration)', () => { await authService.close() }, 60000) - it('should handle order with "审批通过" status', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should handle order with "审批通过" status', async () => { const authService = new ErpAuthService(config) await authService.login() @@ -155,12 +139,7 @@ describe('Cleaner Service (Integration)', () => { await authService.close() }, 60000) - it('should handle multiple orders with progress callback', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should handle multiple orders with progress callback', async () => { const authService = new ErpAuthService(config) await authService.login() @@ -194,12 +173,7 @@ describe('Cleaner Service (Integration)', () => { }) describe('Error handling', () => { - it('should continue processing after order error', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should continue processing after order error', async () => { const authService = new ErpAuthService(config) await authService.login() @@ -221,27 +195,26 @@ describe('Cleaner Service (Integration)', () => { }) describe('Navigation', () => { - it('should navigate to discrete production order maintenance page', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } + it.skipIf(!hasCredentials)( + 'should navigate to discrete production order maintenance page', + async () => { + const authService = new ErpAuthService(config) + await authService.login() - const authService = new ErpAuthService(config) - await authService.login() + const cleaner = new CleanerService(authService, { dryRun: true }) - const cleaner = new CleanerService(authService, { dryRun: true }) + // This tests the internal navigation method + const session = authService.getSession() + const { popupPage, workFrame } = await cleaner.navigateToCleanerPage(session) - // This tests the internal navigation method - const session = authService.getSession() - const { popupPage, workFrame } = await cleaner.navigateToCleanerPage(session) + expect(popupPage).toBeDefined() + expect(workFrame).toBeDefined() - expect(popupPage).toBeDefined() - expect(workFrame).toBeDefined() - - // Cleanup - await popupPage.close() - await authService.close() - }, 60000) + // Cleanup + await popupPage.close() + await authService.close() + }, + 60000 + ) }) }) diff --git a/tests/integration/erp-auth.test.ts b/tests/integration/erp-auth.test.ts index 30332ce..bc6b71e 100644 --- a/tests/integration/erp-auth.test.ts +++ b/tests/integration/erp-auth.test.ts @@ -15,19 +15,11 @@ describe('ERP Authentication Service (Integration)', () => { const hasCredentials = !!(config.url && config.username && config.password) beforeAll(() => { - if (!hasCredentials) { - console.warn('Skipping ERP auth tests: credentials not configured') - return - } + if (!hasCredentials) return authService = new ErpAuthService(config) }) - it('should login successfully', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should login successfully', async () => { const session = await authService.login() expect(session).toBeDefined() @@ -37,12 +29,7 @@ describe('ERP Authentication Service (Integration)', () => { expect(session.isLoggedIn).toBe(true) }, 30000) - it('should navigate to main page after login', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should navigate to main page after login', async () => { const session = await authService.login() const url = session.page.url() diff --git a/tests/integration/extractor.test.ts b/tests/integration/extractor.test.ts index b475883..f1dbf16 100644 --- a/tests/integration/extractor.test.ts +++ b/tests/integration/extractor.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, afterAll } from 'vitest' +import { describe, it, expect } from 'vitest' import { ExtractorService } from '../../src/main/services/erp/extractor' import { ErpAuthService } from '../../src/main/services/erp/erp-auth' import type { ErpConfig } from '../../src/main/types/erp.types' @@ -18,12 +18,7 @@ describe('Extractor Service (Integration)', () => { // Check if we have ERP credentials const hasCredentials = !!(config.url && config.username && config.password) - it('should extract data for single order number', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should extract data for single order number', async () => { // Create fresh auth service for this test const authService = new ErpAuthService(config) await authService.login() @@ -46,12 +41,7 @@ describe('Extractor Service (Integration)', () => { await authService.close() }, 60000) - it('should extract data for multiple order numbers', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should extract data for multiple order numbers', async () => { // Create fresh auth service for this test const authService = new ErpAuthService(config) await authService.login() @@ -59,10 +49,6 @@ describe('Extractor Service (Integration)', () => { const extractor = new ExtractorService(authService) // Read order numbers from productionID.txt file - const fs = await import('fs/promises') - const path = await import('path') - // productionID.txt is at: D:\FileLib\Projects\CodeMigration\references\demo\productionID.txt - // test runs at: D:\FileLib\Projects\CodeMigration\ERPAuto const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt') const content = await fs.readFile(productionIdFile, 'utf-8') const orderNumbers = content @@ -89,12 +75,7 @@ describe('Extractor Service (Integration)', () => { await authService.close() }, 120000) // Increase timeout to 2 minutes - it('should extract data for 300 orders with batch size 70', async () => { - if (!hasCredentials) { - console.warn('Skipping test: ERP credentials not configured') - return - } - + it.skipIf(!hasCredentials)('should extract data for 300 orders with batch size 70', async () => { // Create fresh auth service for this test const authService = new ErpAuthService(config) await authService.login() @@ -102,8 +83,6 @@ describe('Extractor Service (Integration)', () => { const extractor = new ExtractorService(authService) // Read all order numbers from productionID.txt file - const fs = await import('fs/promises') - const path = await import('path') const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt') const content = await fs.readFile(productionIdFile, 'utf-8') const orderNumbers = content @@ -130,7 +109,9 @@ describe('Extractor Service (Integration)', () => { console.log(`Expected batches: ${Math.ceil(orderNumbers.length / 70)}`) console.log(`Downloaded files: ${result.downloadedFiles.length}`) console.log(`Total duration: ${duration}s`) - console.log(`Average time per batch: ${(duration / result.downloadedFiles.length).toFixed(2)}s`) + console.log( + `Average time per batch: ${(duration / result.downloadedFiles.length).toFixed(2)}s` + ) if (result.errors.length > 0) { console.log(`\nErrors encountered: ${result.errors.length}`) diff --git a/tests/unit/audit-logger.test.ts b/tests/unit/audit-logger.test.ts index 23b70f4..463531e 100644 --- a/tests/unit/audit-logger.test.ts +++ b/tests/unit/audit-logger.test.ts @@ -118,9 +118,11 @@ describe('Audit Logger - Real File Integration', () => { }) it('should handle all status values (success, failure, partial)', async () => { - const { logAudit, closeAuditLogger } = + const { logAudit, closeAuditLogger, applyAuditConfig } = await import('../../src/main/services/logger/audit-logger') + applyAuditConfig(30) + // Test success status logAudit('EXTRACT', 'user1', { username: 'extractor', @@ -149,14 +151,16 @@ describe('Audit Logger - Real File Integration', () => { closeAuditLogger() - // Verify all entries were processed - expect(true).toBe(true) // Logger accepted all status types without error + // Verify logAudit executed for each entry (each call invokes app.getVersion) + expect(app.getVersion).toHaveBeenCalledTimes(3) }) it('should handle metadata correctly (with and without)', async () => { - const { logAudit, closeAuditLogger } = + const { logAudit, closeAuditLogger, applyAuditConfig } = await import('../../src/main/services/logger/audit-logger') + applyAuditConfig(30) + // Without metadata logAudit('LOGIN', 'user-no-meta', { username: 'no.meta', @@ -176,8 +180,8 @@ describe('Audit Logger - Real File Integration', () => { closeAuditLogger() - // Both entries should be processed successfully - expect(true).toBe(true) + // Both entries processed (each call invokes app.getVersion) + expect(app.getVersion).toHaveBeenCalledTimes(2) }) it('should generate ISO 8601 timestamp', async () => { @@ -209,9 +213,11 @@ describe('Audit Logger - Real File Integration', () => { }) it('should handle special characters in fields', async () => { - const { logAudit, closeAuditLogger } = + const { logAudit, closeAuditLogger, applyAuditConfig } = await import('../../src/main/services/logger/audit-logger') + applyAuditConfig(30) + logAudit('LOGIN_ATTEMPT', 'user-special', { username: 'user.name+test@example.com', computerName: 'DESKTOP-特殊字符-001', @@ -222,14 +228,16 @@ describe('Audit Logger - Real File Integration', () => { closeAuditLogger() - // Should handle without errors - expect(true).toBe(true) + // Verify special characters were processed without error + expect(app.getVersion).toHaveBeenCalledTimes(1) }) it('should handle empty metadata gracefully', async () => { - const { logAudit, closeAuditLogger } = + const { logAudit, closeAuditLogger, applyAuditConfig } = await import('../../src/main/services/logger/audit-logger') + applyAuditConfig(30) + logAudit('PING', 'ping-user', { username: 'pinger', computerName: 'PC-PING', @@ -240,7 +248,7 @@ describe('Audit Logger - Real File Integration', () => { closeAuditLogger() - // Should handle empty metadata - expect(true).toBe(true) + // Verify empty metadata was processed without error + expect(app.getVersion).toHaveBeenCalledTimes(1) }) }) diff --git a/tests/unit/update-service.test.ts b/tests/unit/update-service.test.ts index fe575a3..477ca13 100644 --- a/tests/unit/update-service.test.ts +++ b/tests/unit/update-service.test.ts @@ -146,9 +146,8 @@ describe('UpdateService', () => { // Note: This integration scenario is complex to test in unit tests. // Moved to integration tests: tests/integration/update-workflow.test.ts - // Skip this test as it requires real integration testing it.skip('checks updates for user and auto-downloads available recommendation', async () => { - expect(true).toBe(true) // Placeholder - see integration tests + // Covered by integration tests }) it('returns disabled catalog when update services are unavailable', async () => {