chore: use database body for tests

This commit is contained in:
Zack Fu Zi Xiang 2024-09-10 13:12:03 +08:00
parent e22f316327
commit f7244f1217
No known key found for this signature in database
1 changed files with 18 additions and 25 deletions

View File

@ -9,6 +9,8 @@ use client_api::entity::{
use client_api_test::TestClient; use client_api_test::TestClient;
use client_api_test::{generate_unique_registered_user_client, localhost_client}; use client_api_test::{generate_unique_registered_user_client, localhost_client};
use collab::util::MapExt; use collab::util::MapExt;
use collab_database::database::DatabaseBody;
use collab_database::entity::FieldType;
use collab_database::views::DatabaseViews; use collab_database::views::DatabaseViews;
use collab_database::workspace_database::WorkspaceDatabaseBody; use collab_database::workspace_database::WorkspaceDatabaseBody;
use collab_document::document::Document; use collab_document::document::Document;
@ -21,8 +23,6 @@ use shared_entity::dto::workspace_dto::PublishedDuplicate;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use yrs::types::Map;
use yrs::MapRef;
use crate::workspace::published_data::{self}; use crate::workspace::published_data::{self};
@ -1200,31 +1200,24 @@ async fn duplicate_to_workspace_db_with_relation() {
.get_db_collab_from_view(&workspace_id_2, &related_db.view_id) .get_db_collab_from_view(&workspace_id_2, &related_db.view_id)
.await; .await;
let fields: MapRef = db_with_rel_col_collab let related_db_id: String = related_db_collab
.data .data
.get_with_path(&db_with_rel_col_collab.transact(), ["database", "fields"]) .get_with_path(&related_db_collab.transact(), ["database", "id"])
.unwrap(); .unwrap();
for (_k, v) in fields.iter(&db_with_rel_col_collab.transact()) {
for related_col_db_id in v let rel_col_db_body = DatabaseBody::from_collab(&db_with_rel_col_collab).unwrap();
.cast::<MapRef>() let txn = db_with_rel_col_collab.transact();
.unwrap() let all_fields = rel_col_db_body.fields.get_all_fields(&txn);
.get(&db_with_rel_col_collab.transact(), "type_option") all_fields
.unwrap() .iter()
.cast::<MapRef>() .map(|f| &f.type_options)
.unwrap() .flat_map(|t| t.iter())
.iter(&db_with_rel_col_collab.transact()) .filter(|(k, _v)| **k == FieldType::Relation.type_id())
.map(|(_k, v)| v.cast::<MapRef>().unwrap()) .map(|(_k, v)| v)
.flat_map(|v| v.get(&db_with_rel_col_collab.transact(), "database_id")) .flat_map(|v| v.iter())
.map(|v| v.to_string(&db_with_rel_col_collab.transact())) .for_each(|(_k, db_id)| {
.filter(|v| !v.is_empty()) assert_eq!(db_id.to_string(), related_db_id);
{ });
let related_db_id: String = related_db_collab
.data
.get_with_path(&related_db_collab.transact(), ["database", "id"])
.unwrap();
assert_eq!(related_db_id, related_col_db_id);
}
}
} }
} }
} }