This commit is contained in:
2025-10-28 00:01:40 +01:00
parent 9be0e3b5c4
commit 7abc10acde
4 changed files with 76 additions and 16 deletions
@@ -0,0 +1,2 @@
ALTER TABLE document_versions
ADD COLUMN operations_summary JSONB NOT NULL DEFAULT '{}'::jsonb;
@@ -0,0 +1,2 @@
ALTER TABLE document_versions
DROP COLUMN IF EXISTS operations_summary;
-1
View File
@@ -675,7 +675,6 @@ pub mod schemas {
pub struct DocumentVersionResponse {
pub id: Uuid,
pub version_number: i32,
pub s3_key: String,
pub size_bytes: i64,
pub checksum: String,
pub created_at: String,
+72 -15
View File
@@ -27,20 +27,25 @@ struct DocumentInfo {
#[serde(default)]
correspondents: Vec<DocumentCorrespondentInfo>,
#[serde(default)]
current_version: Option<DocumentVersion>,
current_version: Option<DocumentVersionPayload>,
}
#[derive(Deserialize)]
struct DocumentVersion {
struct DocumentVersionPayload {
id: Uuid,
s3_key: String,
size_bytes: i64,
version_number: i32,
size_bytes: i64,
download_path: String,
#[serde(default)]
assets: Vec<DocumentAssetInfo>,
}
#[derive(Deserialize)]
struct DocumentVersionListItem {
id: Uuid,
version_number: i32,
}
#[allow(dead_code)]
#[derive(Deserialize)]
struct DocumentAssetInfo {
@@ -52,12 +57,11 @@ struct DocumentAssetInfo {
struct DocumentListItem {
id: Uuid,
#[serde(default)]
current_version: Option<DocumentVersion>,
current_version: Option<DocumentVersionPayload>,
}
#[derive(Deserialize)]
struct DocumentDownload {
url: String,
filename: String,
}
@@ -205,13 +209,6 @@ async fn upload_and_list_document() -> Result<()> {
assert_eq!(current_version.size_bytes, file_bytes.len() as i64);
assert!(current_version.assets.is_empty());
let storage_key = app.storage_key_for(&current_version.s3_key).await?;
let stored = app
.storage()
.get(&storage_key)
.await
.expect("object stored");
assert_eq!(stored.bytes, file_bytes);
assert_eq!(app.storage().object_count().await, 1);
let response = app.get("/api/documents", Some(&token)).await?;
@@ -257,7 +254,6 @@ async fn upload_and_list_document() -> Result<()> {
}
let body = body_to_vec(download.into_body()).await?;
let download_info: DocumentDownload = serde_json::from_slice(&body)?;
assert!(download_info.url.contains(&current_version.s3_key));
assert_eq!(download_info.filename, "doc.txt");
let redirect = app.get(&current_version.download_path, None).await?;
@@ -267,7 +263,7 @@ async fn upload_and_list_document() -> Result<()> {
.get("location")
.expect("redirect location header");
let location = location.to_str().expect("location header utf8");
assert!(location.contains(&current_version.s3_key));
assert!(!location.is_empty());
app.cleanup().await?;
Ok(())
@@ -1789,3 +1785,64 @@ async fn restore_document_to_original_and_custom_folder() -> Result<()> {
app.cleanup().await?;
Ok(())
}
#[tokio::test]
async fn list_document_versions_and_fetch_detail() -> Result<()> {
let _lock = acquire_db_lock().await;
let app = TestApp::new().await?;
let password = "versionlist";
app.insert_user("versions", password, "admin").await?;
let token = app.login_token("versions", password).await?;
let upload = app
.upload_document(
"/api/documents",
"versioned.txt",
"text/plain",
b"versioned",
None,
&token,
)
.await?;
let upload_body = body_to_vec(upload.into_body()).await?;
let detail: DocumentDetail = serde_json::from_slice(&upload_body)?;
let version_id = detail
.document
.current_version
.as_ref()
.expect("current version")
.id;
let list_resp = app
.get(
&format!("/api/documents/{}/versions", detail.document.id),
Some(&token),
)
.await?;
assert!(list_resp.status().is_success());
let list_body = body_to_vec(list_resp.into_body()).await?;
let versions: Vec<DocumentVersionListItem> = serde_json::from_slice(&list_body)?;
assert_eq!(versions.len(), 1);
assert_eq!(versions[0].id, version_id);
let detail_resp = app
.get(
&format!(
"/api/documents/{}/versions/{}",
detail.document.id, version_id
),
Some(&token),
)
.await?;
assert!(detail_resp.status().is_success());
let detail_body = body_to_vec(detail_resp.into_body()).await?;
let version_detail: DocumentVersionPayload = serde_json::from_slice(&detail_body)?;
assert_eq!(version_detail.id, version_id);
assert!(version_detail.download_path.starts_with("/download/"));
assert!(version_detail.assets.is_empty());
app.cleanup().await?;
Ok(())
}