71 lines
2.1 KiB
Rust
71 lines
2.1 KiB
Rust
use application::processing::{ManagePluginCommand, ManagePluginHandler, PluginAction};
|
|
use application::testing::InMemoryPluginRepository;
|
|
use domain::entities::{Plugin, PluginType};
|
|
use domain::ports::PluginRepository;
|
|
use domain::value_objects::StructuredData;
|
|
use std::sync::Arc;
|
|
|
|
#[tokio::test]
|
|
async fn creates_plugin() {
|
|
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
|
|
|
let plugin = handler
|
|
.execute(ManagePluginCommand {
|
|
plugin_id: None,
|
|
action: PluginAction::Create {
|
|
name: "EXIF Extractor".into(),
|
|
plugin_type: PluginType::MediaProcessor,
|
|
config: StructuredData::new(),
|
|
},
|
|
})
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(plugin.name, "EXIF Extractor");
|
|
assert_eq!(plugin.plugin_type, PluginType::MediaProcessor);
|
|
assert!(plugin.is_enabled);
|
|
|
|
let saved = plugin_repo.find_by_id(&plugin.plugin_id).await.unwrap();
|
|
assert!(saved.is_some());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn enables_plugin() {
|
|
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
|
let mut plugin = Plugin::new("Test", PluginType::ScheduledTask);
|
|
plugin.disable();
|
|
let plugin_id = plugin.plugin_id;
|
|
plugin_repo.save(&plugin).await.unwrap();
|
|
|
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
|
let result = handler
|
|
.execute(ManagePluginCommand {
|
|
plugin_id: Some(plugin_id),
|
|
action: PluginAction::Enable,
|
|
})
|
|
.await
|
|
.unwrap();
|
|
|
|
assert!(result.is_enabled);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn disables_plugin() {
|
|
let plugin_repo = Arc::new(InMemoryPluginRepository::new());
|
|
let plugin = Plugin::new("Test", PluginType::SidecarWriter);
|
|
let plugin_id = plugin.plugin_id;
|
|
plugin_repo.save(&plugin).await.unwrap();
|
|
|
|
let handler = ManagePluginHandler::new(plugin_repo.clone());
|
|
let result = handler
|
|
.execute(ManagePluginCommand {
|
|
plugin_id: Some(plugin_id),
|
|
action: PluginAction::Disable,
|
|
})
|
|
.await
|
|
.unwrap();
|
|
|
|
assert!(!result.is_enabled);
|
|
}
|