use cfait::context::TestContext;
use cfait::model::Task;
use cfait::store::TaskStore;
use std::collections::HashMap;
use std::sync::Arc;
#[test]
fn test_move_task_with_original_returns_original_and_updated_and_updates_store() {
let ctx = Arc::new(TestContext::new());
let mut store = TaskStore::new(ctx);
let mut t = Task::new("Unit Test Task", &HashMap::new(), None);
t.uid = "test-uid-1".to_string();
t.calendar_href = "local://cal1".to_string();
store.add_task(t.clone());
let res = store.move_task(&t.uid, "local://cal2".to_string());
assert!(res.is_some(), "Expected move_task to return Some");
let (original, updated) = res.unwrap();
assert_eq!(original.uid, t.uid);
assert_eq!(original.calendar_href, "local://cal1");
assert_eq!(updated.uid, t.uid);
assert_eq!(updated.calendar_href, "local://cal2");
let in_old = store
.calendars
.get("local://cal1")
.map(|m| m.values().any(|x| x.uid == t.uid))
.unwrap_or(false);
assert!(!in_old, "Task should not remain in the old calendar");
let in_new = store
.calendars
.get("local://cal2")
.map(|m| m.values().any(|x| x.uid == t.uid))
.unwrap_or(false);
assert!(in_new, "Task should exist in the new calendar");
}