fix(test): replace meaningless assertions and silent skips with proper test semantics
- Replace 4x expect(true).toBe(true) in audit-logger.test.ts with
applyAuditConfig() + app.getVersion call count assertions
- Replace if(!hasCredentials){return} pattern with it.skipIf() in
3 integration test files (cleaner, erp-auth, extractor) so Vitest
correctly reports 12 tests as "skipped" instead of "passed"
- Remove placeholder assertion from skipped update-service test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,12 +21,7 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
const hasCredentials = !!(config.url && config.username && config.password)
|
const hasCredentials = !!(config.url && config.username && config.password)
|
||||||
|
|
||||||
describe('Dry-run mode', () => {
|
describe('Dry-run mode', () => {
|
||||||
it('should initialize with dry-run mode', async () => {
|
it.skipIf(!hasCredentials)('should initialize with dry-run mode', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
|
|
||||||
@@ -37,64 +32,58 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
await authService.close()
|
await authService.close()
|
||||||
}, 30000)
|
}, 30000)
|
||||||
|
|
||||||
it('should track materials to delete without actually deleting (dry-run)', async () => {
|
it.skipIf(!hasCredentials)(
|
||||||
if (!hasCredentials) {
|
'should track materials to delete without actually deleting (dry-run)',
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
async () => {
|
||||||
return
|
const authService = new ErpAuthService(config)
|
||||||
}
|
await authService.login()
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
// Read test data
|
||||||
await authService.login()
|
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 materialContent = await fs.readFile(materialCodeFile, 'utf-8')
|
||||||
const orderContent = await fs.readFile(productionIdFile, 'utf-8')
|
const materialCodes = materialContent
|
||||||
const orderNumbers = orderContent
|
.split('\n')
|
||||||
.split('\n')
|
.map((line) => line.trim())
|
||||||
.map((line) => line.trim())
|
.filter((line) => line.length > 0)
|
||||||
.filter((line) => line.length > 0)
|
|
||||||
.slice(0, 2) // Test first 2 orders
|
|
||||||
|
|
||||||
const materialContent = await fs.readFile(materialCodeFile, 'utf-8')
|
console.log(
|
||||||
const materialCodes = materialContent
|
`Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes`
|
||||||
.split('\n')
|
)
|
||||||
.map((line) => line.trim())
|
|
||||||
.filter((line) => line.length > 0)
|
|
||||||
|
|
||||||
console.log(
|
const cleaner = new CleanerService(authService, { dryRun: true })
|
||||||
`Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes`
|
|
||||||
)
|
|
||||||
|
|
||||||
const cleaner = new CleanerService(authService, { dryRun: true })
|
const result = await cleaner.clean({
|
||||||
|
orderNumbers,
|
||||||
|
materialCodes,
|
||||||
|
dryRun: true
|
||||||
|
})
|
||||||
|
|
||||||
const result = await cleaner.clean({
|
// In dry-run mode, materialsDeleted should be tracked but not actually deleted
|
||||||
orderNumbers,
|
console.log(`Dry-run result:`, {
|
||||||
materialCodes,
|
ordersProcessed: result.ordersProcessed,
|
||||||
dryRun: true
|
materialsDeleted: result.materialsDeleted,
|
||||||
})
|
materialsSkipped: result.materialsSkipped,
|
||||||
|
errors: result.errors.length
|
||||||
|
})
|
||||||
|
|
||||||
// In dry-run mode, materialsDeleted should be tracked but not actually deleted
|
expect(result.ordersProcessed).toBeGreaterThan(0)
|
||||||
console.log(`Dry-run result:`, {
|
// In dry-run, no actual deletions should happen
|
||||||
ordersProcessed: result.ordersProcessed,
|
expect(result.errors).toHaveLength(0)
|
||||||
materialsDeleted: result.materialsDeleted,
|
|
||||||
materialsSkipped: result.materialsSkipped,
|
|
||||||
errors: result.errors.length
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.ordersProcessed).toBeGreaterThan(0)
|
await authService.close()
|
||||||
// In dry-run, no actual deletions should happen
|
},
|
||||||
expect(result.errors).toHaveLength(0)
|
120000
|
||||||
|
)
|
||||||
await authService.close()
|
|
||||||
}, 120000)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Order processing', () => {
|
describe('Order processing', () => {
|
||||||
it('should process single order and return details', async () => {
|
it.skipIf(!hasCredentials)('should process single order and return details', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
|
|
||||||
@@ -120,12 +109,7 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
await authService.close()
|
await authService.close()
|
||||||
}, 60000)
|
}, 60000)
|
||||||
|
|
||||||
it('should handle order with "审批通过" status', async () => {
|
it.skipIf(!hasCredentials)('should handle order with "审批通过" status', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
|
|
||||||
@@ -155,12 +139,7 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
await authService.close()
|
await authService.close()
|
||||||
}, 60000)
|
}, 60000)
|
||||||
|
|
||||||
it('should handle multiple orders with progress callback', async () => {
|
it.skipIf(!hasCredentials)('should handle multiple orders with progress callback', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
|
|
||||||
@@ -194,12 +173,7 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Error handling', () => {
|
describe('Error handling', () => {
|
||||||
it('should continue processing after order error', async () => {
|
it.skipIf(!hasCredentials)('should continue processing after order error', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
|
|
||||||
@@ -221,27 +195,26 @@ describe('Cleaner Service (Integration)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Navigation', () => {
|
describe('Navigation', () => {
|
||||||
it('should navigate to discrete production order maintenance page', async () => {
|
it.skipIf(!hasCredentials)(
|
||||||
if (!hasCredentials) {
|
'should navigate to discrete production order maintenance page',
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
async () => {
|
||||||
return
|
const authService = new ErpAuthService(config)
|
||||||
}
|
await authService.login()
|
||||||
|
|
||||||
const authService = new ErpAuthService(config)
|
const cleaner = new CleanerService(authService, { dryRun: true })
|
||||||
await authService.login()
|
|
||||||
|
|
||||||
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
|
expect(popupPage).toBeDefined()
|
||||||
const session = authService.getSession()
|
expect(workFrame).toBeDefined()
|
||||||
const { popupPage, workFrame } = await cleaner.navigateToCleanerPage(session)
|
|
||||||
|
|
||||||
expect(popupPage).toBeDefined()
|
// Cleanup
|
||||||
expect(workFrame).toBeDefined()
|
await popupPage.close()
|
||||||
|
await authService.close()
|
||||||
// Cleanup
|
},
|
||||||
await popupPage.close()
|
60000
|
||||||
await authService.close()
|
)
|
||||||
}, 60000)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,19 +15,11 @@ describe('ERP Authentication Service (Integration)', () => {
|
|||||||
const hasCredentials = !!(config.url && config.username && config.password)
|
const hasCredentials = !!(config.url && config.username && config.password)
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
if (!hasCredentials) {
|
if (!hasCredentials) return
|
||||||
console.warn('Skipping ERP auth tests: credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
authService = new ErpAuthService(config)
|
authService = new ErpAuthService(config)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should login successfully', async () => {
|
it.skipIf(!hasCredentials)('should login successfully', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const session = await authService.login()
|
const session = await authService.login()
|
||||||
|
|
||||||
expect(session).toBeDefined()
|
expect(session).toBeDefined()
|
||||||
@@ -37,12 +29,7 @@ describe('ERP Authentication Service (Integration)', () => {
|
|||||||
expect(session.isLoggedIn).toBe(true)
|
expect(session.isLoggedIn).toBe(true)
|
||||||
}, 30000)
|
}, 30000)
|
||||||
|
|
||||||
it('should navigate to main page after login', async () => {
|
it.skipIf(!hasCredentials)('should navigate to main page after login', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const session = await authService.login()
|
const session = await authService.login()
|
||||||
|
|
||||||
const url = session.page.url()
|
const url = session.page.url()
|
||||||
|
|||||||
@@ -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 { ExtractorService } from '../../src/main/services/erp/extractor'
|
||||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
||||||
import type { ErpConfig } from '../../src/main/types/erp.types'
|
import type { ErpConfig } from '../../src/main/types/erp.types'
|
||||||
@@ -18,12 +18,7 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
// Check if we have ERP credentials
|
// Check if we have ERP credentials
|
||||||
const hasCredentials = !!(config.url && config.username && config.password)
|
const hasCredentials = !!(config.url && config.username && config.password)
|
||||||
|
|
||||||
it('should extract data for single order number', async () => {
|
it.skipIf(!hasCredentials)('should extract data for single order number', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create fresh auth service for this test
|
// Create fresh auth service for this test
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
@@ -46,12 +41,7 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
await authService.close()
|
await authService.close()
|
||||||
}, 60000)
|
}, 60000)
|
||||||
|
|
||||||
it('should extract data for multiple order numbers', async () => {
|
it.skipIf(!hasCredentials)('should extract data for multiple order numbers', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create fresh auth service for this test
|
// Create fresh auth service for this test
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
@@ -59,10 +49,6 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
const extractor = new ExtractorService(authService)
|
const extractor = new ExtractorService(authService)
|
||||||
|
|
||||||
// Read order numbers from productionID.txt file
|
// 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 productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
|
||||||
const content = await fs.readFile(productionIdFile, 'utf-8')
|
const content = await fs.readFile(productionIdFile, 'utf-8')
|
||||||
const orderNumbers = content
|
const orderNumbers = content
|
||||||
@@ -89,12 +75,7 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
await authService.close()
|
await authService.close()
|
||||||
}, 120000) // Increase timeout to 2 minutes
|
}, 120000) // Increase timeout to 2 minutes
|
||||||
|
|
||||||
it('should extract data for 300 orders with batch size 70', async () => {
|
it.skipIf(!hasCredentials)('should extract data for 300 orders with batch size 70', async () => {
|
||||||
if (!hasCredentials) {
|
|
||||||
console.warn('Skipping test: ERP credentials not configured')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create fresh auth service for this test
|
// Create fresh auth service for this test
|
||||||
const authService = new ErpAuthService(config)
|
const authService = new ErpAuthService(config)
|
||||||
await authService.login()
|
await authService.login()
|
||||||
@@ -102,8 +83,6 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
const extractor = new ExtractorService(authService)
|
const extractor = new ExtractorService(authService)
|
||||||
|
|
||||||
// Read all order numbers from productionID.txt file
|
// 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 productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
|
||||||
const content = await fs.readFile(productionIdFile, 'utf-8')
|
const content = await fs.readFile(productionIdFile, 'utf-8')
|
||||||
const orderNumbers = content
|
const orderNumbers = content
|
||||||
@@ -130,7 +109,9 @@ describe('Extractor Service (Integration)', () => {
|
|||||||
console.log(`Expected batches: ${Math.ceil(orderNumbers.length / 70)}`)
|
console.log(`Expected batches: ${Math.ceil(orderNumbers.length / 70)}`)
|
||||||
console.log(`Downloaded files: ${result.downloadedFiles.length}`)
|
console.log(`Downloaded files: ${result.downloadedFiles.length}`)
|
||||||
console.log(`Total duration: ${duration}s`)
|
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) {
|
if (result.errors.length > 0) {
|
||||||
console.log(`\nErrors encountered: ${result.errors.length}`)
|
console.log(`\nErrors encountered: ${result.errors.length}`)
|
||||||
|
|||||||
@@ -118,9 +118,11 @@ describe('Audit Logger - Real File Integration', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should handle all status values (success, failure, partial)', async () => {
|
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')
|
await import('../../src/main/services/logger/audit-logger')
|
||||||
|
|
||||||
|
applyAuditConfig(30)
|
||||||
|
|
||||||
// Test success status
|
// Test success status
|
||||||
logAudit('EXTRACT', 'user1', {
|
logAudit('EXTRACT', 'user1', {
|
||||||
username: 'extractor',
|
username: 'extractor',
|
||||||
@@ -149,14 +151,16 @@ describe('Audit Logger - Real File Integration', () => {
|
|||||||
|
|
||||||
closeAuditLogger()
|
closeAuditLogger()
|
||||||
|
|
||||||
// Verify all entries were processed
|
// Verify logAudit executed for each entry (each call invokes app.getVersion)
|
||||||
expect(true).toBe(true) // Logger accepted all status types without error
|
expect(app.getVersion).toHaveBeenCalledTimes(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle metadata correctly (with and without)', async () => {
|
it('should handle metadata correctly (with and without)', async () => {
|
||||||
const { logAudit, closeAuditLogger } =
|
const { logAudit, closeAuditLogger, applyAuditConfig } =
|
||||||
await import('../../src/main/services/logger/audit-logger')
|
await import('../../src/main/services/logger/audit-logger')
|
||||||
|
|
||||||
|
applyAuditConfig(30)
|
||||||
|
|
||||||
// Without metadata
|
// Without metadata
|
||||||
logAudit('LOGIN', 'user-no-meta', {
|
logAudit('LOGIN', 'user-no-meta', {
|
||||||
username: 'no.meta',
|
username: 'no.meta',
|
||||||
@@ -176,8 +180,8 @@ describe('Audit Logger - Real File Integration', () => {
|
|||||||
|
|
||||||
closeAuditLogger()
|
closeAuditLogger()
|
||||||
|
|
||||||
// Both entries should be processed successfully
|
// Both entries processed (each call invokes app.getVersion)
|
||||||
expect(true).toBe(true)
|
expect(app.getVersion).toHaveBeenCalledTimes(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should generate ISO 8601 timestamp', async () => {
|
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 () => {
|
it('should handle special characters in fields', async () => {
|
||||||
const { logAudit, closeAuditLogger } =
|
const { logAudit, closeAuditLogger, applyAuditConfig } =
|
||||||
await import('../../src/main/services/logger/audit-logger')
|
await import('../../src/main/services/logger/audit-logger')
|
||||||
|
|
||||||
|
applyAuditConfig(30)
|
||||||
|
|
||||||
logAudit('LOGIN_ATTEMPT', 'user-special', {
|
logAudit('LOGIN_ATTEMPT', 'user-special', {
|
||||||
username: 'user.name+test@example.com',
|
username: 'user.name+test@example.com',
|
||||||
computerName: 'DESKTOP-特殊字符-001',
|
computerName: 'DESKTOP-特殊字符-001',
|
||||||
@@ -222,14 +228,16 @@ describe('Audit Logger - Real File Integration', () => {
|
|||||||
|
|
||||||
closeAuditLogger()
|
closeAuditLogger()
|
||||||
|
|
||||||
// Should handle without errors
|
// Verify special characters were processed without error
|
||||||
expect(true).toBe(true)
|
expect(app.getVersion).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle empty metadata gracefully', async () => {
|
it('should handle empty metadata gracefully', async () => {
|
||||||
const { logAudit, closeAuditLogger } =
|
const { logAudit, closeAuditLogger, applyAuditConfig } =
|
||||||
await import('../../src/main/services/logger/audit-logger')
|
await import('../../src/main/services/logger/audit-logger')
|
||||||
|
|
||||||
|
applyAuditConfig(30)
|
||||||
|
|
||||||
logAudit('PING', 'ping-user', {
|
logAudit('PING', 'ping-user', {
|
||||||
username: 'pinger',
|
username: 'pinger',
|
||||||
computerName: 'PC-PING',
|
computerName: 'PC-PING',
|
||||||
@@ -240,7 +248,7 @@ describe('Audit Logger - Real File Integration', () => {
|
|||||||
|
|
||||||
closeAuditLogger()
|
closeAuditLogger()
|
||||||
|
|
||||||
// Should handle empty metadata
|
// Verify empty metadata was processed without error
|
||||||
expect(true).toBe(true)
|
expect(app.getVersion).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -146,9 +146,8 @@ describe('UpdateService', () => {
|
|||||||
|
|
||||||
// Note: This integration scenario is complex to test in unit tests.
|
// Note: This integration scenario is complex to test in unit tests.
|
||||||
// Moved to integration tests: tests/integration/update-workflow.test.ts
|
// 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 () => {
|
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 () => {
|
it('returns disabled catalog when update services are unavailable', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user