2021-12-02 13:54:21 +00:00
|
|
|
#![allow(clippy::all)]
|
2021-11-19 05:42:53 +00:00
|
|
|
use crate::util::helper::*;
|
2021-11-08 02:57:33 +00:00
|
|
|
use flowy_workspace_infra::entities::{
|
2021-10-30 09:19:50 +00:00
|
|
|
app::{AppIdentifier, UpdateAppParams},
|
2021-10-18 14:46:05 +00:00
|
|
|
trash::{TrashIdentifier, TrashIdentifiers, TrashType},
|
2021-10-16 08:45:52 +00:00
|
|
|
view::{UpdateViewParams, ViewIdentifier},
|
2021-11-10 15:39:51 +00:00
|
|
|
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdentifier},
|
2021-08-25 09:34:20 +00:00
|
|
|
};
|
2021-08-24 13:38:53 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_create() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = WorkspaceTest::new().await;
|
2021-11-03 07:37:38 +00:00
|
|
|
tracing::info!("{:?}", test.workspace);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
2021-08-24 13:38:53 +00:00
|
|
|
|
2021-08-25 09:34:20 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_read() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = WorkspaceTest::new().await;
|
2021-11-08 11:19:02 +00:00
|
|
|
let read_params = WorkspaceIdentifier::new(Some(test.workspace.id.clone()));
|
2021-11-07 08:58:06 +00:00
|
|
|
let repeated_workspace = test.server.read_workspaces(read_params).await;
|
|
|
|
tracing::info!("{:?}", repeated_workspace);
|
2021-08-24 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 02:19:50 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_read_with_belongs() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = WorkspaceTest::new().await;
|
|
|
|
|
|
|
|
let _ = test.create_app().await;
|
|
|
|
let _ = test.create_app().await;
|
|
|
|
let _ = test.create_app().await;
|
|
|
|
|
2021-11-08 11:19:02 +00:00
|
|
|
let read_params = WorkspaceIdentifier::new(Some(test.workspace.id.clone()));
|
2021-09-10 10:21:35 +00:00
|
|
|
let workspaces = test.server.read_workspaces(read_params).await;
|
2021-08-27 15:53:53 +00:00
|
|
|
let workspace = workspaces.items.first().unwrap();
|
2021-08-26 02:19:50 +00:00
|
|
|
assert_eq!(workspace.apps.len(), 3);
|
|
|
|
}
|
|
|
|
|
2021-08-24 13:38:53 +00:00
|
|
|
#[actix_rt::test]
|
2021-08-25 09:34:20 +00:00
|
|
|
async fn workspace_update() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = WorkspaceTest::new().await;
|
|
|
|
let new_name = "rename workspace name";
|
|
|
|
let new_desc = "rename workspace description";
|
|
|
|
|
2021-08-25 09:34:20 +00:00
|
|
|
let update_params = UpdateWorkspaceParams {
|
2021-09-10 10:21:35 +00:00
|
|
|
id: test.workspace.id.clone(),
|
|
|
|
name: Some(new_name.to_string()),
|
|
|
|
desc: Some(new_desc.to_string()),
|
2021-08-24 13:38:53 +00:00
|
|
|
};
|
2021-09-10 10:21:35 +00:00
|
|
|
test.server.update_workspace(update_params).await;
|
2021-11-08 11:19:02 +00:00
|
|
|
let read_params = WorkspaceIdentifier::new(Some(test.workspace.id.clone()));
|
2021-09-10 10:21:35 +00:00
|
|
|
let repeated_workspace = test.server.read_workspaces(read_params).await;
|
2021-08-24 13:38:53 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let workspace = repeated_workspace.first().unwrap();
|
|
|
|
assert_eq!(workspace.name, new_name);
|
|
|
|
assert_eq!(workspace.desc, new_desc);
|
2021-08-24 13:38:53 +00:00
|
|
|
}
|
2021-08-25 09:34:20 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_delete() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = WorkspaceTest::new().await;
|
2021-11-10 15:39:51 +00:00
|
|
|
let delete_params = WorkspaceIdentifier {
|
2021-11-12 13:44:26 +00:00
|
|
|
workspace_id: Some(test.workspace.id.clone()),
|
2021-08-25 09:34:20 +00:00
|
|
|
};
|
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let _ = test.server.delete_workspace(delete_params).await;
|
2021-11-08 11:19:02 +00:00
|
|
|
let read_params = WorkspaceIdentifier::new(Some(test.workspace.id.clone()));
|
2021-09-10 10:21:35 +00:00
|
|
|
let repeated_workspace = test.server.read_workspaces(read_params).await;
|
2021-08-27 15:53:53 +00:00
|
|
|
assert_eq!(repeated_workspace.len(), 0);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_create() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-11-03 07:37:38 +00:00
|
|
|
tracing::info!("{:?}", test.app);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_read() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-10-16 04:24:02 +00:00
|
|
|
let read_params = AppIdentifier::new(&test.app.id);
|
2021-09-10 10:21:35 +00:00
|
|
|
assert_eq!(test.server.read_app(read_params).await.is_some(), true);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 02:19:50 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_read_with_belongs() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-08-26 02:19:50 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let _ = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
let _ = create_test_view(&test.server, &test.app.id).await;
|
2021-08-26 02:19:50 +00:00
|
|
|
|
2021-10-16 04:24:02 +00:00
|
|
|
let read_params = AppIdentifier::new(&test.app.id);
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = test.server.read_app(read_params).await.unwrap();
|
2021-08-26 02:19:50 +00:00
|
|
|
assert_eq!(app.belongings.len(), 2);
|
|
|
|
}
|
|
|
|
|
2021-08-26 09:58:59 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_read_with_belongs_in_trash() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-08-26 09:58:59 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let _ = create_test_view(&test.server, &test.app.id).await;
|
|
|
|
let view = create_test_view(&test.server, &test.app.id).await;
|
2021-08-26 09:58:59 +00:00
|
|
|
|
2021-10-17 14:44:51 +00:00
|
|
|
test.server.create_view_trash(&view.id).await;
|
2021-08-26 09:58:59 +00:00
|
|
|
|
2021-10-16 04:24:02 +00:00
|
|
|
let read_params = AppIdentifier::new(&test.app.id);
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = test.server.read_app(read_params).await.unwrap();
|
2021-08-26 09:58:59 +00:00
|
|
|
assert_eq!(app.belongings.len(), 1);
|
|
|
|
}
|
|
|
|
|
2021-08-25 09:34:20 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_update() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-08-25 09:34:20 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let new_name = "flowy";
|
2021-08-25 09:34:20 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let update_params = UpdateAppParams::new(&test.app.id).name(new_name);
|
|
|
|
test.server.update_app(update_params).await;
|
|
|
|
|
2021-10-16 04:24:02 +00:00
|
|
|
let read_params = AppIdentifier::new(&test.app.id);
|
2021-09-10 10:21:35 +00:00
|
|
|
let app = test.server.read_app(read_params).await.unwrap();
|
|
|
|
assert_eq!(&app.name, new_name);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn app_delete() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = AppTest::new().await;
|
2021-08-25 09:34:20 +00:00
|
|
|
|
2021-10-30 09:19:50 +00:00
|
|
|
let delete_params = AppIdentifier {
|
2021-09-10 10:21:35 +00:00
|
|
|
app_id: test.app.id.clone(),
|
2021-08-25 09:34:20 +00:00
|
|
|
};
|
2021-09-10 10:21:35 +00:00
|
|
|
test.server.delete_app(delete_params).await;
|
2021-10-16 04:24:02 +00:00
|
|
|
let read_params = AppIdentifier::new(&test.app.id);
|
2021-09-10 10:21:35 +00:00
|
|
|
assert_eq!(test.server.read_app(read_params).await.is_none(), true);
|
2021-08-25 09:34:20 +00:00
|
|
|
}
|
2021-08-25 13:33:29 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn view_create() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = ViewTest::new().await;
|
2021-11-03 07:37:38 +00:00
|
|
|
tracing::info!("{:?}", test.view);
|
2021-08-25 13:33:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 08:45:52 +00:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn view_update() {
|
|
|
|
let test = ViewTest::new().await;
|
|
|
|
let new_name = "name view name";
|
|
|
|
|
|
|
|
// update
|
|
|
|
let update_params = UpdateViewParams::new(&test.view.id).name(new_name);
|
|
|
|
test.server.update_view(update_params).await;
|
|
|
|
|
|
|
|
// read
|
2021-10-19 05:04:09 +00:00
|
|
|
let read_params: ViewIdentifier = test.view.id.clone().into();
|
2021-10-16 08:45:52 +00:00
|
|
|
let view = test.server.read_view(read_params).await.unwrap();
|
|
|
|
assert_eq!(&view.name, new_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn view_delete() {
|
|
|
|
let test = ViewTest::new().await;
|
2021-10-17 14:44:51 +00:00
|
|
|
test.server.create_view_trash(&test.view.id).await;
|
2021-10-16 08:45:52 +00:00
|
|
|
|
2021-10-16 09:05:53 +00:00
|
|
|
let trash_ids = test
|
|
|
|
.server
|
|
|
|
.read_trash()
|
|
|
|
.await
|
|
|
|
.items
|
|
|
|
.into_iter()
|
|
|
|
.map(|item| item.id)
|
|
|
|
.collect::<Vec<String>>();
|
2021-10-16 08:45:52 +00:00
|
|
|
// read
|
2021-10-19 05:04:09 +00:00
|
|
|
let read_params: ViewIdentifier = test.view.id.clone().into();
|
2021-10-16 09:05:53 +00:00
|
|
|
|
|
|
|
// the view can't read from the server. it should be in the trash
|
2021-10-16 08:45:52 +00:00
|
|
|
assert_eq!(test.server.read_view(read_params).await.is_none(), true);
|
2021-10-16 09:05:53 +00:00
|
|
|
assert_eq!(trash_ids.contains(&test.view.id), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
2021-10-18 14:46:05 +00:00
|
|
|
async fn trash_delete() {
|
2021-10-16 09:05:53 +00:00
|
|
|
let test = ViewTest::new().await;
|
2021-10-17 14:44:51 +00:00
|
|
|
test.server.create_view_trash(&test.view.id).await;
|
2021-10-16 09:05:53 +00:00
|
|
|
|
2021-10-18 14:46:05 +00:00
|
|
|
let identifier = TrashIdentifier {
|
|
|
|
id: test.view.id.clone(),
|
|
|
|
ty: TrashType::View,
|
|
|
|
};
|
|
|
|
test.server.delete_view_trash(vec![identifier].into()).await;
|
|
|
|
|
|
|
|
assert_eq!(test.server.read_trash().await.is_empty(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn trash_delete_all() {
|
|
|
|
let test = ViewTest::new().await;
|
|
|
|
test.server.create_view_trash(&test.view.id).await;
|
|
|
|
|
|
|
|
test.server.delete_view_trash(TrashIdentifiers::all()).await;
|
2021-10-16 09:05:53 +00:00
|
|
|
assert_eq!(test.server.read_trash().await.is_empty(), true);
|
2021-10-16 08:45:52 +00:00
|
|
|
}
|
2021-08-26 09:58:59 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_list_read() {
|
2021-09-27 15:23:23 +00:00
|
|
|
let mut server = spawn_user_server().await;
|
2021-09-10 10:21:35 +00:00
|
|
|
let token = server.register_user().await.token;
|
|
|
|
server.user_token = Some(token);
|
2021-08-26 09:58:59 +00:00
|
|
|
for i in 0..3 {
|
|
|
|
let params = CreateWorkspaceParams {
|
|
|
|
name: format!("{} workspace", i),
|
|
|
|
desc: format!("This is my {} workspace", i),
|
|
|
|
};
|
2021-09-10 10:21:35 +00:00
|
|
|
let _ = server.create_workspace(params).await;
|
2021-08-26 09:58:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 07:32:57 +00:00
|
|
|
let read_params = WorkspaceIdentifier::new(None);
|
2021-09-10 10:21:35 +00:00
|
|
|
let workspaces = server.read_workspaces(read_params).await;
|
2021-08-26 09:58:59 +00:00
|
|
|
assert_eq!(workspaces.len(), 4);
|
|
|
|
}
|