Files
client-web/src/api/types.test.mjs
T

20 lines
752 B
JavaScript
Raw Normal View History

2026-08-06 18:02:02 +08:00
import assert from 'node:assert/strict'
import test from 'node:test'
import { apiErrorMessage, asFieldErrors } from './errorDetails.ts'
test('adds validation field details to a generic API message', () => {
const errors = asFieldErrors({ carrierName: '不能为空', carrierId: '不能为null' })
assert.equal(
apiErrorMessage('Validation failed', errors),
'Validation failed:carrierName: 不能为空;carrierId: 不能为null',
)
})
test('does not duplicate validation details already included by the server', () => {
const errors = { carrierName: '不能为空', carrierId: '不能为null' }
const message = 'carrierName: 不能为空;carrierId: 不能为null'
assert.equal(apiErrorMessage(message, errors), message)
})