style: apply formatter to docs, types, and test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-04-05 11:56:22 +08:00
parent 9791a84047
commit e54d94fce2
13 changed files with 444 additions and 358 deletions

View File

@@ -18,117 +18,129 @@ describe('Extractor Service (Integration)', () => {
// Check if we have ERP credentials
const hasCredentials = !!(config.url && config.username && config.password)
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()
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()
const extractor = new ExtractorService(authService)
const extractor = new ExtractorService(authService)
const result = await extractor.extract({
orderNumbers: [testOrderNumber]
})
const result = await extractor.extract({
orderNumbers: [testOrderNumber]
})
expect(result.downloadedFiles).toHaveLength(1)
expect(result.errors).toHaveLength(0)
expect(result.downloadedFiles).toHaveLength(1)
expect(result.errors).toHaveLength(0)
// Verify file exists
const filePath = result.downloadedFiles[0]
const stats = await fs.stat(filePath)
expect(stats.size).toBeGreaterThan(0)
// Clean up
await authService.close()
}, 60000)
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()
const extractor = new ExtractorService(authService)
// Read order numbers from productionID.txt file
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
.slice(0, 5) // Test first 5 orders
console.log(`Testing with ${orderNumbers.length} order numbers:`, orderNumbers)
const result = await extractor.extract({
orderNumbers,
batchSize: 100 // Process all in one batch
})
console.log(`Downloaded ${result.downloadedFiles.length} files`)
if (result.errors.length > 0) {
console.log('Errors:', result.errors)
}
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1)
// Clean up
await authService.close()
}, 120000) // Increase timeout to 2 minutes
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()
const extractor = new ExtractorService(authService)
// Read all order numbers from productionID.txt file
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
console.log(`Testing with ${orderNumbers.length} order numbers`)
console.log(`Batch size: 70, Expected batches: ${Math.ceil(orderNumbers.length / 70)}`)
const startTime = Date.now()
const result = await extractor.extract({
orderNumbers,
batchSize: 70 // Process 70 orders per batch
})
const endTime = Date.now()
const duration = ((endTime - startTime) / 1000).toFixed(2)
console.log(`\n=== Extraction Summary ===`)
console.log(`Total orders: ${orderNumbers.length}`)
console.log(`Batch size: 70`)
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`
)
if (result.errors.length > 0) {
console.log(`\nErrors encountered: ${result.errors.length}`)
result.errors.forEach((err, idx) => console.log(` ${idx + 1}. ${err}`))
}
// Verify results
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1)
// Verify each downloaded file exists and has content
for (const filePath of result.downloadedFiles) {
// Verify file exists
const filePath = result.downloadedFiles[0]
const stats = await fs.stat(filePath)
console.log(` - ${path.basename(filePath)}: ${(stats.size / 1024).toFixed(2)} KB`)
expect(stats.size).toBeGreaterThan(0)
}
// Clean up
await authService.close()
}, 600000) // 10 minutes timeout for large batch test
// Clean up
await authService.close()
},
60000
)
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()
const extractor = new ExtractorService(authService)
// Read order numbers from productionID.txt file
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
.slice(0, 5) // Test first 5 orders
console.log(`Testing with ${orderNumbers.length} order numbers:`, orderNumbers)
const result = await extractor.extract({
orderNumbers,
batchSize: 100 // Process all in one batch
})
console.log(`Downloaded ${result.downloadedFiles.length} files`)
if (result.errors.length > 0) {
console.log('Errors:', result.errors)
}
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1)
// Clean up
await authService.close()
},
120000
) // Increase timeout to 2 minutes
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()
const extractor = new ExtractorService(authService)
// Read all order numbers from productionID.txt file
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
console.log(`Testing with ${orderNumbers.length} order numbers`)
console.log(`Batch size: 70, Expected batches: ${Math.ceil(orderNumbers.length / 70)}`)
const startTime = Date.now()
const result = await extractor.extract({
orderNumbers,
batchSize: 70 // Process 70 orders per batch
})
const endTime = Date.now()
const duration = ((endTime - startTime) / 1000).toFixed(2)
console.log(`\n=== Extraction Summary ===`)
console.log(`Total orders: ${orderNumbers.length}`)
console.log(`Batch size: 70`)
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`
)
if (result.errors.length > 0) {
console.log(`\nErrors encountered: ${result.errors.length}`)
result.errors.forEach((err, idx) => console.log(` ${idx + 1}. ${err}`))
}
// Verify results
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1)
// Verify each downloaded file exists and has content
for (const filePath of result.downloadedFiles) {
const stats = await fs.stat(filePath)
console.log(` - ${path.basename(filePath)}: ${(stats.size / 1024).toFixed(2)} KB`)
expect(stats.size).toBeGreaterThan(0)
}
// Clean up
await authService.close()
},
600000
) // 10 minutes timeout for large batch test
})