test(message): erp-message 从 45 增至 69 个单元测试 — DND 时间窗 + TransactionError + model_to_resp
Some checks failed
CI / frontend-build (push) Has been cancelled
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- module.rs: 提取 is_in_dnd_window 纯函数 + 14 个 DND 时间窗测试(正常范围/跨午夜/边界)
- error.rs: 2 个 TransactionError 转换测试(Connection/Transaction)
- message_service: 2 个 model_to_resp 字段映射测试
- template_service: 1 个 model_to_resp 字段映射测试
- subscription_service: 1 个 model_to_resp 字段映射测试
This commit is contained in:
iven
2026-04-28 18:26:36 +08:00
parent 50e63530d9
commit 26aa66d6e3
5 changed files with 236 additions and 4 deletions

View File

@@ -117,4 +117,28 @@ mod tests {
"版本冲突: 数据已被其他操作修改,请刷新后重试"
);
}
#[test]
fn transaction_connection_error_maps_to_validation() {
let db_err = sea_orm::DbErr::Conn(sea_orm::RuntimeErr::Internal("连接超时".to_string()));
let tx_err: sea_orm::TransactionError<MessageError> =
sea_orm::TransactionError::Connection(db_err);
let msg_err: MessageError = tx_err.into();
match msg_err {
MessageError::Validation(msg) => assert!(msg.contains("连接超时")),
other => panic!("期望 Validation得到 {:?}", other),
}
}
#[test]
fn transaction_inner_error_passthrough() {
let inner = MessageError::NotFound("模板不存在".to_string());
let tx_err: sea_orm::TransactionError<MessageError> =
sea_orm::TransactionError::Transaction(inner);
let msg_err: MessageError = tx_err.into();
match msg_err {
MessageError::NotFound(msg) => assert_eq!(msg, "模板不存在"),
other => panic!("期望 NotFound得到 {:?}", other),
}
}
}