Message now accepts into action.

This commit is contained in:
Jeff Baskin 2025-08-02 08:58:50 -04:00
parent 0553524ec6
commit 96e6c48dbe

View File

@ -80,9 +80,95 @@ impl From<&NameID> for NameID {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum MsgAction { enum MsgAction {
Create(DocDef), Create(DocDef),
// Alter
// Remove
Error(MTTError), Error(MTTError),
Query(Access), Query(Access),
Reply(Response), Reply(Response),
// Add
// Delete
}
impl From<DocDef> for MsgAction {
fn from(value: DocDef) -> Self {
MsgAction::Create(value)
}
}
impl From<MTTError> for MsgAction {
fn from(value: MTTError) -> Self {
MsgAction::Error(value)
}
}
impl From<Access> for MsgAction {
fn from(value: Access) -> Self {
MsgAction::Query(value)
}
}
impl From<Response> for MsgAction {
fn from(value: Response) -> Self {
MsgAction::Reply(value)
}
}
#[cfg(test)]
mod msgactions {
use super::*;
#[test]
fn turn_document_definition_into_action() {
let value = DocDef::new();
let result: MsgAction = value.into();
match result {
MsgAction::Create(_) => {},
_ => unreachable!("Got {:?}: dhould have been create", result),
}
}
#[test]
fn turn_error_into_action() {
let data = "data".to_string();
let value = MTTError::DocumentAlreadyExists(data.clone());
let result: MsgAction = value.into();
match result {
MsgAction::Error(result) => match result {
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
_ => unreachable!("Got {:?}: dhould have been create", result),
},
_ => unreachable!("Got {:?}: dhould have been create", result),
}
let value = MTTError::DocumentNotFound(data.clone());
let result: MsgAction = value.into();
match result {
MsgAction::Error(result) => match result {
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
_ => unreachable!("Got {:?}: dhould have been create", result),
},
_ => unreachable!("Got {:?}: dhould have been create", result),
}
}
#[test]
fn turn_query_into_action() {
let value = Access::new();
let result: MsgAction = value.into();
match result {
MsgAction::Query(_) => {},
_ => unreachable!("Got {:?}: dhould have been query", result),
}
}
#[test]
fn turn_reply_into_action() {
let value = Response::new();
let result: MsgAction = value.into();
match result {
MsgAction::Reply(_) => {},
_ => unreachable!("Got {:?}: dhould have been reply", result),
}
}
} }
#[derive(Clone)] #[derive(Clone)]
@ -93,14 +179,15 @@ struct Message {
} }
impl Message { impl Message {
fn new<D>(doc_id: D, action: MsgAction) -> Self fn new<D, A>(doc_id: D, action: A) -> Self
where where
D: Into<NameID>, D: Into<NameID>,
A: Into<MsgAction>,
{ {
Self { Self {
msg_id: Uuid::new_v4(), msg_id: Uuid::new_v4(),
document_id: doc_id.into(), document_id: doc_id.into(),
action: action, action: action.into(),
} }
} }
@ -892,6 +979,16 @@ impl Document {
} }
} }
#[cfg(test)]
mod documents {
use super::support_test::TIMEOUT;
use super::*;
#[test]
fn has_data_fields() {
}
}
#[cfg(test)] #[cfg(test)]
mod createdocs { mod createdocs {
use super::support_test::TIMEOUT; use super::support_test::TIMEOUT;