Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

[client]: add putback test

appflowyab36f520de7d
diff --git a/rust-lib/flowy-test/src/workspace.rs b/rust-lib/flowy-test/src/workspace.rs
index 4a69b355ce..3f56440aec 100644
--- a/rust-lib/flowy-test/src/workspace.rs
+++ b/rust-lib/flowy-test/src/workspace.rs
@@ -1,7 +1,12 @@
use crate::prelude::*;
use flowy_document::entities::doc::Doc;
use flowy_workspace::{
- entities::{app::*, view::*, workspace::*},
+ entities::{
+ app::*,
+ trash::{RepeatedTrash, TrashIdentifier},
+ view::*,
+ workspace::*,
+ },
event::WorkspaceEvent::*,
};
@@ -233,6 +238,22 @@ pub async fn delete_view(sdk: &FlowyTestSDK, request: DeleteViewRequest) {
.await;
}
+pub async fn read_trash(sdk: &FlowyTestSDK) -> RepeatedTrash {
+ FlowyWorkspaceTest::new(sdk.clone())
+ .event(ReadTrash)
+ .async_send()
+ .await
+ .parse::<RepeatedTrash>()
+}
+
+pub async fn putback_trash(sdk: &FlowyTestSDK, id: TrashIdentifier) {
+ FlowyWorkspaceTest::new(sdk.clone())
+ .event(PutbackTrash)
+ .request(id)
+ .async_send()
+ .await;
+}
+
pub async fn open_view(sdk: &FlowyTestSDK, request: OpenViewRequest) -> Doc {
FlowyWorkspaceTest::new(sdk.clone())
.event(OpenView)
diff --git a/rust-lib/flowy-workspace/src/errors.rs b/rust-lib/flowy-workspace/src/errors.rs
index 4cecdeda6d..69be45d4a0 100644
--- a/rust-lib/flowy-workspace/src/errors.rs
+++ b/rust-lib/flowy-workspace/src/errors.rs
@@ -50,7 +50,7 @@ impl WorkspaceError {
static_workspace_error!(view_data, ErrorCode::ViewDataInvalid);
static_workspace_error!(unauthorized, ErrorCode::UserUnauthorized);
static_workspace_error!(internal, ErrorCode::InternalError);
- static_workspace_error!(not_found, ErrorCode::RecordNotFound);
+ static_workspace_error!(record_not_found, ErrorCode::RecordNotFound);
static_workspace_error!(ws, ErrorCode::WsConnectError);
pub fn context<T: Debug>(mut self, error: T) -> Self {
diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs
index 2f083fec18..fab248a337 100644
--- a/rust-lib/flowy-workspace/src/services/view_controller.rs
+++ b/rust-lib/flowy-workspace/src/services/view_controller.rs
@@ -83,6 +83,12 @@ impl ViewController {
pub(crate) async fn read_view(&self, params: ViewIdentifier) -> Result<View, WorkspaceError> {
let conn = self.database.db_connection()?;
let view_table = ViewTableSql::read_view(&params.view_id, &*conn)?;
+
+ let trash_ids = self.trash_can.trash_ids(&conn)?;
+ if trash_ids.contains(&view_table.id) {
+ return Err(WorkspaceError::record_not_found());
+ }
+
let view: View = view_table.into();
let _ = self.read_view_on_server(params);
Ok(view)
diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs
index b49115d2c7..4a0703a142 100644
--- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs
+++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs
@@ -191,7 +191,7 @@ impl WorkspaceController {
// Opti: fetch single workspace from local db
let mut repeated_workspace = self.read_local_workspaces(Some(workspace_id.clone()), user_id, conn)?;
if repeated_workspace.is_empty() {
- return Err(WorkspaceError::not_found().context(format!("{} workspace not found", workspace_id)));
+ return Err(WorkspaceError::record_not_found().context(format!("{} workspace not found", workspace_id)));
}
debug_assert_eq!(repeated_workspace.len(), 1);
@@ -313,9 +313,8 @@ fn set_current_workspace(workspace: &str) { KV::set_str(CURRENT_WORKSPACE_ID, wo
fn get_current_workspace() -> Result<String, WorkspaceError> {
match KV::get_str(CURRENT_WORKSPACE_ID) {
- None => {
- Err(WorkspaceError::not_found().context("Current workspace not found or should call open workspace first"))
- },
+ None => Err(WorkspaceError::record_not_found()
+ .context("Current workspace not found or should call open workspace first")),
Some(workspace_id) => Ok(workspace_id),
}
}
diff --git a/rust-lib/flowy-workspace/tests/workspace/view_test.rs b/rust-lib/flowy-workspace/tests/workspace/view_test.rs
index 77a275ee9d..af25f596d6 100644
--- a/rust-lib/flowy-workspace/tests/workspace/view_test.rs
+++ b/rust-lib/flowy-workspace/tests/workspace/view_test.rs
@@ -1,9 +1,9 @@
use flowy_test::{workspace::*, FlowyTest};
-use flowy_workspace::entities::view::*;
+use flowy_workspace::entities::{trash::TrashIdentifier, view::*};
#[tokio::test]
#[should_panic]
-async fn view_move_to_trash() {
+async fn view_delete() {
let test = FlowyTest::setup();
let _ = test.init_user();
@@ -13,6 +13,26 @@ async fn view_move_to_trash() {
let _ = read_view(&test.sdk, query).await;
}
+#[tokio::test]
+async fn view_delete_and_putback() {
+ let test = FlowyTest::setup();
+ let _ = test.init_user();
+
+ let test = ViewTest::new(&test).await;
+ test.delete().await;
+ putback_trash(
+ &test.sdk,
+ TrashIdentifier {
+ id: test.view.id.clone(),
+ },
+ )
+ .await;
+
+ let query = QueryViewRequest::new(&test.view.id);
+ let view = read_view(&test.sdk, query).await;
+ assert_eq!(&view, &test.view);
+}
+
#[tokio::test]
async fn view_open_doc() {
let test = FlowyTest::setup();