style: apply prettier formatting
Apply consistent formatting across all files (line endings, spacing) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
88
tests/fixtures/create-fixtures.ts
vendored
88
tests/fixtures/create-fixtures.ts
vendored
@@ -1,25 +1,25 @@
|
||||
import ExcelJS from 'exceljs';
|
||||
import path from 'path';
|
||||
import ExcelJS from 'exceljs'
|
||||
import path from 'path'
|
||||
|
||||
/**
|
||||
* Create test fixture Excel files for unit tests
|
||||
*/
|
||||
|
||||
async function createTestFixture() {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('Sheet1');
|
||||
const workbook = new ExcelJS.Workbook()
|
||||
const worksheet = workbook.addWorksheet('Sheet1')
|
||||
|
||||
// Row 1: Order title
|
||||
worksheet.addRow([null, '离散备料计划']);
|
||||
worksheet.addRow([null, '离散备料计划'])
|
||||
|
||||
// Row 2-5: Order header info
|
||||
worksheet.addRow([null, '生产部门:', null, '生产车间', '产品编码:', null, 'P001']);
|
||||
worksheet.addRow([null, '生产订单:', null, 'SC202501001', '产品名称:', null, '测试产品A']);
|
||||
worksheet.addRow([null, '产品规格:', null, '标准规格', '计划数量:', null, '100']);
|
||||
worksheet.addRow([null, '单位:', null, '件', '需用日期:', null, '2025-02-15']);
|
||||
worksheet.addRow([null, '生产部门:', null, '生产车间', '产品编码:', null, 'P001'])
|
||||
worksheet.addRow([null, '生产订单:', null, 'SC202501001', '产品名称:', null, '测试产品A'])
|
||||
worksheet.addRow([null, '产品规格:', null, '标准规格', '计划数量:', null, '100'])
|
||||
worksheet.addRow([null, '单位:', null, '件', '需用日期:', null, '2025-02-15'])
|
||||
|
||||
// Row 6: Empty row before table header
|
||||
worksheet.addRow([]);
|
||||
worksheet.addRow([])
|
||||
|
||||
// Row 7: Table header
|
||||
worksheet.addRow([
|
||||
@@ -36,8 +36,8 @@ async function createTestFixture() {
|
||||
'需用日期',
|
||||
'发料仓库',
|
||||
'单位用量',
|
||||
'累计出库数量',
|
||||
]);
|
||||
'累计出库数量'
|
||||
])
|
||||
|
||||
// Row 8-10: Material data
|
||||
worksheet.addRow([
|
||||
@@ -54,8 +54,8 @@ async function createTestFixture() {
|
||||
'2025-02-10',
|
||||
'仓库1',
|
||||
0.5,
|
||||
0,
|
||||
]);
|
||||
0
|
||||
])
|
||||
worksheet.addRow([
|
||||
null,
|
||||
2,
|
||||
@@ -70,8 +70,8 @@ async function createTestFixture() {
|
||||
'2025-02-12',
|
||||
'仓库1',
|
||||
1.0,
|
||||
20,
|
||||
]);
|
||||
20
|
||||
])
|
||||
worksheet.addRow([
|
||||
null,
|
||||
3,
|
||||
@@ -86,34 +86,34 @@ async function createTestFixture() {
|
||||
'2025-02-14',
|
||||
'仓库2',
|
||||
2.0,
|
||||
50,
|
||||
]);
|
||||
50
|
||||
])
|
||||
|
||||
// Row 11: Footer info
|
||||
worksheet.addRow([null, '制单人:', null, '张三', '打印人:', null, '李四']);
|
||||
worksheet.addRow([null, '打印日期:', null, '2025-01-15']);
|
||||
worksheet.addRow([null, '制单人:', null, '张三', '打印人:', null, '李四'])
|
||||
worksheet.addRow([null, '打印日期:', null, '2025-01-15'])
|
||||
|
||||
// Save file
|
||||
const filePath = path.resolve(__dirname, 'test-export.xlsx');
|
||||
await workbook.xlsx.writeFile(filePath);
|
||||
console.log('Created test fixture:', filePath);
|
||||
const filePath = path.resolve(__dirname, 'test-export.xlsx')
|
||||
await workbook.xlsx.writeFile(filePath)
|
||||
console.log('Created test fixture:', filePath)
|
||||
}
|
||||
|
||||
async function createEmptyOrdersFixture() {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('Sheet1');
|
||||
const workbook = new ExcelJS.Workbook()
|
||||
const worksheet = workbook.addWorksheet('Sheet1')
|
||||
|
||||
// Row 1: Order title
|
||||
worksheet.addRow([null, '离散备料计划']);
|
||||
worksheet.addRow([null, '离散备料计划'])
|
||||
|
||||
// Row 2-5: Order header info
|
||||
worksheet.addRow([null, '生产部门:', null, '生产车间', '产品编码:', null, 'P002']);
|
||||
worksheet.addRow([null, '生产订单:', null, 'SC202501002', '产品名称:', null, '测试产品B']);
|
||||
worksheet.addRow([null, '产品规格:', null, '特殊规格', '计划数量:', null, '50']);
|
||||
worksheet.addRow([null, '单位:', null, '套', '需用日期:', null, '2025-03-01']);
|
||||
worksheet.addRow([null, '生产部门:', null, '生产车间', '产品编码:', null, 'P002'])
|
||||
worksheet.addRow([null, '生产订单:', null, 'SC202501002', '产品名称:', null, '测试产品B'])
|
||||
worksheet.addRow([null, '产品规格:', null, '特殊规格', '计划数量:', null, '50'])
|
||||
worksheet.addRow([null, '单位:', null, '套', '需用日期:', null, '2025-03-01'])
|
||||
|
||||
// Row 6: Empty row before table header
|
||||
worksheet.addRow([]);
|
||||
worksheet.addRow([])
|
||||
|
||||
// Row 7: Table header
|
||||
worksheet.addRow([
|
||||
@@ -130,27 +130,27 @@ async function createEmptyOrdersFixture() {
|
||||
'需用日期',
|
||||
'发料仓库',
|
||||
'单位用量',
|
||||
'累计出库数量',
|
||||
]);
|
||||
'累计出库数量'
|
||||
])
|
||||
|
||||
// Row 8: Empty row (no data)
|
||||
worksheet.addRow([]);
|
||||
worksheet.addRow([])
|
||||
|
||||
// Row 9: Footer info
|
||||
worksheet.addRow([null, '制单人:', null, '王五', '打印人:', null, '赵六']);
|
||||
worksheet.addRow([null, '打印日期:', null, '2025-01-16']);
|
||||
worksheet.addRow([null, '制单人:', null, '王五', '打印人:', null, '赵六'])
|
||||
worksheet.addRow([null, '打印日期:', null, '2025-01-16'])
|
||||
|
||||
// Save file
|
||||
const filePath = path.resolve(__dirname, 'test-empty-orders.xlsx');
|
||||
await workbook.xlsx.writeFile(filePath);
|
||||
console.log('Created empty orders fixture:', filePath);
|
||||
const filePath = path.resolve(__dirname, 'test-empty-orders.xlsx')
|
||||
await workbook.xlsx.writeFile(filePath)
|
||||
console.log('Created empty orders fixture:', filePath)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('Creating test fixture Excel files...');
|
||||
await createTestFixture();
|
||||
await createEmptyOrdersFixture();
|
||||
console.log('Done!');
|
||||
console.log('Creating test fixture Excel files...')
|
||||
await createTestFixture()
|
||||
await createEmptyOrdersFixture()
|
||||
console.log('Done!')
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
main().catch(console.error)
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth';
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types';
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types'
|
||||
|
||||
describe('ERP Authentication Service (Integration)', () => {
|
||||
let authService: ErpAuthService;
|
||||
let authService: ErpAuthService
|
||||
const config: ErpConfig = {
|
||||
url: process.env.ERP_URL || '',
|
||||
username: process.env.ERP_USERNAME || '',
|
||||
password: process.env.ERP_PASSWORD || '',
|
||||
};
|
||||
password: process.env.ERP_PASSWORD || ''
|
||||
}
|
||||
|
||||
// Check if we have ERP credentials
|
||||
const hasCredentials = !!(config.url && config.username && config.password);
|
||||
const hasCredentials = !!(config.url && config.username && config.password)
|
||||
|
||||
beforeAll(() => {
|
||||
if (!hasCredentials) {
|
||||
console.warn('Skipping ERP auth tests: credentials not configured');
|
||||
return;
|
||||
console.warn('Skipping ERP auth tests: credentials not configured')
|
||||
return
|
||||
}
|
||||
authService = new ErpAuthService(config);
|
||||
});
|
||||
authService = new ErpAuthService(config)
|
||||
})
|
||||
|
||||
it('should login successfully', async () => {
|
||||
if (!hasCredentials) {
|
||||
console.warn('Skipping test: ERP credentials not configured');
|
||||
return;
|
||||
console.warn('Skipping test: ERP credentials not configured')
|
||||
return
|
||||
}
|
||||
|
||||
const session = await authService.login();
|
||||
const session = await authService.login()
|
||||
|
||||
expect(session).toBeDefined();
|
||||
expect(session.browser).toBeDefined();
|
||||
expect(session.context).toBeDefined();
|
||||
expect(session.page).toBeDefined();
|
||||
expect(session.isLoggedIn).toBe(true);
|
||||
}, 30000);
|
||||
expect(session).toBeDefined()
|
||||
expect(session.browser).toBeDefined()
|
||||
expect(session.context).toBeDefined()
|
||||
expect(session.page).toBeDefined()
|
||||
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;
|
||||
console.warn('Skipping test: ERP credentials not configured')
|
||||
return
|
||||
}
|
||||
|
||||
const session = await authService.login();
|
||||
const session = await authService.login()
|
||||
|
||||
const url = session.page.url();
|
||||
expect(url).toContain(config.url);
|
||||
}, 30000);
|
||||
const url = session.page.url()
|
||||
expect(url).toContain(config.url)
|
||||
}, 30000)
|
||||
|
||||
afterAll(async () => {
|
||||
if (hasCredentials && authService) {
|
||||
await authService.close();
|
||||
await authService.close()
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,150 +1,152 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } 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';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { describe, it, expect, beforeAll, afterAll } 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'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
describe('Extractor Service (Integration)', () => {
|
||||
const config: ErpConfig = {
|
||||
url: process.env.ERP_URL || '',
|
||||
username: process.env.ERP_USERNAME || '',
|
||||
password: process.env.ERP_PASSWORD || '',
|
||||
};
|
||||
password: process.env.ERP_PASSWORD || ''
|
||||
}
|
||||
|
||||
const testOrderNumber = 'SC70202602120085'; // From references/demo/productionID.txt
|
||||
const testOrderNumber = 'SC70202602120085' // From references/demo/productionID.txt
|
||||
|
||||
// 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 () => {
|
||||
if (!hasCredentials) {
|
||||
console.warn('Skipping test: ERP credentials not configured');
|
||||
return;
|
||||
console.warn('Skipping test: ERP credentials not configured')
|
||||
return
|
||||
}
|
||||
|
||||
// Create fresh auth service for this test
|
||||
const authService = new ErpAuthService(config);
|
||||
await authService.login();
|
||||
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],
|
||||
});
|
||||
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);
|
||||
const filePath = result.downloadedFiles[0]
|
||||
const stats = await fs.stat(filePath)
|
||||
expect(stats.size).toBeGreaterThan(0)
|
||||
|
||||
// Clean up
|
||||
await authService.close();
|
||||
}, 60000);
|
||||
await authService.close()
|
||||
}, 60000)
|
||||
|
||||
it('should extract data for multiple order numbers', async () => {
|
||||
if (!hasCredentials) {
|
||||
console.warn('Skipping test: ERP credentials not configured');
|
||||
return;
|
||||
console.warn('Skipping test: ERP credentials not configured')
|
||||
return
|
||||
}
|
||||
|
||||
// Create fresh auth service for this test
|
||||
const authService = new ErpAuthService(config);
|
||||
await authService.login();
|
||||
const authService = new ErpAuthService(config)
|
||||
await authService.login()
|
||||
|
||||
const extractor = new ExtractorService(authService);
|
||||
const extractor = new ExtractorService(authService)
|
||||
|
||||
// Read order numbers from productionID.txt file
|
||||
const fs = await import('fs/promises');
|
||||
const path = await import('path');
|
||||
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.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line.length > 0)
|
||||
.slice(0, 5); // Test first 5 orders
|
||||
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);
|
||||
console.log(`Testing with ${orderNumbers.length} order numbers:`, orderNumbers)
|
||||
|
||||
const result = await extractor.extract({
|
||||
orderNumbers,
|
||||
batchSize: 100, // Process all in one batch
|
||||
});
|
||||
batchSize: 100 // Process all in one batch
|
||||
})
|
||||
|
||||
console.log(`Downloaded ${result.downloadedFiles.length} files`);
|
||||
console.log(`Downloaded ${result.downloadedFiles.length} files`)
|
||||
if (result.errors.length > 0) {
|
||||
console.log('Errors:', result.errors);
|
||||
console.log('Errors:', result.errors)
|
||||
}
|
||||
|
||||
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1);
|
||||
expect(result.downloadedFiles.length).toBeGreaterThanOrEqual(1)
|
||||
|
||||
// Clean up
|
||||
await authService.close();
|
||||
}, 120000); // Increase timeout to 2 minutes
|
||||
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;
|
||||
console.warn('Skipping test: ERP credentials not configured')
|
||||
return
|
||||
}
|
||||
|
||||
// Create fresh auth service for this test
|
||||
const authService = new ErpAuthService(config);
|
||||
await authService.login();
|
||||
const authService = new ErpAuthService(config)
|
||||
await authService.login()
|
||||
|
||||
const extractor = new ExtractorService(authService);
|
||||
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.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line.length > 0);
|
||||
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
|
||||
.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)}`);
|
||||
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 startTime = Date.now()
|
||||
|
||||
const result = await extractor.extract({
|
||||
orderNumbers,
|
||||
batchSize: 70, // Process 70 orders per batch
|
||||
});
|
||||
batchSize: 70 // Process 70 orders per batch
|
||||
})
|
||||
|
||||
const endTime = Date.now();
|
||||
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
||||
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`);
|
||||
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}`));
|
||||
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);
|
||||
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);
|
||||
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
|
||||
});
|
||||
await authService.close()
|
||||
}, 600000) // 10 minutes timeout for large batch test
|
||||
})
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { beforeAll, afterAll } from 'vitest';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { beforeAll, afterAll } from 'vitest'
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
|
||||
// Load environment variables from project root
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '.env') })
|
||||
|
||||
beforeAll(async () => {
|
||||
// Global test setup
|
||||
console.log('Test suite starting...');
|
||||
});
|
||||
console.log('Test suite starting...')
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
// Global test teardown
|
||||
console.log('Test suite completed.');
|
||||
});
|
||||
console.log('Test suite completed.')
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth';
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types';
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types'
|
||||
|
||||
describe('ERP Authentication Service (Unit)', () => {
|
||||
describe('Session Management', () => {
|
||||
@@ -8,52 +8,52 @@ describe('ERP Authentication Service (Unit)', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(service).toBeDefined();
|
||||
expect(service.isActive()).toBe(false);
|
||||
});
|
||||
expect(service).toBeDefined()
|
||||
expect(service.isActive()).toBe(false)
|
||||
})
|
||||
|
||||
it('should throw error when getting session before login', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(() => service.getSession()).toThrow('Not logged in. Call login() first.');
|
||||
});
|
||||
expect(() => service.getSession()).toThrow('Not logged in. Call login() first.')
|
||||
})
|
||||
|
||||
it('should report inactive status before login', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(service.isActive()).toBe(false);
|
||||
});
|
||||
});
|
||||
expect(service.isActive()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Close Method', () => {
|
||||
it('should handle close when no session exists', async () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
// Should not throw when closing without session
|
||||
await expect(service.close()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
await expect(service.close()).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ExcelParser } from '../../src/main/services/excel/excel-parser';
|
||||
import type { DiscreteMaterialPlan } from '../../src/main/types/excel.types';
|
||||
import path from 'path';
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { ExcelParser } from '../../src/main/services/excel/excel-parser'
|
||||
import type { DiscreteMaterialPlan } from '../../src/main/types/excel.types'
|
||||
import path from 'path'
|
||||
|
||||
describe('Excel Parser', () => {
|
||||
it('should parse Excel file and extract material plans', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(Array.isArray(plans)).toBe(true);
|
||||
expect(plans.length).toBeGreaterThan(0);
|
||||
expect(Array.isArray(plans)).toBe(true)
|
||||
expect(plans.length).toBeGreaterThan(0)
|
||||
|
||||
const firstPlan = plans[0];
|
||||
expect(firstPlan).toHaveProperty('orderNumber');
|
||||
expect(firstPlan).toHaveProperty('materialCode');
|
||||
});
|
||||
const firstPlan = plans[0]
|
||||
expect(firstPlan).toHaveProperty('orderNumber')
|
||||
expect(firstPlan).toHaveProperty('materialCode')
|
||||
})
|
||||
|
||||
it('should parse all material fields correctly', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(plans.length).toBe(3);
|
||||
expect(plans.length).toBe(3)
|
||||
|
||||
// Check first material
|
||||
expect(plans[0].orderNumber).toBe('SC202501001');
|
||||
expect(plans[0].materialCode).toBe('M001');
|
||||
expect(plans[0].materialName).toBe('钢材A');
|
||||
expect(plans[0].specification).toBe('规格1');
|
||||
expect(plans[0].model).toBe('型号1');
|
||||
expect(plans[0].drawingNumber).toBe('图号1');
|
||||
expect(plans[0].material).toBe('材质1');
|
||||
expect(plans[0].quantity).toBe(50);
|
||||
expect(plans[0].unit).toBe('kg');
|
||||
expect(plans[0].requiredDate).toBe('2025-02-10');
|
||||
expect(plans[0].warehouse).toBe('仓库1');
|
||||
expect(plans[0].unitUsage).toBe(0.5);
|
||||
expect(plans[0].cumulativeOutboundQty).toBe(0);
|
||||
expect(plans[0].orderNumber).toBe('SC202501001')
|
||||
expect(plans[0].materialCode).toBe('M001')
|
||||
expect(plans[0].materialName).toBe('钢材A')
|
||||
expect(plans[0].specification).toBe('规格1')
|
||||
expect(plans[0].model).toBe('型号1')
|
||||
expect(plans[0].drawingNumber).toBe('图号1')
|
||||
expect(plans[0].material).toBe('材质1')
|
||||
expect(plans[0].quantity).toBe(50)
|
||||
expect(plans[0].unit).toBe('kg')
|
||||
expect(plans[0].requiredDate).toBe('2025-02-10')
|
||||
expect(plans[0].warehouse).toBe('仓库1')
|
||||
expect(plans[0].unitUsage).toBe(0.5)
|
||||
expect(plans[0].cumulativeOutboundQty).toBe(0)
|
||||
|
||||
// Check third material (with some empty fields)
|
||||
expect(plans[2].materialCode).toBe('M003');
|
||||
expect(plans[2].materialName).toBe('配件C');
|
||||
expect(plans[2].quantity).toBe(200);
|
||||
});
|
||||
expect(plans[2].materialCode).toBe('M003')
|
||||
expect(plans[2].materialName).toBe('配件C')
|
||||
expect(plans[2].quantity).toBe(200)
|
||||
})
|
||||
|
||||
it('should handle empty orders gracefully', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-empty-orders.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-empty-orders.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(plans).toBeDefined();
|
||||
expect(plans.length).toBe(0);
|
||||
});
|
||||
});
|
||||
expect(plans).toBeDefined()
|
||||
expect(plans.length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
import { describe, it, expect, beforeEach } 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';
|
||||
import { describe, it, expect, beforeEach } 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'
|
||||
|
||||
describe('Extractor Service (Unit)', () => {
|
||||
let authService: ErpAuthService;
|
||||
let extractor: ExtractorService;
|
||||
let authService: ErpAuthService
|
||||
let extractor: ExtractorService
|
||||
const mockConfig: ErpConfig = {
|
||||
url: 'https://test.erp.com',
|
||||
username: 'test_user',
|
||||
password: 'test_pass',
|
||||
};
|
||||
password: 'test_pass'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
authService = new ErpAuthService(mockConfig);
|
||||
extractor = new ExtractorService(authService, './test-downloads');
|
||||
});
|
||||
authService = new ErpAuthService(mockConfig)
|
||||
extractor = new ExtractorService(authService, './test-downloads')
|
||||
})
|
||||
|
||||
describe('Batch Creation', () => {
|
||||
it('should create single batch for small order list', () => {
|
||||
// This tests the createBatches method indirectly through extract
|
||||
// We'll need to add a public method or test through the class
|
||||
const orders = ['ORDER1', 'ORDER2', 'ORDER3'];
|
||||
const batchSize = 10;
|
||||
const orders = ['ORDER1', 'ORDER2', 'ORDER3']
|
||||
const batchSize = 10
|
||||
|
||||
// Expected: 1 batch with 3 orders
|
||||
const expectedBatches = 1;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 1
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should create multiple batches for large order list', () => {
|
||||
const orders = Array.from({ length: 250 }, (_, i) => `ORDER${i}`);
|
||||
const batchSize = 100;
|
||||
const orders = Array.from({ length: 250 }, (_, i) => `ORDER${i}`)
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 3 batches (100, 100, 50)
|
||||
const expectedBatches = 3;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 3
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should handle exact batch size', () => {
|
||||
const orders = Array.from({ length: 200 }, (_, i) => `ORDER${i}`);
|
||||
const batchSize = 100;
|
||||
const orders = Array.from({ length: 200 }, (_, i) => `ORDER${i}`)
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 2 batches exactly
|
||||
const expectedBatches = 2;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 2
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should handle empty order list', () => {
|
||||
const orders: string[] = [];
|
||||
const batchSize = 100;
|
||||
const orders: string[] = []
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 0 batches
|
||||
const expectedBatches = 0;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
});
|
||||
const expectedBatches = 0
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Service Initialization', () => {
|
||||
it('should create service instance', () => {
|
||||
expect(extractor).toBeDefined();
|
||||
expect(extractor).toBeInstanceOf(ExtractorService);
|
||||
});
|
||||
expect(extractor).toBeDefined()
|
||||
expect(extractor).toBeInstanceOf(ExtractorService)
|
||||
})
|
||||
|
||||
it('should use default download directory', () => {
|
||||
const defaultExtractor = new ExtractorService(authService);
|
||||
expect(defaultExtractor).toBeDefined();
|
||||
});
|
||||
const defaultExtractor = new ExtractorService(authService)
|
||||
expect(defaultExtractor).toBeDefined()
|
||||
})
|
||||
|
||||
it('should use custom download directory', () => {
|
||||
const customExtractor = new ExtractorService(authService, './custom-downloads');
|
||||
expect(customExtractor).toBeDefined();
|
||||
});
|
||||
});
|
||||
const customExtractor = new ExtractorService(authService, './custom-downloads')
|
||||
expect(customExtractor).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should handle extraction with no auth session', async () => {
|
||||
const result = await extractor.extract({
|
||||
orderNumbers: ['ORDER1'],
|
||||
});
|
||||
orderNumbers: ['ORDER1']
|
||||
})
|
||||
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
expect(result.downloadedFiles).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(result.errors.length).toBeGreaterThan(0)
|
||||
expect(result.downloadedFiles).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ERP_LOCATORS } from '../../src/main/services/erp/locators';
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { ERP_LOCATORS } from '../../src/main/services/erp/locators'
|
||||
|
||||
describe('ERP Locators', () => {
|
||||
it('should have login page locators defined', () => {
|
||||
expect(ERP_LOCATORS.login.usernameInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.login.passwordInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.login.submitButton).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.login.usernameInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.login.passwordInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.login.submitButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have main frame locator', () => {
|
||||
expect(ERP_LOCATORS.main.mainIframe).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.main.mainIframe).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have extractor page locators', () => {
|
||||
expect(ERP_LOCATORS.extractor.orderNumberInputRole).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.queryButton).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.exportButton).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.confirmButton).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.extractor.orderNumberInputRole).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.queryButton).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.exportButton).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.confirmButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have cleaner page locators', () => {
|
||||
expect(ERP_LOCATORS.cleaner.orderNumberInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.cleaner.materialGrid).toBeDefined();
|
||||
expect(ERP_LOCATORS.cleaner.saveButton).toBeDefined();
|
||||
});
|
||||
});
|
||||
expect(ERP_LOCATORS.cleaner.orderNumberInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.cleaner.materialGrid).toBeDefined()
|
||||
expect(ERP_LOCATORS.cleaner.saveButton).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user