Files
lotteryLaravel/tests/Unit/ApiValidationErrorsTest.php
kang 3f04b4ebe3
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
lotterLaravel E2E / e2e-api (push) Has been cancelled
feat(admin): 密码校验统一与后台 API/设置增强
- 管理端账号/代理/站点等密码最短长度统一为 6 位
- LotterySettings、审计日志展示、币种与报表接口等小修复
- 补充设置批量更新、注单、校验错误等相关测试
2026-06-26 14:39:22 +08:00

83 lines
2.9 KiB
PHP
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.
<?php
use App\Support\ApiValidationErrors;
test('normalizes english regex error for code field in zh', function (): void {
$errors = ApiValidationErrors::normalize(
['code' => ['The code field format is invalid.']],
'zh',
);
expect($errors['code'][0])->toContain('编码只能使用字母、数字');
});
test('normalizes business shorthand unique in zh', function (): void {
$errors = ApiValidationErrors::normalize(['code' => ['unique']], 'zh');
expect($errors['code'][0])->toBe('该内容已存在,请更换后重试。');
});
test('normalizes rebate exceeds limit with field specific message in zh', function (): void {
$errors = ApiValidationErrors::normalize(['rebate_rate' => ['exceeds_limit']], 'zh');
expect($errors['rebate_rate'][0])->toBe('回水比例不能超过代理回水上限。');
});
test('normalizes settlement bill not payable in zh', function (): void {
$errors = ApiValidationErrors::normalize(['bill' => ['not_payable']], 'zh');
expect($errors['bill'][0])->toBe('当前账单状态不允许登记收付,请先确认账单。');
});
test('summary joins multiple field errors', function (): void {
$normalized = [
'code' => ['编码格式不正确。'],
'name' => ['名称不能为空。'],
];
expect(ApiValidationErrors::summary($normalized))->toBe('编码格式不正确。;名称不能为空。');
});
test('keeps already localized chinese messages', function (): void {
$message = '最小下注额不能小于 0';
$errors = ApiValidationErrors::normalize(['items.0.min_bet_amount' => [$message]], 'zh');
expect($errors['items.0.min_bet_amount'][0])->toBe($message);
});
test('normalizes english min length for password in zh', function (): void {
$errors = ApiValidationErrors::normalize(
['password' => ['The password field must be at least 6 characters.']],
'zh',
);
expect($errors['password'][0])->toBe('密码至少需要 6 个字符。');
});
test('normalizes exact draw items message in zh', function (): void {
$errors = ApiValidationErrors::normalize(
['items' => ['items must contain the complete 23 draw prize slots.']],
'zh',
);
expect($errors['items'][0])->toContain('23');
});
test('normalizes compact english max for rebate rate in zh', function (): void {
$errors = ApiValidationErrors::normalize(
['rebate_rate' => ['rebate rate must not be greater than 1.']],
'zh',
);
expect($errors['rebate_rate'][0])->toBe('回水比例不能超过 1100% 记为 1。');
});
test('normalizes compact english max for rebate limit in zh', function (): void {
$errors = ApiValidationErrors::normalize(
['rebate_limit' => ['rebate limit must not be greater than 1.']],
'zh',
);
expect($errors['rebate_limit'][0])->toBe('回水上限不能超过 1100% 记为 1。');
});