mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: add database event tests (#2744)
* chore: add tests * test: add tests * test: add tests
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
use bytes::Bytes;
|
||||
use std::convert::TryFrom;
|
||||
use std::env::temp_dir;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -132,6 +134,49 @@ impl FlowyCoreTest {
|
||||
.parse::<flowy_folder2::entities::ViewPB>()
|
||||
}
|
||||
|
||||
pub async fn create_board(&self, parent_id: &str, name: String, initial_data: Vec<u8>) -> ViewPB {
|
||||
let payload = CreateViewPayloadPB {
|
||||
parent_view_id: parent_id.to_string(),
|
||||
name,
|
||||
desc: "".to_string(),
|
||||
thumbnail: None,
|
||||
layout: ViewLayoutPB::Board,
|
||||
initial_data,
|
||||
meta: Default::default(),
|
||||
set_as_current: true,
|
||||
};
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::CreateView)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<flowy_folder2::entities::ViewPB>()
|
||||
}
|
||||
|
||||
pub async fn create_calendar(
|
||||
&self,
|
||||
parent_id: &str,
|
||||
name: String,
|
||||
initial_data: Vec<u8>,
|
||||
) -> ViewPB {
|
||||
let payload = CreateViewPayloadPB {
|
||||
parent_view_id: parent_id.to_string(),
|
||||
name,
|
||||
desc: "".to_string(),
|
||||
thumbnail: None,
|
||||
layout: ViewLayoutPB::Calendar,
|
||||
initial_data,
|
||||
meta: Default::default(),
|
||||
set_as_current: true,
|
||||
};
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::CreateView)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<flowy_folder2::entities::ViewPB>()
|
||||
}
|
||||
|
||||
pub async fn get_database(&self, view_id: &str) -> DatabasePB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetDatabase)
|
||||
@ -238,7 +283,20 @@ impl FlowyCoreTest {
|
||||
.parse::<RowPB>()
|
||||
}
|
||||
|
||||
pub async fn get_row(&self, view_id: &str, row_id: &str) -> RowPB {
|
||||
pub async fn delete_row(&self, view_id: &str, row_id: &str) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::DeleteRow)
|
||||
.payload(RowIdPB {
|
||||
view_id: view_id.to_string(),
|
||||
row_id: row_id.to_string(),
|
||||
group_id: None,
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn get_row(&self, view_id: &str, row_id: &str) -> OptionalRowPB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetRow)
|
||||
.payload(RowIdPB {
|
||||
@ -248,7 +306,7 @@ impl FlowyCoreTest {
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RowPB>()
|
||||
.parse::<OptionalRowPB>()
|
||||
}
|
||||
|
||||
pub async fn duplicate_row(&self, view_id: &str, row_id: &str) -> Option<FlowyError> {
|
||||
@ -264,6 +322,19 @@ impl FlowyCoreTest {
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn move_row(&self, view_id: &str, row_id: &str, to_row_id: &str) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::MoveRow)
|
||||
.payload(MoveRowPayloadPB {
|
||||
view_id: view_id.to_string(),
|
||||
from_row_id: row_id.to_string(),
|
||||
to_row_id: to_row_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn update_cell(&self, changeset: CellChangesetPB) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::UpdateCell)
|
||||
@ -273,6 +344,15 @@ impl FlowyCoreTest {
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn update_date_cell(&self, changeset: DateChangesetPB) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::UpdateDateCell)
|
||||
.payload(changeset)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn get_cell(&self, view_id: &str, row_id: &str, field_id: &str) -> CellPB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetCell)
|
||||
@ -286,6 +366,41 @@ impl FlowyCoreTest {
|
||||
.parse::<CellPB>()
|
||||
}
|
||||
|
||||
pub async fn get_date_cell(&self, view_id: &str, row_id: &str, field_id: &str) -> DateCellDataPB {
|
||||
let cell = self.get_cell(view_id, row_id, field_id).await;
|
||||
DateCellDataPB::try_from(Bytes::from(cell.data)).unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_checklist_cell(
|
||||
&self,
|
||||
view_id: &str,
|
||||
field_id: &str,
|
||||
row_id: &str,
|
||||
) -> ChecklistCellDataPB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetChecklistCellData)
|
||||
.payload(CellIdPB {
|
||||
view_id: view_id.to_string(),
|
||||
row_id: row_id.to_string(),
|
||||
field_id: field_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<ChecklistCellDataPB>()
|
||||
}
|
||||
|
||||
pub async fn update_checklist_cell(
|
||||
&self,
|
||||
changeset: ChecklistCellDataChangesetPB,
|
||||
) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::UpdateChecklistCell)
|
||||
.payload(changeset)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn insert_option(
|
||||
&self,
|
||||
view_id: &str,
|
||||
@ -317,6 +432,84 @@ impl FlowyCoreTest {
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn get_groups(&self, view_id: &str) -> Vec<GroupPB> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetGroups)
|
||||
.payload(DatabaseViewIdPB {
|
||||
value: view_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RepeatedGroupPB>()
|
||||
.items
|
||||
}
|
||||
|
||||
pub async fn move_group(&self, view_id: &str, from_id: &str, to_id: &str) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::MoveGroup)
|
||||
.payload(MoveGroupPayloadPB {
|
||||
view_id: view_id.to_string(),
|
||||
from_group_id: from_id.to_string(),
|
||||
to_group_id: to_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn set_group_by_field(&self, view_id: &str, field_id: &str) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::SetGroupByField)
|
||||
.payload(GroupByFieldPayloadPB {
|
||||
field_id: field_id.to_string(),
|
||||
view_id: view_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn update_group(
|
||||
&self,
|
||||
view_id: &str,
|
||||
group_id: &str,
|
||||
name: Option<String>,
|
||||
visible: Option<bool>,
|
||||
) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::UpdateGroup)
|
||||
.payload(UpdateGroupPB {
|
||||
view_id: view_id.to_string(),
|
||||
group_id: group_id.to_string(),
|
||||
name,
|
||||
visible,
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn update_setting(&self, changeset: DatabaseSettingChangesetPB) -> Option<FlowyError> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::UpdateDatabaseSetting)
|
||||
.payload(changeset)
|
||||
.async_send()
|
||||
.await
|
||||
.error()
|
||||
}
|
||||
|
||||
pub async fn get_all_calendar_events(&self, view_id: &str) -> Vec<CalendarEventPB> {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_database2::event_map::DatabaseEvent::GetAllCalendarEvents)
|
||||
.payload(CalendarEventRequestPB {
|
||||
view_id: view_id.to_string(),
|
||||
})
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RepeatedCalendarEventPB>()
|
||||
.items
|
||||
}
|
||||
|
||||
pub async fn get_view(&self, view_id: &str) -> ViewPB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::ReadView)
|
||||
|
Reference in New Issue
Block a user