优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
59 lines
4.2 KiB
JavaScript
59 lines
4.2 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import {purchaseDocumentKinds,purchaseAttachmentError,purchaseDocumentPath,purchaseDocumentId,purchaseUploadId,purchaseNumberDirty,mergePurchaseDocuments} from '../../src/utils/purchase-documents.js'
|
|
|
|
test('five batch groups keep the request number and merge quotation documents',()=>{
|
|
assert.deepEqual(purchaseDocumentKinds.map(g=>g.kind),['REQUEST','CONTRACT','ACCEPTANCE','PAYMENT','OTHER'])
|
|
assert.equal(purchaseDocumentKinds[0].numberLabel,'随行编号')
|
|
assert.equal(purchaseDocumentKinds[1].numberLabel,'合同编号')
|
|
})
|
|
test('workflow groups accept PDF and other/detail attachments allow ordinary office formats',()=>{
|
|
assert.equal(purchaseAttachmentError({name:'合同.pdf',size:1024},'CONTRACT'),'')
|
|
assert.match(purchaseAttachmentError({name:'合同.png',size:1024},'CONTRACT'),/PDF/)
|
|
for(const ext of ['pdf','png','jpg','jpeg','doc','docx','xls','xlsx','txt','zip']) assert.equal(purchaseAttachmentError({name:`备注.${ext}`,size:1024},'OTHER'),'')
|
|
for(const ext of ['html','exe','svg','js'])assert.match(purchaseAttachmentError({name:`危险.${ext}`,size:1024},'OTHER'),/支持/)
|
|
for(const kind of ['REQUEST','CONTRACT','ACCEPTANCE','PAYMENT','OTHER']) {
|
|
for(const size of [10*1024*1024+1,50*1024*1024])assert.equal(purchaseAttachmentError({name:'a.pdf',size},kind),'')
|
|
for(const size of [0,-1,NaN,Infinity,50*1024*1024+1])assert.match(purchaseAttachmentError({name:'a.pdf',size},kind),/50 MB/)
|
|
}
|
|
})
|
|
test('private URLs cannot be built from unsaved ids, traversal, or another target kind',()=>{
|
|
assert.equal(purchaseDocumentPath('batch',12),'/warehouse/purchase/documents/batch/12')
|
|
assert.equal(purchaseDocumentPath('detail',12),'/warehouse/purchase/documents/detail/12')
|
|
for(const id of [null,undefined,0,-1,'../12','http://elsewhere',1.5,'1e3'])assert.throws(()=>purchaseDocumentPath('batch',id))
|
|
assert.throws(()=>purchaseDocumentPath('unknown',1))
|
|
for(const id of ['../secret','abc','https://other.test/1'])assert.throws(()=>purchaseDocumentId(id))
|
|
})
|
|
test('UUID generation works on production HTTP origins without crypto.randomUUID',()=>{
|
|
const id=purchaseUploadId({getRandomValues: bytes=>{bytes.fill(21);return bytes}})
|
|
assert.match(id,/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
|
|
assert.equal(purchaseDocumentId(id),id)
|
|
assert.throws(()=>purchaseUploadId({}))
|
|
})
|
|
test('attachment reload preserves unsaved numbers and their version and reports a concurrent edit',()=>{
|
|
const old=[{kind:'REQUEST',number:'OLD',draft:'MY-NEW',version:2,files:[]}]
|
|
const fresh=[{kind:'REQUEST',number:'OTHER-EDITOR',version:3,files:[{id:'a'}]}]
|
|
const merged=mergePurchaseDocuments(fresh,old)
|
|
assert.equal(merged[0].draft,'MY-NEW');assert.equal(merged[0].version,2);assert.equal(merged[0].conflict,true)
|
|
assert.equal(merged[0].serverNumber,'OTHER-EDITOR');assert.equal(merged[0].serverVersion,3);assert.equal(merged[0].files.length,1)
|
|
assert.equal(purchaseNumberDirty(merged[0]),true)
|
|
assert.equal(mergePurchaseDocuments(fresh)[0].draft,'OTHER-EDITOR')
|
|
assert.equal(purchaseNumberDirty(undefined),false)
|
|
})
|
|
test('purchase sheet exposes batch buttons and saved-line attachment entry without gating business actions',()=>{
|
|
const sheet=fs.readFileSync(new URL('../../src/components/PurchaseSheet/index.vue',import.meta.url),'utf8')
|
|
assert.match(sheet,/v-for="document in documentKinds"/)
|
|
assert.match(sheet,/documents\.open\('detail',row\.id/)
|
|
const drawer=fs.readFileSync(new URL('../../src/components/PurchaseDocuments/index.vue',import.meta.url),'utf8')
|
|
assert.doesNotMatch(drawer,/<el-dialog/)
|
|
assert.match(drawer,/生成验收资料前需补齐采购申请、合同/)
|
|
assert.match(drawer,/user\.permissions/)
|
|
assert.match(drawer,/groups\.value\.some\(purchaseNumberDirty\)/)
|
|
})
|
|
|
|
test('acceptance invoices allow PDF and photo files but reject office documents and excessive size',()=>{
|
|
for(const ext of ['pdf','png','jpg','jpeg'])assert.equal(purchaseAttachmentError({name:`发票.${ext}`,size:50*1024*1024},'INVOICE'),'');
|
|
assert.match(purchaseAttachmentError({name:'发票.docx',size:1024},'INVOICE'),/发票/);assert.match(purchaseAttachmentError({name:'发票.pdf',size:50*1024*1024+1},'INVOICE'),/50 MB/);
|
|
});
|