chore: add tests (#442)
This commit is contained in:
parent
632fbc6a7d
commit
feb993e5b9
|
|
@ -1421,7 +1421,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a7a990dfc62a766829d28d2a9bb383840d8146f4#a7a990dfc62a766829d28d2a9bb383840d8146f4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4#bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
|
@ -1445,7 +1445,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-document"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a7a990dfc62a766829d28d2a9bb383840d8146f4#a7a990dfc62a766829d28d2a9bb383840d8146f4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4#bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"collab",
|
||||
|
|
@ -1464,7 +1464,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-entity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a7a990dfc62a766829d28d2a9bb383840d8146f4#a7a990dfc62a766829d28d2a9bb383840d8146f4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4#bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
|
|
@ -1479,7 +1479,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "collab-folder"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=a7a990dfc62a766829d28d2a9bb383840d8146f4#a7a990dfc62a766829d28d2a9bb383840d8146f4"
|
||||
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4#bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -199,10 +199,10 @@ debug = true
|
|||
# will be removed when using yrs 0.18.2 that expose pendings
|
||||
yrs = { git = "https://github.com/appflowy/y-crdt", rev = "3f25bb510ca5274e7657d3713fbed41fb46b4487" }
|
||||
|
||||
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a7a990dfc62a766829d28d2a9bb383840d8146f4" }
|
||||
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a7a990dfc62a766829d28d2a9bb383840d8146f4" }
|
||||
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a7a990dfc62a766829d28d2a9bb383840d8146f4" }
|
||||
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "a7a990dfc62a766829d28d2a9bb383840d8146f4" }
|
||||
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4" }
|
||||
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4" }
|
||||
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4" }
|
||||
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bb25e76d08d1fc99d5044907aa6fe1e8eabd41d4" }
|
||||
|
||||
[features]
|
||||
ai_enable = []
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
use app_error::ErrorCode;
|
||||
use client_api_test_util::TestClient;
|
||||
use collab::core::transaction::DocTransactionExtension;
|
||||
use collab::preclude::Doc;
|
||||
use collab_entity::CollabType;
|
||||
use database_entity::dto::CreateCollabParams;
|
||||
use workspace_template::document::get_started::GetStartedDocumentTemplate;
|
||||
use workspace_template::WorkspaceTemplateBuilder;
|
||||
|
||||
#[tokio::test]
|
||||
async fn insert_empty_data_test() {
|
||||
let test_client = TestClient::new_user().await;
|
||||
let workspace_id = test_client.workspace_id().await;
|
||||
let object_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// test all collab type
|
||||
for collab_type in [
|
||||
CollabType::Folder,
|
||||
CollabType::Document,
|
||||
CollabType::UserAwareness,
|
||||
CollabType::WorkspaceDatabase,
|
||||
CollabType::Database,
|
||||
CollabType::DatabaseRow,
|
||||
] {
|
||||
let params = CreateCollabParams {
|
||||
workspace_id: workspace_id.clone(),
|
||||
object_id: object_id.clone(),
|
||||
encoded_collab_v1: vec![],
|
||||
collab_type,
|
||||
override_if_exist: false,
|
||||
};
|
||||
let error = test_client
|
||||
.api_client
|
||||
.create_collab(params)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(error.code, ErrorCode::InvalidRequest);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn insert_invalid_data_test() {
|
||||
let test_client = TestClient::new_user().await;
|
||||
let workspace_id = test_client.workspace_id().await;
|
||||
let object_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
let doc = Doc::new();
|
||||
let encoded_collab_v1 = doc.get_encoded_collab_v1().encode_to_bytes().unwrap();
|
||||
for collab_type in [
|
||||
CollabType::Folder,
|
||||
CollabType::Document,
|
||||
CollabType::UserAwareness,
|
||||
CollabType::WorkspaceDatabase,
|
||||
CollabType::Database,
|
||||
CollabType::DatabaseRow,
|
||||
] {
|
||||
let params = CreateCollabParams {
|
||||
workspace_id: workspace_id.clone(),
|
||||
object_id: object_id.clone(),
|
||||
encoded_collab_v1: encoded_collab_v1.clone(),
|
||||
collab_type: collab_type.clone(),
|
||||
override_if_exist: false,
|
||||
};
|
||||
let error = test_client
|
||||
.api_client
|
||||
.create_collab(params)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
error.code,
|
||||
ErrorCode::NoRequiredData,
|
||||
"collab_type: {:?}",
|
||||
collab_type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn insert_folder_data_success_test() {
|
||||
let test_client = TestClient::new_user().await;
|
||||
let workspace_id = test_client.workspace_id().await;
|
||||
let object_id = uuid::Uuid::new_v4().to_string();
|
||||
let uid = test_client.uid().await;
|
||||
|
||||
let templates = WorkspaceTemplateBuilder::new(uid, &workspace_id)
|
||||
.with_templates(vec![GetStartedDocumentTemplate])
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(templates.len(), 2);
|
||||
for (index, template) in templates.into_iter().enumerate() {
|
||||
if index == 0 {
|
||||
assert_eq!(template.object_type, CollabType::Document);
|
||||
}
|
||||
if index == 1 {
|
||||
assert_eq!(template.object_type, CollabType::Folder);
|
||||
}
|
||||
|
||||
let data = template.object_data.encode_to_bytes().unwrap();
|
||||
let params = CreateCollabParams {
|
||||
workspace_id: workspace_id.clone(),
|
||||
object_id: object_id.clone(),
|
||||
encoded_collab_v1: data,
|
||||
collab_type: template.object_type,
|
||||
override_if_exist: false,
|
||||
};
|
||||
test_client.api_client.create_collab(params).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
mod awareness_test;
|
||||
mod collab_curd_test;
|
||||
mod dirty_data_write_test;
|
||||
mod edit_permission;
|
||||
mod member_crud;
|
||||
mod missing_update_test;
|
||||
|
|
|
|||
Loading…
Reference in New Issue