backend
This commit is contained in:
@@ -18,6 +18,8 @@ struct DocumentInfo {
|
||||
title: String,
|
||||
filename: String,
|
||||
original_name: String,
|
||||
#[serde(default)]
|
||||
folder_id: Option<Uuid>,
|
||||
deleted_at: Option<String>,
|
||||
issued_at: Option<String>,
|
||||
metadata: Value,
|
||||
@@ -1632,3 +1634,158 @@ async fn patch_document_updates_multiple_fields() -> Result<()> {
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_documents_by_status_filter() -> Result<()> {
|
||||
let _lock = acquire_db_lock().await;
|
||||
let app = TestApp::new().await?;
|
||||
|
||||
let password = "statusfilter";
|
||||
app.insert_user("statususer", password, "admin").await?;
|
||||
let token = app.login_token("statususer", password).await?;
|
||||
|
||||
let upload = app
|
||||
.upload_document(
|
||||
"/api/documents",
|
||||
"trash.txt",
|
||||
"text/plain",
|
||||
b"trash",
|
||||
None,
|
||||
&token,
|
||||
)
|
||||
.await?;
|
||||
let body = body_to_vec(upload.into_body()).await?;
|
||||
let detail: DocumentDetail = serde_json::from_slice(&body)?;
|
||||
|
||||
let delete_resp = app
|
||||
.delete(
|
||||
&format!("/api/documents/{}", detail.document.id),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(delete_resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let active_resp = app.get("/api/documents", Some(&token)).await?;
|
||||
assert!(active_resp.status().is_success());
|
||||
let active_body = body_to_vec(active_resp.into_body()).await?;
|
||||
let active_docs: Vec<DocumentListItem> = serde_json::from_slice(&active_body)?;
|
||||
assert!(active_docs.iter().all(|doc| doc.id != detail.document.id));
|
||||
|
||||
let deleted_resp = app
|
||||
.get("/api/documents?status=deleted", Some(&token))
|
||||
.await?;
|
||||
assert!(deleted_resp.status().is_success());
|
||||
let deleted_body = body_to_vec(deleted_resp.into_body()).await?;
|
||||
let deleted_docs: Vec<DocumentListItem> = serde_json::from_slice(&deleted_body)?;
|
||||
assert!(deleted_docs.iter().any(|doc| doc.id == detail.document.id));
|
||||
|
||||
let all_resp = app.get("/api/documents?status=all", Some(&token)).await?;
|
||||
assert!(all_resp.status().is_success());
|
||||
let all_body = body_to_vec(all_resp.into_body()).await?;
|
||||
let all_docs: Vec<DocumentListItem> = serde_json::from_slice(&all_body)?;
|
||||
assert!(all_docs.iter().any(|doc| doc.id == detail.document.id));
|
||||
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn restore_document_to_original_and_custom_folder() -> Result<()> {
|
||||
let _lock = acquire_db_lock().await;
|
||||
let app = TestApp::new().await?;
|
||||
|
||||
let password = "restoretest";
|
||||
app.insert_user("restorer", password, "admin").await?;
|
||||
let token = app.login_token("restorer", password).await?;
|
||||
|
||||
let upload = app
|
||||
.upload_document(
|
||||
"/api/documents",
|
||||
"to-restore.txt",
|
||||
"text/plain",
|
||||
b"restore",
|
||||
None,
|
||||
&token,
|
||||
)
|
||||
.await?;
|
||||
let body = body_to_vec(upload.into_body()).await?;
|
||||
let detail: DocumentDetail = serde_json::from_slice(&body)?;
|
||||
|
||||
let delete_resp = app
|
||||
.delete(
|
||||
&format!("/api/documents/{}", detail.document.id),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(delete_resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let restore_resp = app
|
||||
.post_json(
|
||||
&format!("/api/documents/{}/restore", detail.document.id),
|
||||
&serde_json::json!({}),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(restore_resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let fetched = app
|
||||
.get(
|
||||
&format!("/api/documents/{}", detail.document.id),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert!(fetched.status().is_success());
|
||||
let fetched_body = body_to_vec(fetched.into_body()).await?;
|
||||
let fetched_detail: DocumentDetail = serde_json::from_slice(&fetched_body)?;
|
||||
assert!(fetched_detail.document.deleted_at.is_none());
|
||||
|
||||
let folder_resp = app
|
||||
.post_json(
|
||||
"/api/folders",
|
||||
&CreateFolderRequest {
|
||||
name: "Restored",
|
||||
parent_id: None,
|
||||
},
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert!(folder_resp.status().is_success());
|
||||
let folder_body = body_to_vec(folder_resp.into_body()).await?;
|
||||
let folder: FolderResponse = serde_json::from_slice(&folder_body)?;
|
||||
|
||||
let delete_again = app
|
||||
.delete(
|
||||
&format!("/api/documents/{}", detail.document.id),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(delete_again.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let restore_custom = app
|
||||
.post_json(
|
||||
&format!("/api/documents/{}/restore", detail.document.id),
|
||||
&serde_json::json!({
|
||||
"folder_id": folder.folder.id
|
||||
}),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(restore_custom.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let fetched_custom = app
|
||||
.get(
|
||||
&format!("/api/documents/{}", detail.document.id),
|
||||
Some(&token),
|
||||
)
|
||||
.await?;
|
||||
let fetched_custom_body = body_to_vec(fetched_custom.into_body()).await?;
|
||||
let fetched_custom_detail: DocumentDetail = serde_json::from_slice(&fetched_custom_body)?;
|
||||
assert_eq!(
|
||||
fetched_custom_detail.document.folder_id,
|
||||
Some(folder.folder.id)
|
||||
);
|
||||
assert!(fetched_custom_detail.document.deleted_at.is_none());
|
||||
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user