Files
client-web/src/api/types.test.mjs
T
2026-08-06 18:02:02 +08:00

20 lines
752 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
})