use std::future::Future;
use std::pin::Pin;
use anyhow::Result;
use crate::atlassian::adf::AdfDocument;
#[derive(Debug, Clone)]
pub struct ContentItem {
pub id: String,
pub title: String,
pub body_adf: Option<serde_json::Value>,
pub metadata: ContentMetadata,
}
#[derive(Debug, Clone)]
pub enum ContentMetadata {
Jira {
status: Option<String>,
issue_type: Option<String>,
assignee: Option<String>,
priority: Option<String>,
labels: Vec<String>,
},
Confluence {
space_key: String,
status: Option<String>,
version: Option<u32>,
parent_id: Option<String>,
},
}
pub trait AtlassianApi: Send + Sync {
fn get_content<'a>(
&'a self,
id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<ContentItem>> + Send + 'a>>;
fn update_content<'a>(
&'a self,
id: &'a str,
body_adf: &'a AdfDocument,
title: Option<&'a str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn verify_auth<'a>(&'a self) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'a>>;
fn backend_name(&self) -> &'static str;
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
#[test]
fn content_metadata_jira_variant() {
let meta = ContentMetadata::Jira {
status: Some("Open".to_string()),
issue_type: Some("Bug".to_string()),
assignee: None,
priority: Some("High".to_string()),
labels: vec!["backend".to_string()],
};
match &meta {
ContentMetadata::Jira { status, labels, .. } => {
assert_eq!(status.as_deref(), Some("Open"));
assert_eq!(labels.len(), 1);
}
_ => panic!("Expected Jira variant"),
}
}
#[test]
fn content_metadata_confluence_variant() {
let meta = ContentMetadata::Confluence {
space_key: "ENG".to_string(),
status: Some("current".to_string()),
version: Some(7),
parent_id: None,
};
match &meta {
ContentMetadata::Confluence {
space_key, version, ..
} => {
assert_eq!(space_key, "ENG");
assert_eq!(*version, Some(7));
}
_ => panic!("Expected Confluence variant"),
}
}
#[test]
fn content_item_fields() {
let item = ContentItem {
id: "PROJ-123".to_string(),
title: "Fix the bug".to_string(),
body_adf: None,
metadata: ContentMetadata::Jira {
status: None,
issue_type: None,
assignee: None,
priority: None,
labels: vec![],
},
};
assert_eq!(item.id, "PROJ-123");
assert_eq!(item.title, "Fix the bug");
assert!(item.body_adf.is_none());
}
}