mirror of
https://github.com/thegeneralist01/archivr
synced 2026-10-09 12:55:00 +02:00
test: cover tweet image summary selection
This commit is contained in:
parent
d56fd8b41b
commit
0b5ac0a516
1 changed files with 65 additions and 29 deletions
|
|
@ -2829,7 +2829,11 @@ mod tests {
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
archive::initialize_store_directories(&store_path).unwrap();
|
||||||
fs::create_dir_all(&archive_path).unwrap();
|
fs::create_dir_all(&archive_path).unwrap();
|
||||||
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
||||||
fs::write(archive_path.join("store_path"), store_path.to_str().unwrap()).unwrap();
|
fs::write(
|
||||||
|
archive_path.join("store_path"),
|
||||||
|
store_path.to_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let archive_paths = ArchivePaths {
|
let archive_paths = ArchivePaths {
|
||||||
archive_path: archive_path.clone(),
|
archive_path: archive_path.clone(),
|
||||||
|
|
@ -2851,7 +2855,8 @@ mod tests {
|
||||||
// Verify entry was created
|
// Verify entry was created
|
||||||
let conn = database::open_or_initialize(&archive_path).unwrap();
|
let conn = database::open_or_initialize(&archive_path).unwrap();
|
||||||
let default_coll_id = database::ensure_default_collection(&conn).unwrap();
|
let default_coll_id = database::ensure_default_collection(&conn).unwrap();
|
||||||
let entries = archive::list_entries_for_collection(&conn, default_coll_id, 0xFFFFFFFF).unwrap();
|
let entries =
|
||||||
|
archive::list_entries_for_collection(&conn, default_coll_id, 0xFFFFFFFF).unwrap();
|
||||||
assert_eq!(entries.len(), 1);
|
assert_eq!(entries.len(), 1);
|
||||||
let entry = &entries[0];
|
let entry = &entries[0];
|
||||||
assert_eq!(entry.title, Some(title.to_string()));
|
assert_eq!(entry.title, Some(title.to_string()));
|
||||||
|
|
@ -2878,7 +2883,11 @@ mod tests {
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
archive::initialize_store_directories(&store_path).unwrap();
|
||||||
fs::create_dir_all(&archive_path).unwrap();
|
fs::create_dir_all(&archive_path).unwrap();
|
||||||
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
||||||
fs::write(archive_path.join("store_path"), store_path.to_str().unwrap()).unwrap();
|
fs::write(
|
||||||
|
archive_path.join("store_path"),
|
||||||
|
store_path.to_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let archive_paths = ArchivePaths {
|
let archive_paths = ArchivePaths {
|
||||||
archive_path: archive_path.clone(),
|
archive_path: archive_path.clone(),
|
||||||
|
|
@ -2897,7 +2906,8 @@ mod tests {
|
||||||
// Verify entry was created
|
// Verify entry was created
|
||||||
let conn = database::open_or_initialize(&archive_path).unwrap();
|
let conn = database::open_or_initialize(&archive_path).unwrap();
|
||||||
let default_coll_id = database::ensure_default_collection(&conn).unwrap();
|
let default_coll_id = database::ensure_default_collection(&conn).unwrap();
|
||||||
let entries = archive::list_entries_for_collection(&conn, default_coll_id, 0xFFFFFFFF).unwrap();
|
let entries =
|
||||||
|
archive::list_entries_for_collection(&conn, default_coll_id, 0xFFFFFFFF).unwrap();
|
||||||
assert_eq!(entries.len(), 1);
|
assert_eq!(entries.len(), 1);
|
||||||
let entry = &entries[0];
|
let entry = &entries[0];
|
||||||
assert_eq!(entry.title, Some(title.to_string()));
|
assert_eq!(entry.title, Some(title.to_string()));
|
||||||
|
|
@ -2920,7 +2930,11 @@ mod tests {
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
archive::initialize_store_directories(&store_path).unwrap();
|
||||||
fs::create_dir_all(&archive_path).unwrap();
|
fs::create_dir_all(&archive_path).unwrap();
|
||||||
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
||||||
fs::write(archive_path.join("store_path"), store_path.to_str().unwrap()).unwrap();
|
fs::write(
|
||||||
|
archive_path.join("store_path"),
|
||||||
|
store_path.to_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let archive_paths = ArchivePaths {
|
let archive_paths = ArchivePaths {
|
||||||
archive_path,
|
archive_path,
|
||||||
|
|
@ -2930,7 +2944,10 @@ mod tests {
|
||||||
|
|
||||||
let result = perform_text_capture(&archive_paths, "", "Some body", "text/plain", None);
|
let result = perform_text_capture(&archive_paths, "", "Some body", "text/plain", None);
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result.unwrap_err().to_string().contains("title must not be empty"));
|
assert!(result
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string()
|
||||||
|
.contains("title must not be empty"));
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
let _ = fs::remove_dir_all(&base_path);
|
let _ = fs::remove_dir_all(&base_path);
|
||||||
|
|
@ -2950,7 +2967,11 @@ mod tests {
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
archive::initialize_store_directories(&store_path).unwrap();
|
||||||
fs::create_dir_all(&archive_path).unwrap();
|
fs::create_dir_all(&archive_path).unwrap();
|
||||||
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
||||||
fs::write(archive_path.join("store_path"), store_path.to_str().unwrap()).unwrap();
|
fs::write(
|
||||||
|
archive_path.join("store_path"),
|
||||||
|
store_path.to_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let archive_paths = ArchivePaths {
|
let archive_paths = ArchivePaths {
|
||||||
archive_path,
|
archive_path,
|
||||||
|
|
@ -2960,7 +2981,10 @@ mod tests {
|
||||||
|
|
||||||
let result = perform_text_capture(&archive_paths, "Some Title", "", "text/plain", None);
|
let result = perform_text_capture(&archive_paths, "Some Title", "", "text/plain", None);
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result.unwrap_err().to_string().contains("body must not be empty"));
|
assert!(result
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string()
|
||||||
|
.contains("body must not be empty"));
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
let _ = fs::remove_dir_all(&base_path);
|
let _ = fs::remove_dir_all(&base_path);
|
||||||
|
|
@ -2980,7 +3004,11 @@ mod tests {
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
archive::initialize_store_directories(&store_path).unwrap();
|
||||||
fs::create_dir_all(&archive_path).unwrap();
|
fs::create_dir_all(&archive_path).unwrap();
|
||||||
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
fs::write(archive_path.join("name"), "test-archive").unwrap();
|
||||||
fs::write(archive_path.join("store_path"), store_path.to_str().unwrap()).unwrap();
|
fs::write(
|
||||||
|
archive_path.join("store_path"),
|
||||||
|
store_path.to_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let archive_paths = ArchivePaths {
|
let archive_paths = ArchivePaths {
|
||||||
archive_path,
|
archive_path,
|
||||||
|
|
@ -2988,15 +3016,12 @@ mod tests {
|
||||||
name: "test-archive".to_string(),
|
name: "test-archive".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = perform_text_capture(
|
let result = perform_text_capture(&archive_paths, "Title", "Body", "text/html", None);
|
||||||
&archive_paths,
|
|
||||||
"Title",
|
|
||||||
"Body",
|
|
||||||
"text/html",
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result.unwrap_err().to_string().contains("unsupported MIME type"));
|
assert!(result
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string()
|
||||||
|
.contains("unsupported MIME type"));
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
let _ = fs::remove_dir_all(&base_path);
|
let _ = fs::remove_dir_all(&base_path);
|
||||||
|
|
@ -3022,12 +3047,15 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_record_tweet_entry_links_json_and_raw_artifacts() {
|
fn test_record_tweet_entry_links_json_and_raw_artifacts() {
|
||||||
let store_path = env::temp_dir().join(format!(
|
let temp = tempfile::tempdir().unwrap();
|
||||||
"archivr-tweet-db-test-{}",
|
let archive_paths = archive::initialize_archive(
|
||||||
Local::now().format("%Y%m%d%H%M%S%3f")
|
temp.path(),
|
||||||
));
|
&temp.path().join("store"),
|
||||||
let _ = fs::remove_dir_all(&store_path);
|
"Tweet summary test",
|
||||||
archive::initialize_store_directories(&store_path).unwrap();
|
false,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let store_path = &archive_paths.store_path;
|
||||||
fs::create_dir_all(store_path.join("raw").join("a").join("b")).unwrap();
|
fs::create_dir_all(store_path.join("raw").join("a").join("b")).unwrap();
|
||||||
fs::create_dir_all(store_path.join("raw").join("c").join("d")).unwrap();
|
fs::create_dir_all(store_path.join("raw").join("c").join("d")).unwrap();
|
||||||
fs::write(
|
fs::write(
|
||||||
|
|
@ -3051,14 +3079,14 @@ mod tests {
|
||||||
fs::write(
|
fs::write(
|
||||||
store_path.join("raw_tweets").join("tweet-123.json"),
|
store_path.join("raw_tweets").join("tweet-123.json"),
|
||||||
r#"{
|
r#"{
|
||||||
|
"full_text": "Tweet body for summary selection.",
|
||||||
"author": { "avatar_local_path": "raw/a/b/abcdef.jpg" },
|
"author": { "avatar_local_path": "raw/a/b/abcdef.jpg" },
|
||||||
"entities": { "media": [{ "local_path": "raw/c/d/cdef01.jpg" }] }
|
"entities": { "media": [{ "local_path": "raw/c/d/cdef01.jpg" }] }
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let conn = rusqlite::Connection::open_in_memory().unwrap();
|
let conn = database::open_or_initialize(&archive_paths.archive_path).unwrap();
|
||||||
database::initialize_schema(&conn).unwrap();
|
|
||||||
let user_id = database::ensure_default_user(&conn).unwrap();
|
let user_id = database::ensure_default_user(&conn).unwrap();
|
||||||
let run = database::create_archive_run(&conn, user_id, 1).unwrap();
|
let run = database::create_archive_run(&conn, user_id, 1).unwrap();
|
||||||
let item = database::create_archive_run_item(
|
let item = database::create_archive_run_item(
|
||||||
|
|
@ -3115,10 +3143,18 @@ mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(media_mime.as_deref(), Some("image/jpeg"));
|
assert_eq!(media_mime.as_deref(), Some("image/jpeg"));
|
||||||
|
let summary_input = crate::summarizer::build_summary_input(
|
||||||
|
&archive_paths,
|
||||||
|
&entry.entry_uid,
|
||||||
|
crate::summarizer::SummaryBuildOptions {
|
||||||
|
include_images: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(summary_input.request.images.len(), 1);
|
||||||
|
assert_eq!(summary_input.request.images[0].mime_type, "image/jpeg");
|
||||||
assert_eq!(run_status, "completed");
|
assert_eq!(run_status, "completed");
|
||||||
assert!(store_path.join(&entry.structured_root_relpath).is_dir());
|
assert!(store_path.join(&entry.structured_root_relpath).is_dir());
|
||||||
|
|
||||||
let _ = fs::remove_dir_all(store_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod title_tests {
|
mod title_tests {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue