cmvr-wms/ruoyi-ui-vue3/tests/unit/purchase-documents.test.mjs
lixiaolong a82258561b feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-16 15:30:10 +08:00

52 lines
3.7 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('six optional batch groups and business numbers are presented in business order',()=>{
assert.deepEqual(purchaseDocumentKinds.map(g=>g.kind),['REQUEST','QUOTE','CONTRACT','ACCEPTANCE','PAYMENT','OTHER'])
assert.equal(purchaseDocumentKinds[0].numberLabel,'随行编号')
assert.equal(purchaseDocumentKinds[2].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 size of [0,-1,NaN,Infinity,10485761])assert.match(purchaseAttachmentError({name:'a.pdf',size},'OTHER'),/10 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',s\.row\.id/)
assert.match(sheet,/保存批次后可维护附件及编号/)
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\)/)
})