Added create document to client.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
30
src/lib.rs
30
src/lib.rs
@@ -125,6 +125,36 @@ impl MTTClient {
|
||||
pub fn session_id(&self) -> String {
|
||||
self.session_id.to_string()
|
||||
}
|
||||
|
||||
pub fn create_document(&self, docdef: DocDef) -> Result<(), MTTError> {
|
||||
let msg_id = MessageID::new();
|
||||
let paths = [
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::DocumentCreated),
|
||||
),
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::Error),
|
||||
),
|
||||
];
|
||||
for path in paths.iter() {
|
||||
let reg_msg = Register::new(self.sender_id.clone(), RegMsg::AddRoute(path.clone()));
|
||||
self.queue.send(Message::with_id(msg_id.clone(), reg_msg));
|
||||
self.rx.recv().unwrap(); // Wait for completion.
|
||||
}
|
||||
self.queue.send(Message::with_id(msg_id.clone(), docdef));
|
||||
match self.rx.recv_timeout(TIMEOUT) {
|
||||
Ok(data) => match data.get_action() {
|
||||
MsgAction::DocumentCreated => Ok(()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive confirmation or errors"),
|
||||
},
|
||||
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MTTClient {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use isolang::Language;
|
||||
use morethantext::{Action, Field, Include, MoreThanText, Name, Path, TestMoreThanText};
|
||||
use morethantext::{
|
||||
Action, DocDef, ErrorID, Field, Include, MTTError, MoreThanText, Name, Path, TestMoreThanText,
|
||||
};
|
||||
use std::{collections::HashSet, sync::mpsc::RecvTimeoutError};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -120,3 +122,24 @@ fn do_existing_sessions_keep_language_unchanged() {
|
||||
let rec = result.iter().last().unwrap();
|
||||
assert_eq!(rec.get(&lang_name()).unwrap(), lang1.into());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_client_create_a_document() {
|
||||
let doc_name = Name::english("dragon");
|
||||
let docdef = DocDef::new(doc_name);
|
||||
let mtt = MoreThanText::new();
|
||||
let client = mtt.client();
|
||||
client.create_document(docdef).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_error_on_create_document() {
|
||||
let doc_name = Name::english("dragon");
|
||||
let docdef = DocDef::new(doc_name.clone());
|
||||
let mtt = MoreThanText::new();
|
||||
let client = mtt.client();
|
||||
client.create_document(docdef.clone()).unwrap();
|
||||
let mut expected = MTTError::new(ErrorID::NameAlreadyExists);
|
||||
let result = client.create_document(docdef).unwrap_err();
|
||||
assert_eq!(result.to_string(), expected.to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user