Got document service functioning.

This commit is contained in:
2025-04-15 18:37:02 -04:00
parent a5b4398eab
commit a38bfc200d
3 changed files with 116 additions and 60 deletions

View File

@ -10,8 +10,8 @@ pub enum MsgType {
ClientRequest,
Document,
DocumentRequest,
Session,
SessionValidate,
SessionValidated,
Time,
}
@ -59,7 +59,10 @@ impl Message {
self.data.insert(name.into(), data.into());
}
pub fn get_data<S>(&self, name: S) -> Option<&Field> where S: Into<String> {
pub fn get_data<S>(&self, name: S) -> Option<&Field>
where
S: Into<String>,
{
let field_name = name.into();
self.data.get(&field_name)
}
@ -153,14 +156,18 @@ mod messages {
#[test]
fn copy_data_with_reply() {
let id = Uuid::new_v4();
let reply_type = MsgType::Session;
let reply_type = MsgType::SessionValidated;
let mut msg = Message::new(MsgType::SessionValidate);
msg.add_data(id, id);
let reply = msg.reply_with_data(reply_type.clone());
assert_eq!(reply.id, msg.id);
match reply.get_msg_type() {
MsgType::Session => {},
_ => unreachable!("Got {:?} should have been {:?}", msg.get_msg_type(), reply_type),
MsgType::SessionValidated => {}
_ => unreachable!(
"Got {:?} should have been {:?}",
msg.get_msg_type(),
reply_type
),
}
assert_eq!(reply.data.len(), msg.data.len());
let output = reply.get_data(&id.to_string()).unwrap().to_uuid().unwrap();
@ -170,7 +177,7 @@ mod messages {
#[test]
fn get_message_id() {
let msg = Message::new(MsgType::Session);
let msg = Message::new(MsgType::SessionValidated);
assert_eq!(msg.get_id(), msg.id);
}
@ -261,7 +268,7 @@ mod queues {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
queue.add(tx1, [MsgType::SessionValidate].to_vec());
queue.add(tx2, [MsgType::Session].to_vec());
queue.add(tx2, [MsgType::SessionValidated].to_vec());
queue.send(Message::new(MsgType::SessionValidate)).unwrap();
let result = rx1.recv().unwrap();
match result.get_msg_type() {
@ -278,10 +285,10 @@ mod queues {
_ => unreachable!("{:?}", err),
},
}
queue.send(Message::new(MsgType::Session)).unwrap();
queue.send(Message::new(MsgType::SessionValidated)).unwrap();
let result = rx2.recv().unwrap();
match result.get_msg_type() {
MsgType::Session => {}
MsgType::SessionValidated => {}
_ => unreachable!(
"received {:?}, should have been session vvalidate",
result.get_msg_type()
@ -300,19 +307,22 @@ mod queues {
fn assign_sender_multiple_message_types() {
let queue = Queue::new();
let (tx, rx) = channel();
queue.add(tx, [MsgType::Session, MsgType::SessionValidate].to_vec());
queue.add(
tx,
[MsgType::SessionValidated, MsgType::SessionValidate].to_vec(),
);
queue.send(Message::new(MsgType::SessionValidate)).unwrap();
let msg = rx.recv().unwrap();
assert_eq!(msg.get_msg_type(), &MsgType::SessionValidate);
queue.send(Message::new(MsgType::Session)).unwrap();
queue.send(Message::new(MsgType::SessionValidated)).unwrap();
let msg = rx.recv().unwrap();
assert_eq!(msg.get_msg_type(), &MsgType::Session);
assert_eq!(msg.get_msg_type(), &MsgType::SessionValidated);
}
#[test]
fn unassigned_message_should_return_error() {
let queue = Queue::new();
match queue.send(Message::new(MsgType::Session)) {
match queue.send(Message::new(MsgType::SessionValidated)) {
Ok(_) => unreachable!("should return error"),
Err(_) => {}
}