+where
+ T: TesterTrait,
+{
+ pub fn login(mut self) -> Self {
+ let user_detail = self.tester.login();
+ self.user_detail = Some(user_detail);
+ self
+ }
+
+ pub fn login_if_need(&mut self) {
+ let user_detail = self.tester.login_if_need();
+ self.user_detail = Some(user_detail);
+ }
+
+ pub fn logout(self) -> Self {
+ // self.tester.logout();
+ self
+ }
+
+ pub fn request(mut self, request: P) -> Self
+ where
+ P: ToBytes,
+ {
+ self.tester.set_payload(request);
+ self
+ }
+
+ pub fn event(mut self, event: E) -> Self
+ where
+ E: Eq + Hash + Debug + Clone + Display,
+ {
+ self.tester.set_event(event);
+ self
+ }
+
+ pub fn sync_send(mut self) -> Self {
+ self.tester.sync_send();
+ self
+ }
+
+ pub fn parse(mut self) -> R
+ where
+ R: FromBytes,
+ {
+ self.tester.parse::()
+ }
+
+ pub fn error(mut self) -> ::Error { self.tester.error() }
+
+ pub fn assert_error(mut self) -> Self {
+ self.tester.assert_error();
+ self
+ }
+
+ pub fn assert_success(mut self) -> Self {
+ self.tester.assert_success();
+ self
+ }
+}
+
+pub struct RandomUserTester {
+ context: TesterContext,
+ err_phantom: PhantomData,
+}
+
+impl RandomUserTester
+where
+ Error: FromBytes + Debug,
+{
+ pub fn new() -> Self {
+ Self {
+ context: TesterContext::default(),
+ err_phantom: PhantomData,
+ }
+ }
+}
+
+impl TesterTrait for RandomUserTester
+where
+ Error: FromBytes + Debug,
+{
+ type Error = Error;
+
+ fn mut_context(&mut self) -> &mut TesterContext { &mut self.context }
+
+ fn context(&self) -> &TesterContext { &self.context }
+}
+
+pub struct FixedUserTester {
+ context: TesterContext,
+ err_phantom: PhantomData,
+}
+
+impl FixedUserTester
+where
+ Error: FromBytes + Debug,
+{
+ pub fn new() -> Self {
+ Self {
+ context: TesterContext::new(valid_email()),
+ err_phantom: PhantomData,
+ }
+ }
+}
+
+impl TesterTrait for FixedUserTester
+where
+ Error: FromBytes + Debug,
+{
+ type Error = Error;
+
+ fn mut_context(&mut self) -> &mut TesterContext { &mut self.context }
+
+ fn context(&self) -> &TesterContext { &self.context }
+}
diff --git a/rust-lib/flowy-test/src/helper.rs b/rust-lib/flowy-test/src/helper.rs
new file mode 100644
index 0000000000..f13adeba12
--- /dev/null
+++ b/rust-lib/flowy-test/src/helper.rs
@@ -0,0 +1,24 @@
+use flowy_infra::uuid;
+use std::{fs, path::PathBuf};
+
+pub fn root_dir() -> String {
+ // https://doc.rust-lang.org/cargo/reference/environment-variables.html
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or("./".to_owned());
+ let mut path_buf = fs::canonicalize(&PathBuf::from(&manifest_dir)).unwrap();
+ path_buf.pop(); // rust-lib
+ path_buf.push("flowy-test");
+ path_buf.push("temp");
+ path_buf.push("flowy");
+
+ let root_dir = path_buf.to_str().unwrap().to_string();
+ if !std::path::Path::new(&root_dir).exists() {
+ std::fs::create_dir_all(&root_dir).unwrap();
+ }
+ root_dir
+}
+
+pub fn random_valid_email() -> String { format!("{}@appflowy.io", uuid()) }
+
+pub fn valid_email() -> String { "annie@appflowy.io".to_string() }
+
+pub fn valid_password() -> String { "HelloWorld!123".to_string() }
diff --git a/rust-lib/flowy-test/src/lib.rs b/rust-lib/flowy-test/src/lib.rs
index 9c89eafc34..15187a56c5 100644
--- a/rust-lib/flowy-test/src/lib.rs
+++ b/rust-lib/flowy-test/src/lib.rs
@@ -1,253 +1,24 @@
-use flowy_dispatch::prelude::*;
-pub use flowy_sdk::*;
-use flowy_user::{
- errors::UserError,
- event::UserEvent::{SignIn, SignOut},
- prelude::*,
-};
-use std::{
- convert::TryFrom,
- fmt::{Debug, Display},
- fs,
- hash::Hash,
- marker::PhantomData,
- path::PathBuf,
- sync::Once,
- thread,
-};
+pub mod builder;
+mod helper;
+mod tester;
+
+use crate::helper::root_dir;
+use flowy_sdk::{ArcFlowyServer, FlowySDK};
+use std::sync::Once;
pub mod prelude {
- pub use crate::Tester;
+ pub use crate::{
+ builder::{TestBuilder, *},
+ helper::*,
+ };
pub use flowy_dispatch::prelude::*;
- pub use std::convert::TryFrom;
}
static INIT: Once = Once::new();
-pub fn init_sdk() {
+pub fn init_test_sdk(server: ArcFlowyServer) {
let root_dir = root_dir();
INIT.call_once(|| {
- FlowySDK::new(&root_dir).construct();
+ FlowySDK::construct_with(&root_dir, server);
});
}
-
-fn root_dir() -> String {
- // https://doc.rust-lang.org/cargo/reference/environment-variables.html
- let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or("./".to_owned());
- let mut path_buf = fs::canonicalize(&PathBuf::from(&manifest_dir)).unwrap();
- path_buf.pop(); // rust-lib
- path_buf.push("flowy-test");
- path_buf.push("temp");
- path_buf.push("flowy");
-
- let root_dir = path_buf.to_str().unwrap().to_string();
- if !std::path::Path::new(&root_dir).exists() {
- std::fs::create_dir_all(&root_dir).unwrap();
- }
- root_dir
-}
-
-pub struct TestBuilder