2021-07-23 06:37:18 +00:00
|
|
|
pub use flowy_test::builder::SingleUserTestBuilder;
|
2021-07-20 06:03:21 +00:00
|
|
|
use flowy_workspace::{
|
2021-07-20 07:51:49 +00:00
|
|
|
entities::{app::*, view::*, workspace::*},
|
|
|
|
event::WorkspaceEvent::*,
|
2021-07-20 06:03:21 +00:00
|
|
|
};
|
2021-07-14 13:12:52 +00:00
|
|
|
|
|
|
|
pub(crate) fn invalid_workspace_name_test_case() -> Vec<String> {
|
|
|
|
vec!["", "1234".repeat(100).as_str()]
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
}
|
2021-07-20 06:03:21 +00:00
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
pub fn create_workspace(name: &str, desc: &str) -> (String, Workspace) {
|
|
|
|
let builder = SingleUserTestBuilder::new();
|
|
|
|
let user_id = builder.user_detail.as_ref().unwrap().id.clone();
|
|
|
|
|
2021-07-20 06:03:21 +00:00
|
|
|
let request = CreateWorkspaceRequest {
|
|
|
|
name: name.to_owned(),
|
|
|
|
desc: desc.to_owned(),
|
2021-08-29 14:00:42 +00:00
|
|
|
user_id: user_id.clone(),
|
2021-07-20 06:03:21 +00:00
|
|
|
};
|
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
let workspace = builder
|
2021-07-20 06:03:21 +00:00
|
|
|
.event(CreateWorkspace)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<Workspace>();
|
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
(user_id, workspace)
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
pub fn read_workspaces(request: QueryWorkspaceRequest) -> Option<Workspace> {
|
|
|
|
let mut repeated_workspace = SingleUserTestBuilder::new()
|
2021-07-29 09:27:59 +00:00
|
|
|
.event(ReadWorkspace)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
2021-08-29 14:00:42 +00:00
|
|
|
.parse::<RepeatedWorkspace>();
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
debug_assert_eq!(repeated_workspace.len(), 1);
|
|
|
|
repeated_workspace
|
|
|
|
.drain(..1)
|
|
|
|
.collect::<Vec<Workspace>>()
|
|
|
|
.pop()
|
2021-07-29 09:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 14:00:42 +00:00
|
|
|
pub fn create_app(name: &str, desc: &str, workspace_id: &str) -> App {
|
2021-07-20 06:03:21 +00:00
|
|
|
let create_app_request = CreateAppRequest {
|
2021-08-29 14:00:42 +00:00
|
|
|
workspace_id: workspace_id.to_owned(),
|
2021-07-20 06:03:21 +00:00
|
|
|
name: name.to_string(),
|
|
|
|
desc: desc.to_string(),
|
|
|
|
color_style: Default::default(),
|
|
|
|
};
|
|
|
|
|
2021-07-23 06:37:18 +00:00
|
|
|
let app = SingleUserTestBuilder::new()
|
2021-07-20 06:03:21 +00:00
|
|
|
.event(CreateApp)
|
|
|
|
.request(create_app_request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<App>();
|
|
|
|
app
|
|
|
|
}
|
|
|
|
|
2021-07-29 09:27:59 +00:00
|
|
|
pub fn delete_app(app_id: &str) {
|
|
|
|
let delete_app_request = DeleteAppRequest {
|
|
|
|
app_id: app_id.to_string(),
|
|
|
|
};
|
2021-07-20 06:03:21 +00:00
|
|
|
|
2021-07-29 09:27:59 +00:00
|
|
|
SingleUserTestBuilder::new()
|
|
|
|
.event(DeleteApp)
|
|
|
|
.request(delete_app_request)
|
|
|
|
.sync_send();
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
2021-07-20 07:51:49 +00:00
|
|
|
|
2021-07-29 09:27:59 +00:00
|
|
|
pub fn update_app(request: UpdateAppRequest) {
|
|
|
|
SingleUserTestBuilder::new()
|
|
|
|
.event(UpdateApp)
|
|
|
|
.request(request)
|
|
|
|
.sync_send();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_app(request: QueryAppRequest) -> App {
|
2021-07-23 06:37:18 +00:00
|
|
|
let app = SingleUserTestBuilder::new()
|
2021-07-29 09:27:59 +00:00
|
|
|
.event(ReadApp)
|
2021-07-20 07:51:49 +00:00
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<App>();
|
|
|
|
|
|
|
|
app
|
|
|
|
}
|
|
|
|
|
2021-07-29 09:27:59 +00:00
|
|
|
pub fn create_view_with_request(request: CreateViewRequest) -> View {
|
2021-07-23 06:37:18 +00:00
|
|
|
let view = SingleUserTestBuilder::new()
|
2021-07-20 07:51:49 +00:00
|
|
|
.event(CreateView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<View>();
|
|
|
|
|
|
|
|
view
|
|
|
|
}
|
2021-07-29 09:27:59 +00:00
|
|
|
|
|
|
|
pub fn create_view() -> View {
|
2021-08-29 14:00:42 +00:00
|
|
|
let workspace = create_workspace("Workspace", "").1;
|
|
|
|
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
|
2021-07-29 09:27:59 +00:00
|
|
|
let request = CreateViewRequest {
|
|
|
|
belong_to_id: app.id.clone(),
|
|
|
|
name: "View A".to_string(),
|
|
|
|
desc: "".to_string(),
|
|
|
|
thumbnail: None,
|
|
|
|
view_type: ViewType::Doc,
|
|
|
|
};
|
|
|
|
|
|
|
|
create_view_with_request(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_view(request: UpdateViewRequest) {
|
|
|
|
SingleUserTestBuilder::new()
|
|
|
|
.event(UpdateView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_view(request: QueryViewRequest) -> View {
|
|
|
|
SingleUserTestBuilder::new()
|
|
|
|
.event(ReadView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<View>()
|
|
|
|
}
|