2021-09-10 10:21:35 +00:00
|
|
|
use crate::helper::*;
|
2021-08-25 09:34:20 +00:00
|
|
|
use flowy_workspace::entities::{
|
2021-09-10 10:21:35 +00:00
|
|
|
app::{DeleteAppParams, QueryAppParams, UpdateAppParams},
|
2021-09-11 12:09:46 +00:00
|
|
|
view::{DeleteViewParams, QueryViewParams, UpdateViewParams},
|
2021-08-25 09:34:20 +00:00
|
|
|
workspace::{
|
|
|
|
CreateWorkspaceParams,
|
|
|
|
DeleteWorkspaceParams,
|
|
|
|
QueryWorkspaceParams,
|
|
|
|
UpdateWorkspaceParams,
|
|
|
|
},
|
|
|
|
};
|
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;
|
|
|
|
log::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;
|
|
|
|
let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
log::info!("{:?}", test.server.read_workspaces(read_params).await);
|
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;
|
|
|
|
|
|
|
|
let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
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;
|
|
|
|
let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
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-08-25 09:34:20 +00:00
|
|
|
let delete_params = DeleteWorkspaceParams {
|
2021-09-10 10:21:35 +00:00
|
|
|
workspace_id: 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;
|
|
|
|
let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id);
|
|
|
|
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;
|
|
|
|
log::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;
|
|
|
|
let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
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-09-10 10:21:35 +00:00
|
|
|
let read_params = QueryAppParams::new(&test.app.id).read_belongings();
|
|
|
|
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
|
|
|
|
|
|
|
let update_params = UpdateViewParams::new(&view.id).trash();
|
2021-09-10 10:21:35 +00:00
|
|
|
test.server.update_view(update_params).await;
|
2021-08-26 09:58:59 +00:00
|
|
|
|
2021-09-10 10:21:35 +00:00
|
|
|
let read_params = QueryAppParams::new(&test.app.id).read_belongings();
|
|
|
|
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;
|
|
|
|
|
|
|
|
let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
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
|
|
|
|
|
|
|
let delete_params = DeleteAppParams {
|
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;
|
|
|
|
let read_params = QueryAppParams::new(&test.app.id);
|
|
|
|
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;
|
|
|
|
log::info!("{:?}", test.view);
|
2021-08-25 13:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn view_update() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = ViewTest::new().await;
|
|
|
|
let new_name = "name view name";
|
2021-08-25 13:33:29 +00:00
|
|
|
|
|
|
|
// update
|
2021-09-10 10:21:35 +00:00
|
|
|
let update_params = UpdateViewParams::new(&test.view.id).trash().name(new_name);
|
|
|
|
test.server.update_view(update_params).await;
|
2021-08-25 13:33:29 +00:00
|
|
|
|
|
|
|
// read
|
2021-09-10 10:21:35 +00:00
|
|
|
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);
|
2021-08-25 13:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn view_delete() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let test = ViewTest::new().await;
|
2021-08-25 13:33:29 +00:00
|
|
|
// delete
|
|
|
|
let delete_params = DeleteViewParams {
|
2021-09-10 10:21:35 +00:00
|
|
|
view_id: test.view.id.clone(),
|
2021-08-25 13:33:29 +00:00
|
|
|
};
|
2021-09-10 10:21:35 +00:00
|
|
|
test.server.delete_view(delete_params).await;
|
2021-08-25 13:33:29 +00:00
|
|
|
|
|
|
|
// read
|
2021-09-10 10:21:35 +00:00
|
|
|
let read_params = QueryViewParams::new(&test.view.id).trash();
|
|
|
|
assert_eq!(test.server.read_view(read_params).await.is_none(), true);
|
2021-08-25 13:33:29 +00:00
|
|
|
}
|
2021-08-26 09:58:59 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn workspace_list_read() {
|
2021-09-10 10:21:35 +00:00
|
|
|
let mut server = spawn_server().await;
|
|
|
|
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-09-02 06:47:39 +00:00
|
|
|
let read_params = QueryWorkspaceParams::new();
|
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);
|
|
|
|
}
|