Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronleopold committed Feb 9, 2025
1 parent 5f372d4 commit 844d5f8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/server/src/routers/api/v1/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ async fn delete_library_scan_history(
)]
/// Queue a ScannerJob to scan the library by id. The job, when started, is
/// executed in a separate thread.
#[tracing::instrument(skip(ctx, req))]
async fn scan_library(
Path(id): Path<String>,
State(ctx): State<AppState>,
Expand Down Expand Up @@ -1144,6 +1145,7 @@ async fn scan_library(
"Failed to enqueue library scan job".to_string(),
)
})?;
tracing::debug!("Enqueued library scan job");

Ok(())
}
Expand Down
69 changes: 62 additions & 7 deletions core/src/filesystem/scanner/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl BookVisitResult {
/// specific options.
#[derive(Debug, Default, Clone, Copy, Deserialize, Type, Serialize)]
pub struct ScanOptions {
#[serde(default)]
pub config: ScanConfig,
}

Expand Down Expand Up @@ -217,10 +216,66 @@ mod tests {
);
}

#[test]
fn test_serialize_scan_options() {
assert_eq!(
serde_json::to_string(&ScanOptions {
config: ScanConfig::ForceRebuild {
force_rebuild: true
}
})
.unwrap(),
r#"{"config":{"force_rebuild":true}}"#
);

assert_eq!(
serde_json::to_string(&ScanOptions {
config: ScanConfig::ForceRebuild {
force_rebuild: false
}
})
.unwrap(),
r#"{"config":{"force_rebuild":false}}"#
);

assert_eq!(
serde_json::to_string(&ScanOptions {
config: ScanConfig::Custom(CustomVisit {
regen_meta: true,
regen_hashes: false
})
})
.unwrap(),
r#"{"config":{"regen_meta":true,"regen_hashes":false}}"#
);

assert_eq!(
serde_json::to_string(&ScanOptions {
config: ScanConfig::Custom(CustomVisit {
regen_meta: false,
regen_hashes: true
})
})
.unwrap(),
r#"{"config":{"regen_meta":false,"regen_hashes":true}}"#
);

assert_eq!(
serde_json::to_string(&ScanOptions {
config: ScanConfig::Custom(CustomVisit {
regen_meta: true,
regen_hashes: true
})
})
.unwrap(),
r#"{"config":{"regen_meta":true,"regen_hashes":true}}"#
);
}

#[test]
fn test_deserialize_scan_options() {
assert!(matches!(
serde_json::from_str::<ScanOptions>(r#"{"force_rebuild":true}"#)
serde_json::from_str::<ScanOptions>(r#"{"config":{"force_rebuild":true}}"#)
.unwrap()
.config,
ScanConfig::ForceRebuild {
Expand All @@ -229,7 +284,7 @@ mod tests {
));

assert!(matches!(
serde_json::from_str::<ScanOptions>(r#"{"force_rebuild":false}"#)
serde_json::from_str::<ScanOptions>(r#"{"config":{"force_rebuild":false}}"#)
.unwrap()
.config,
ScanConfig::ForceRebuild {
Expand All @@ -238,7 +293,7 @@ mod tests {
));

assert!(matches!(
serde_json::from_str::<ScanOptions>(r#"{"regen_meta":true}"#)
serde_json::from_str::<ScanOptions>(r#"{"config":{"regen_meta":true}}"#)
.unwrap()
.config,
ScanConfig::Custom(CustomVisit {
Expand All @@ -248,7 +303,7 @@ mod tests {
));

assert!(matches!(
serde_json::from_str::<ScanOptions>(r#"{"regen_hashes":true}"#)
serde_json::from_str::<ScanOptions>(r#"{"config":{"regen_hashes":true}}"#)
.unwrap()
.config,
ScanConfig::Custom(CustomVisit {
Expand All @@ -259,7 +314,7 @@ mod tests {

assert!(matches!(
serde_json::from_str::<ScanOptions>(
r#"{"regen_meta":true,"regen_hashes":true}"#
r#"{"config":{"regen_meta":true,"regen_hashes":true}}"#
)
.unwrap()
.config,
Expand Down Expand Up @@ -312,7 +367,7 @@ mod tests {

#[test]
fn test_deserialize_default() {
let options = r#"{}"#;
let options = r#"{"config": null}"#;
let options: ScanOptions = serde_json::from_str(options).unwrap();
assert!(options.is_default());
}
Expand Down

0 comments on commit 844d5f8

Please sign in to comment.