use crate::plugin::org_suite::types::{OrgArchetype, OrgSuiteError};
pub trait OrgConverter: Send + Sync {
fn source_archetype(&self) -> OrgArchetype;
fn target_archetype(&self) -> OrgArchetype;
fn convert(&self, source_data: &serde_json::Value) -> Result<serde_json::Value, OrgSuiteError>;
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
struct MockConverter;
impl OrgConverter for MockConverter {
fn source_archetype(&self) -> OrgArchetype {
OrgArchetype::Holacracy
}
fn target_archetype(&self) -> OrgArchetype {
OrgArchetype::Hierarchy
}
fn convert(
&self,
source_data: &serde_json::Value,
) -> Result<serde_json::Value, OrgSuiteError> {
Ok(json!({
"converted": true,
"from": "holacracy",
"to": "hierarchy",
"source": source_data
}))
}
}
#[test]
fn test_mock_converter() {
let converter = MockConverter;
assert_eq!(converter.source_archetype(), OrgArchetype::Holacracy);
assert_eq!(converter.target_archetype(), OrgArchetype::Hierarchy);
let source = json!({"members": 50});
let result = converter.convert(&source).unwrap();
assert_eq!(result["converted"], true);
assert_eq!(result["from"], "holacracy");
}
}