|
@@ -1,6 +1,6 @@
|
|
-use crate::helper::{spawn_app, TestApp};
|
|
|
|
|
|
+use crate::helper::*;
|
|
use flowy_workspace::entities::{
|
|
use flowy_workspace::entities::{
|
|
- app::{App, ColorStyle, CreateAppParams, DeleteAppParams, QueryAppParams, UpdateAppParams},
|
|
|
|
|
|
+ app::{DeleteAppParams, QueryAppParams, UpdateAppParams},
|
|
view::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams, View, ViewType},
|
|
view::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams, View, ViewType},
|
|
workspace::{
|
|
workspace::{
|
|
CreateWorkspaceParams,
|
|
CreateWorkspaceParams,
|
|
@@ -13,246 +13,179 @@ use flowy_workspace::entities::{
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_create() {
|
|
async fn workspace_create() {
|
|
- let app = spawn_app().await;
|
|
|
|
- let (workspace, _) = create_test_workspace(&app).await;
|
|
|
|
- log::info!("{:?}", workspace);
|
|
|
|
|
|
+ let test = WorkspaceTest::new().await;
|
|
|
|
+ log::info!("{:?}", test.workspace);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_read() {
|
|
async fn workspace_read() {
|
|
- let app = spawn_app().await;
|
|
|
|
- let (workspace_1, token) = create_test_workspace(&app).await;
|
|
|
|
- let read_params = QueryWorkspaceParams::new().workspace_id(&workspace_1.id);
|
|
|
|
- log::info!("{:?}", app.read_workspaces(read_params, &token).await);
|
|
|
|
|
|
+ let test = WorkspaceTest::new().await;
|
|
|
|
+ let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
+ log::info!("{:?}", test.server.read_workspaces(read_params).await);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_read_with_belongs() {
|
|
async fn workspace_read_with_belongs() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let _ = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- let _ = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- let _ = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
-
|
|
|
|
- let read_params = QueryWorkspaceParams::new().workspace_id(&workspace.id);
|
|
|
|
- let workspaces = application.read_workspaces(read_params, &token).await;
|
|
|
|
|
|
+ let test = WorkspaceTest::new().await;
|
|
|
|
+
|
|
|
|
+ let _ = test.create_app().await;
|
|
|
|
+ let _ = test.create_app().await;
|
|
|
|
+ let _ = test.create_app().await;
|
|
|
|
+
|
|
|
|
+ let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
+ let workspaces = test.server.read_workspaces(read_params).await;
|
|
let workspace = workspaces.items.first().unwrap();
|
|
let workspace = workspaces.items.first().unwrap();
|
|
assert_eq!(workspace.apps.len(), 3);
|
|
assert_eq!(workspace.apps.len(), 3);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_update() {
|
|
async fn workspace_update() {
|
|
- let app = spawn_app().await;
|
|
|
|
- let (workspace_1, token) = create_test_workspace(&app).await;
|
|
|
|
|
|
+ let test = WorkspaceTest::new().await;
|
|
|
|
+ let new_name = "rename workspace name";
|
|
|
|
+ let new_desc = "rename workspace description";
|
|
|
|
+
|
|
let update_params = UpdateWorkspaceParams {
|
|
let update_params = UpdateWorkspaceParams {
|
|
- id: workspace_1.id.clone(),
|
|
|
|
- name: Some("workspace 2".to_string()),
|
|
|
|
- desc: Some("rename workspace description".to_string()),
|
|
|
|
|
|
+ id: test.workspace.id.clone(),
|
|
|
|
+ name: Some(new_name.to_string()),
|
|
|
|
+ desc: Some(new_desc.to_string()),
|
|
};
|
|
};
|
|
- app.update_workspace(update_params, &token).await;
|
|
|
|
|
|
+ test.server.update_workspace(update_params).await;
|
|
|
|
+ let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
+ let repeated_workspace = test.server.read_workspaces(read_params).await;
|
|
|
|
|
|
- let read_params = QueryWorkspaceParams::new().workspace_id(&workspace_1.id);
|
|
|
|
- let workspace_2 = app.read_workspaces(read_params, &token).await;
|
|
|
|
- log::info!("{:?}", workspace_2);
|
|
|
|
|
|
+ let workspace = repeated_workspace.first().unwrap();
|
|
|
|
+ assert_eq!(workspace.name, new_name);
|
|
|
|
+ assert_eq!(workspace.desc, new_desc);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_delete() {
|
|
async fn workspace_delete() {
|
|
- let app = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&app).await;
|
|
|
|
|
|
+ let test = WorkspaceTest::new().await;
|
|
let delete_params = DeleteWorkspaceParams {
|
|
let delete_params = DeleteWorkspaceParams {
|
|
- workspace_id: workspace.id.clone(),
|
|
|
|
|
|
+ workspace_id: test.workspace.id.clone(),
|
|
};
|
|
};
|
|
|
|
|
|
- let _ = app.delete_workspace(delete_params, &token).await;
|
|
|
|
- let read_params = QueryWorkspaceParams::new().workspace_id(&workspace.id);
|
|
|
|
- let repeated_workspace = app.read_workspaces(read_params, &token).await;
|
|
|
|
|
|
+ let _ = test.server.delete_workspace(delete_params).await;
|
|
|
|
+ let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
+ let repeated_workspace = test.server.read_workspaces(read_params).await;
|
|
assert_eq!(repeated_workspace.len(), 0);
|
|
assert_eq!(repeated_workspace.len(), 0);
|
|
}
|
|
}
|
|
|
|
|
|
-async fn create_test_workspace(app: &TestApp) -> (Workspace, String) {
|
|
|
|
- let response = app.register_test_user().await;
|
|
|
|
-
|
|
|
|
- let params = CreateWorkspaceParams {
|
|
|
|
- name: "My first workspace".to_string(),
|
|
|
|
- desc: "This is my first workspace".to_string(),
|
|
|
|
- };
|
|
|
|
- let workspace = app.create_workspace(params, &response.token).await;
|
|
|
|
- (workspace, response.token)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_create() {
|
|
async fn app_create() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- log::info!("{:?}", app);
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
+ log::info!("{:?}", test.app);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_read() {
|
|
async fn app_read() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- let read_params = QueryAppParams::new(&app.id);
|
|
|
|
- log::info!(
|
|
|
|
- "{:?}",
|
|
|
|
- application.read_app(read_params, &token).await.unwrap()
|
|
|
|
- );
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
+ let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
+ assert_eq!(test.server.read_app(read_params).await.is_some(), true);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_read_with_belongs() {
|
|
async fn app_read_with_belongs() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
|
|
- let _ = create_test_view(&application, &app.id, &token).await;
|
|
|
|
- let _ = create_test_view(&application, &app.id, &token).await;
|
|
|
|
|
|
+ let _ = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
+ let _ = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
|
|
- let read_params = QueryAppParams::new(&app.id).read_belongings();
|
|
|
|
- let app = application.read_app(read_params, &token).await.unwrap();
|
|
|
|
|
|
+ let read_params = QueryAppParams::new(&test.app.id).read_belongings();
|
|
|
|
+ let app = test.server.read_app(read_params).await.unwrap();
|
|
assert_eq!(app.belongings.len(), 2);
|
|
assert_eq!(app.belongings.len(), 2);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_read_with_belongs_in_trash() {
|
|
async fn app_read_with_belongs_in_trash() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
|
|
- let _ = create_test_view(&application, &app.id, &token).await;
|
|
|
|
- let view = create_test_view(&application, &app.id, &token).await;
|
|
|
|
|
|
+ let _ = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
+ let view = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
|
|
let update_params = UpdateViewParams::new(&view.id).trash();
|
|
let update_params = UpdateViewParams::new(&view.id).trash();
|
|
- application.update_view(update_params, &token).await;
|
|
|
|
|
|
+ test.server.update_view(update_params).await;
|
|
|
|
|
|
- let read_params = QueryAppParams::new(&app.id).read_belongings();
|
|
|
|
- let app = application.read_app(read_params, &token).await.unwrap();
|
|
|
|
|
|
+ let read_params = QueryAppParams::new(&test.app.id).read_belongings();
|
|
|
|
+ let app = test.server.read_app(read_params).await.unwrap();
|
|
assert_eq!(app.belongings.len(), 1);
|
|
assert_eq!(app.belongings.len(), 1);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_update() {
|
|
async fn app_update() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
|
|
- let update_params = UpdateAppParams::new(&app.id).name("flowy");
|
|
|
|
- application.update_app(update_params, &token).await;
|
|
|
|
|
|
+ let new_name = "flowy";
|
|
|
|
|
|
- let read_params = QueryAppParams::new(&app.id);
|
|
|
|
- let app = application.read_app(read_params, &token).await.unwrap();
|
|
|
|
- log::info!("{:?}", app);
|
|
|
|
|
|
+ let update_params = UpdateAppParams::new(&test.app.id).name(new_name);
|
|
|
|
+ test.server.update_app(update_params).await;
|
|
|
|
+
|
|
|
|
+ let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
+ let app = test.server.read_app(read_params).await.unwrap();
|
|
|
|
+ assert_eq!(&app.name, new_name);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn app_delete() {
|
|
async fn app_delete() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
|
|
+ let test = AppTest::new().await;
|
|
|
|
|
|
let delete_params = DeleteAppParams {
|
|
let delete_params = DeleteAppParams {
|
|
- app_id: app.id.clone(),
|
|
|
|
- };
|
|
|
|
- application.delete_app(delete_params, &token).await;
|
|
|
|
-
|
|
|
|
- let read_params = QueryAppParams::new(&app.id);
|
|
|
|
- assert_eq!(
|
|
|
|
- application.read_app(read_params, &token).await.is_none(),
|
|
|
|
- true
|
|
|
|
- );
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-async fn create_test_app(app: &TestApp, workspace_id: &str, token: &str) -> App {
|
|
|
|
- let params = CreateAppParams {
|
|
|
|
- workspace_id: workspace_id.to_owned(),
|
|
|
|
- name: "My first app".to_string(),
|
|
|
|
- desc: "This is my first app".to_string(),
|
|
|
|
- color_style: ColorStyle::default(),
|
|
|
|
|
|
+ app_id: test.app.id.clone(),
|
|
};
|
|
};
|
|
-
|
|
|
|
- let app = app.create_app(params, token).await;
|
|
|
|
- app
|
|
|
|
|
|
+ test.server.delete_app(delete_params).await;
|
|
|
|
+ let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
+ assert_eq!(test.server.read_app(read_params).await.is_none(), true);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn view_create() {
|
|
async fn view_create() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
-
|
|
|
|
- let view = create_test_view(&application, &app.id, &token).await;
|
|
|
|
- log::info!("{:?}", view);
|
|
|
|
|
|
+ let test = ViewTest::new().await;
|
|
|
|
+ log::info!("{:?}", test.view);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn view_update() {
|
|
async fn view_update() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- let view = create_test_view(&application, &app.id, &token).await;
|
|
|
|
|
|
+ let test = ViewTest::new().await;
|
|
|
|
+ let new_name = "name view name";
|
|
|
|
|
|
// update
|
|
// update
|
|
- let update_params = UpdateViewParams::new(&view.id)
|
|
|
|
- .trash()
|
|
|
|
- .name("new view name");
|
|
|
|
- application.update_view(update_params, &token).await;
|
|
|
|
|
|
+ let update_params = UpdateViewParams::new(&test.view.id).trash().name(new_name);
|
|
|
|
+ test.server.update_view(update_params).await;
|
|
|
|
|
|
// read
|
|
// read
|
|
- let read_params = QueryViewParams::new(&view.id).trash();
|
|
|
|
- let view = application.read_view(read_params, &token).await;
|
|
|
|
- log::info!("{:?}", view);
|
|
|
|
|
|
+ let read_params = QueryViewParams::new(&test.view.id).trash();
|
|
|
|
+ let view = test.server.read_view(read_params).await.unwrap();
|
|
|
|
+ assert_eq!(&view.name, new_name);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn view_delete() {
|
|
async fn view_delete() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let (workspace, token) = create_test_workspace(&application).await;
|
|
|
|
- let app = create_test_app(&application, &workspace.id, &token).await;
|
|
|
|
- let view = create_test_view(&application, &app.id, &token).await;
|
|
|
|
-
|
|
|
|
|
|
+ let test = ViewTest::new().await;
|
|
// delete
|
|
// delete
|
|
let delete_params = DeleteViewParams {
|
|
let delete_params = DeleteViewParams {
|
|
- view_id: view.id.clone(),
|
|
|
|
|
|
+ view_id: test.view.id.clone(),
|
|
};
|
|
};
|
|
- application.delete_view(delete_params, &token).await;
|
|
|
|
|
|
+ test.server.delete_view(delete_params).await;
|
|
|
|
|
|
// read
|
|
// read
|
|
- let read_params = QueryViewParams::new(&view.id).trash();
|
|
|
|
- assert_eq!(
|
|
|
|
- application.read_view(read_params, &token).await.is_none(),
|
|
|
|
- true
|
|
|
|
- );
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-async fn create_test_view(application: &TestApp, app_id: &str, token: &str) -> View {
|
|
|
|
- let params = CreateViewParams {
|
|
|
|
- belong_to_id: app_id.to_string(),
|
|
|
|
- name: "My first view".to_string(),
|
|
|
|
- desc: "This is my first view".to_string(),
|
|
|
|
- thumbnail: "http://1.png".to_string(),
|
|
|
|
- view_type: ViewType::Doc,
|
|
|
|
- };
|
|
|
|
- let app = application.create_view(params, token).await;
|
|
|
|
- app
|
|
|
|
|
|
+ let read_params = QueryViewParams::new(&test.view.id).trash();
|
|
|
|
+ assert_eq!(test.server.read_view(read_params).await.is_none(), true);
|
|
}
|
|
}
|
|
|
|
|
|
#[actix_rt::test]
|
|
#[actix_rt::test]
|
|
async fn workspace_list_read() {
|
|
async fn workspace_list_read() {
|
|
- let application = spawn_app().await;
|
|
|
|
- let response = application.register_test_user().await;
|
|
|
|
|
|
+ let mut server = spawn_server().await;
|
|
|
|
+ let token = server.register_user().await.token;
|
|
|
|
+ server.user_token = Some(token);
|
|
for i in 0..3 {
|
|
for i in 0..3 {
|
|
let params = CreateWorkspaceParams {
|
|
let params = CreateWorkspaceParams {
|
|
name: format!("{} workspace", i),
|
|
name: format!("{} workspace", i),
|
|
desc: format!("This is my {} workspace", i),
|
|
desc: format!("This is my {} workspace", i),
|
|
};
|
|
};
|
|
- let _ = application.create_workspace(params, &response.token).await;
|
|
|
|
|
|
+ let _ = server.create_workspace(params).await;
|
|
}
|
|
}
|
|
|
|
|
|
let read_params = QueryWorkspaceParams::new();
|
|
let read_params = QueryWorkspaceParams::new();
|
|
- let workspaces = application
|
|
|
|
- .read_workspaces(read_params, &response.token)
|
|
|
|
- .await;
|
|
|
|
|
|
+ let workspaces = server.read_workspaces(read_params).await;
|
|
assert_eq!(workspaces.len(), 4);
|
|
assert_eq!(workspaces.len(), 4);
|
|
}
|
|
}
|