feat: 完善采购申请流程 - 添加审批、执行、列表筛选排序功能
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
const request = require('supertest');
|
||||
const app = require('./api-complete');
|
||||
|
||||
// 测试报销申请功能
|
||||
describe('报销申请功能测试', () => {
|
||||
it('应该支持公司支出和项目支出类型', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'company',
|
||||
description: '测试报销',
|
||||
expense_type: 'company',
|
||||
reason: '测试报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
|
||||
it('项目支出时必须提供项目ID', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'project',
|
||||
description: '测试项目报销',
|
||||
expense_type: 'project',
|
||||
project_id: 1,
|
||||
reason: '测试项目报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'accommodation'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
|
||||
it('应该正确处理支出分类', async () => {
|
||||
// 测试项目支出分类
|
||||
const projectResponse = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'project',
|
||||
description: '测试项目报销',
|
||||
expense_type: 'project',
|
||||
project_id: 1,
|
||||
reason: '测试项目报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'accommodation'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(projectResponse.statusCode).toBe(200);
|
||||
expect(projectResponse.body.success).toBe(true);
|
||||
|
||||
// 测试公司支出分类
|
||||
const companyResponse = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'company',
|
||||
description: '测试公司报销',
|
||||
expense_type: 'company',
|
||||
reason: '测试公司报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(companyResponse.statusCode).toBe(200);
|
||||
expect(companyResponse.body.success).toBe(true);
|
||||
});
|
||||
|
||||
it('应该支持币种统一', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
currency: 'USD',
|
||||
amount_cny: 7000,
|
||||
type: 'company',
|
||||
description: '测试外币报销',
|
||||
expense_type: 'company',
|
||||
reason: '测试外币报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
|
||||
it('应该支持附件上传', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'company',
|
||||
description: '测试附件报销',
|
||||
expense_type: 'company',
|
||||
reason: '测试附件报销',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations',
|
||||
attachments: ['https://example.com/test.jpg']
|
||||
}],
|
||||
attachments: ['https://example.com/main.jpg']
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// 测试付款申请功能
|
||||
describe('付款申请功能测试', () => {
|
||||
it('应该创建付款申请', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/payment-requests')
|
||||
.send({
|
||||
applicant: '测试申请人',
|
||||
payee: '测试收款人',
|
||||
bank_account: '1234567890',
|
||||
bank_name: '测试银行',
|
||||
amount: 1000,
|
||||
amount_cny: 1000,
|
||||
currency: 'CNY',
|
||||
payment_date: new Date().toISOString().split('T')[0],
|
||||
reason: '测试付款',
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// 测试核销申请功能
|
||||
describe('核销申请功能测试', () => {
|
||||
it('应该创建核销申请', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/verifications')
|
||||
.send({
|
||||
applicant: '测试申请人',
|
||||
advance_code: 'ADV20240101001',
|
||||
advance_amount: 1000,
|
||||
amount: 800,
|
||||
amount_cny: 800,
|
||||
currency: 'CNY',
|
||||
verification_date: new Date().toISOString().split('T')[0],
|
||||
reason: '测试核销',
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 800,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// 测试审批流程
|
||||
describe('审批流程测试', () => {
|
||||
it('应该支持撤回功能', async () => {
|
||||
// 先创建一个报销申请
|
||||
const createResponse = await request(app)
|
||||
.post('/api/reimbursements')
|
||||
.send({
|
||||
amount: 1000,
|
||||
type: 'company',
|
||||
description: '测试撤回',
|
||||
expense_type: 'company',
|
||||
reason: '测试撤回',
|
||||
reimbursement_date: new Date().toISOString().split('T')[0],
|
||||
detail_items: [{
|
||||
description: '测试明细',
|
||||
amount: 1000,
|
||||
category: 'general_operations'
|
||||
}],
|
||||
attachments: []
|
||||
});
|
||||
|
||||
if (createResponse.body.success && createResponse.body.data) {
|
||||
const id = createResponse.body.data.id;
|
||||
|
||||
// 测试撤回功能
|
||||
const withdrawResponse = await request(app)
|
||||
.post(`/api/reimbursements/${id}/withdraw`);
|
||||
|
||||
expect(withdrawResponse.statusCode).toBe(200);
|
||||
expect(withdrawResponse.body.success).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
console.log('测试完成');
|
||||
Reference in New Issue
Block a user