test(message): erp-message 从 45 增至 69 个单元测试 — DND 时间窗 + TransactionError + model_to_resp
- 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:
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user