a lot of things
This commit is contained in:
@@ -9,8 +9,6 @@ use uuid::Uuid;
|
||||
#[derive(Deserialize)]
|
||||
struct DocumentDetail {
|
||||
document: DocumentInfo,
|
||||
current_version: DocumentVersion,
|
||||
assets: Vec<DocumentAssetInfo>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -18,11 +16,11 @@ struct DocumentInfo {
|
||||
id: Uuid,
|
||||
title: String,
|
||||
original_name: String,
|
||||
current_version: i32,
|
||||
deleted_at: Option<String>,
|
||||
issued_at: Option<String>,
|
||||
tags: Vec<TagSummary>,
|
||||
download_path: String,
|
||||
#[serde(default)]
|
||||
current_version: Option<DocumentVersion>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -30,6 +28,10 @@ struct DocumentVersion {
|
||||
id: Uuid,
|
||||
s3_key: String,
|
||||
size_bytes: i64,
|
||||
version_number: i32,
|
||||
download_path: String,
|
||||
#[serde(default)]
|
||||
assets: Vec<DocumentAssetInfo>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -42,8 +44,8 @@ struct DocumentAssetInfo {
|
||||
#[derive(Deserialize)]
|
||||
struct DocumentListItem {
|
||||
id: Uuid,
|
||||
current_version: i32,
|
||||
download_path: String,
|
||||
#[serde(default)]
|
||||
current_version: Option<DocumentVersion>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -152,17 +154,22 @@ async fn upload_and_list_document() -> Result<()> {
|
||||
|
||||
assert_eq!(detail.document.original_name, "doc.txt");
|
||||
assert_eq!(detail.document.title, "doc");
|
||||
assert_eq!(detail.document.current_version, 1);
|
||||
assert_eq!(detail.document.deleted_at, None);
|
||||
assert!(detail.document.issued_at.is_none());
|
||||
assert!(detail.document.tags.is_empty());
|
||||
assert!(detail.document.download_path.starts_with("/download/"));
|
||||
assert_eq!(detail.current_version.size_bytes, file_bytes.len() as i64);
|
||||
assert!(detail.assets.is_empty());
|
||||
assert!(current_version.download_path.starts_with("/download/"));
|
||||
let current_version = detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("current version detail");
|
||||
assert_eq!(current_version.version_number, 1);
|
||||
assert_eq!(current_version.size_bytes, file_bytes.len() as i64);
|
||||
assert!(current_version.assets.is_empty());
|
||||
|
||||
let stored = app
|
||||
.storage()
|
||||
.get(&detail.current_version.s3_key)
|
||||
.get(¤t_version.s3_key)
|
||||
.await
|
||||
.expect("object stored");
|
||||
assert_eq!(stored.bytes, file_bytes);
|
||||
@@ -175,8 +182,18 @@ async fn upload_and_list_document() -> Result<()> {
|
||||
assert_eq!(list.len(), 1);
|
||||
let item = list.pop().unwrap();
|
||||
assert_eq!(item.id, detail.document.id);
|
||||
assert_eq!(item.current_version, 1);
|
||||
assert!(item.download_path.starts_with("/download/"));
|
||||
assert_eq!(
|
||||
item.current_version
|
||||
.as_ref()
|
||||
.map(|version| version.version_number),
|
||||
Some(1)
|
||||
);
|
||||
assert!(item
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("list current version")
|
||||
.download_path
|
||||
.starts_with("/download/"));
|
||||
|
||||
let download = app
|
||||
.get(
|
||||
@@ -187,17 +204,17 @@ async fn upload_and_list_document() -> Result<()> {
|
||||
assert_eq!(download.status(), StatusCode::OK);
|
||||
let body = body_to_vec(download.into_body()).await?;
|
||||
let download_info: DocumentDownload = serde_json::from_slice(&body)?;
|
||||
assert!(download_info.url.contains(&detail.current_version.s3_key));
|
||||
assert!(download_info.url.contains(¤t_version.s3_key));
|
||||
assert_eq!(download_info.filename, "doc.txt");
|
||||
|
||||
let redirect = app.get(&detail.document.download_path, None).await?;
|
||||
let redirect = app.get(¤t_version.download_path, None).await?;
|
||||
assert_eq!(redirect.status(), StatusCode::TEMPORARY_REDIRECT);
|
||||
let location = redirect
|
||||
.headers()
|
||||
.get("location")
|
||||
.expect("redirect location header");
|
||||
let location = location.to_str().expect("location header utf8");
|
||||
assert!(location.contains(&detail.current_version.s3_key));
|
||||
assert!(location.contains(¤t_version.s3_key));
|
||||
|
||||
app.cleanup().await?;
|
||||
Ok(())
|
||||
@@ -243,7 +260,13 @@ async fn duplicate_and_restore_document() -> Result<()> {
|
||||
|
||||
assert_eq!(first_detail.document.id, second_detail.document.id);
|
||||
assert_eq!(second_detail.document.deleted_at, None);
|
||||
assert!(second_detail.assets.is_empty());
|
||||
assert!(second_detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("second current version")
|
||||
.assets
|
||||
.is_empty());
|
||||
assert_eq!(app.storage().object_count().await, 1);
|
||||
|
||||
let delete = app
|
||||
@@ -341,8 +364,24 @@ async fn bulk_reanalyze_documents() -> Result<()> {
|
||||
}
|
||||
|
||||
let mut expected = vec![
|
||||
(first_detail.document.id, first_detail.current_version.id),
|
||||
(second_detail.document.id, second_detail.current_version.id),
|
||||
(
|
||||
first_detail.document.id,
|
||||
first_detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("first current version")
|
||||
.id,
|
||||
),
|
||||
(
|
||||
second_detail.document.id,
|
||||
second_detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("second current version")
|
||||
.id,
|
||||
),
|
||||
];
|
||||
payload_docs.sort();
|
||||
expected.sort();
|
||||
@@ -661,8 +700,24 @@ async fn bulk_reanalyze_selected_documents() -> Result<()> {
|
||||
.all(|(doc_id, _)| *doc_id != second_detail.document.id));
|
||||
|
||||
let mut expected = vec![
|
||||
(first_detail.document.id, first_detail.current_version.id),
|
||||
(third_detail.document.id, third_detail.current_version.id),
|
||||
(
|
||||
first_detail.document.id,
|
||||
first_detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("first current version")
|
||||
.id,
|
||||
),
|
||||
(
|
||||
third_detail.document.id,
|
||||
third_detail
|
||||
.document
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("third current version")
|
||||
.id,
|
||||
),
|
||||
];
|
||||
payload_docs.sort();
|
||||
expected.sort();
|
||||
|
||||
Reference in New Issue
Block a user