refactor(mobile-oa-h5): allow transfer helpers to use payment contextId
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e2fee1d9c5
commit
9de7f5456e
2 files changed
+34
-8
No files matched your search
@@ -94,12 +94,21 @@ export function buildTransferSavePayload(transfer) {
|
||||
}
|
||||
}
|
||||
|
||||
export function assertCanSaveTransfer({ protocolId, scheduleId } = {}) {
|
||||
if (!String(protocolId || '').trim()) {
|
||||
throw new Error('请先保存协议后再保存转账记录')
|
||||
export function assertCanSaveTransfer({ protocolId, contextId, scheduleId } = {}) {
|
||||
const ctx = String(contextId || protocolId || '').trim()
|
||||
if (!ctx) {
|
||||
throw new Error(
|
||||
contextId != null && String(contextId).trim() === '' && protocolId == null
|
||||
? '请先保存后再保存转账记录'
|
||||
: '请先保存协议后再保存转账记录'
|
||||
)
|
||||
}
|
||||
if (!String(scheduleId || '').trim()) {
|
||||
throw new Error('请先保存协议后再保存转账记录')
|
||||
throw new Error(
|
||||
contextId != null
|
||||
? '缺少应缴批次,无法保存转账记录'
|
||||
: '请先保存协议后再保存转账记录'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,17 +123,17 @@ export function validateTransferRow(transfer) {
|
||||
return ''
|
||||
}
|
||||
|
||||
export function canSubmitFinance(transfer, protocolId) {
|
||||
export function canSubmitFinance(transfer, contextId) {
|
||||
return Boolean(
|
||||
String(protocolId || '').trim() &&
|
||||
String(contextId || '').trim() &&
|
||||
transfer?.id &&
|
||||
String(transfer.payStatus || 'dfj') === 'dfj'
|
||||
)
|
||||
}
|
||||
|
||||
export function canWithdrawFinance(transfer, protocolId) {
|
||||
export function canWithdrawFinance(transfer, contextId) {
|
||||
return Boolean(
|
||||
String(protocolId || '').trim() &&
|
||||
String(contextId || '').trim() &&
|
||||
transfer?.id &&
|
||||
String(transfer.payStatus || '') === 'jfqrz'
|
||||
)
|
||||
|
||||
@@ -36,6 +36,23 @@ test('save requires persisted protocol and schedule ids', () => {
|
||||
assert.doesNotThrow(() => assertCanSaveTransfer({ protocolId: 'p1', scheduleId: 's1' }))
|
||||
})
|
||||
|
||||
test('assertCanSaveTransfer accepts contextId alias for protocolId', () => {
|
||||
assert.doesNotThrow(() =>
|
||||
assertCanSaveTransfer({ contextId: 'pay-1', scheduleId: 's1' })
|
||||
)
|
||||
assert.throws(
|
||||
() => assertCanSaveTransfer({ contextId: '', scheduleId: 's1' }),
|
||||
/请先保存/
|
||||
)
|
||||
})
|
||||
|
||||
test('canSubmitFinance accepts contextId', () => {
|
||||
assert.equal(
|
||||
canSubmitFinance({ id: 't1', payStatus: 'dfj' }, 'pay-1'),
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
test('validate transfer row requires type and positive amount', () => {
|
||||
assert.match(validateTransferRow({}), /转账方式/)
|
||||
assert.match(validateTransferRow({ transferType: 'wx', transferAmount: 0 }), /转账金额/)
|
||||
|
||||
Reference in new issue
Block a user