From 8fd416fae1af00c842f47fb75472418a2f0bf5df Mon Sep 17 00:00:00 2001 From: daladim Date: Sun, 18 Apr 2021 00:32:13 +0200 Subject: [PATCH] Provider uses update_item --- src/provider.rs | 26 ++++---------------------- tests/sync.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/provider.rs b/src/provider.rs index 3c9d3a0..27eb933 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -314,17 +314,8 @@ where continue; }, Some(item) => { - // - // - // - // - // TODO: implement update_item (maybe only create_item also updates it?) - // - if let Err(err) = cal_local.immediately_delete_item(&id_change).await { - result.error(&format!("Unable to delete (update) item {} from local calendar: {}", id_change, err)); - } - if let Err(err) = cal_local.add_item(item.clone()).await { - result.error(&format!("Unable to add (update) item {} to local calendar: {}", id_change, err)); + if let Err(err) = cal_local.update_item(item.clone()).await { + result.error(&format!("Unable to update item {} in local calendar: {}", id_change, err)); } }, } @@ -359,17 +350,8 @@ where continue; }, Some(item) => { - // - // - // - // - // TODO: implement update_item (maybe only create_item also updates it?) - // - if let Err(err) = cal_remote.delete_item(&id_change).await { - result.error(&format!("Unable to delete (update) item {} from remote calendar: {}", id_change, err)); - } - match cal_remote.add_item(item.clone()).await { - Err(err) => log::error!("Unable to add (update) item {} to remote calendar: {}", id_change, err), + match cal_remote.update_item(item.clone()).await { + Err(err) => result.error(&format!("Unable to update item {} in remote calendar: {}", id_change, err)), Ok(new_ss) => { // Update local sync status item.set_sync_status(new_ss); diff --git a/tests/sync.rs b/tests/sync.rs index 90bf502..e3d484e 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -34,6 +34,7 @@ impl TestFlavour { pub fn normal_with_errors9() -> Self { Self{} } pub fn normal_with_errors10() -> Self { Self{} } pub fn normal_with_errors11() -> Self { Self{} } + pub fn normal_with_errors12() -> Self { Self{} } pub async fn run(&self, _max_attempts: u32) { println!("WARNING: This test required the \"integration_tests\" Cargo feature"); @@ -188,6 +189,16 @@ impl TestFlavour { } } + pub fn normal_with_errors12() -> Self { + Self { + scenarii: scenarii::scenarii_basic(), + mock_behaviour: Arc::new(Mutex::new(MockBehaviour{ + update_item_behaviour: (0,3), + ..MockBehaviour::default() + })), + } + } + pub async fn run(&self, max_attempts: u32) { self.mock_behaviour.lock().unwrap().suspend(); @@ -306,6 +317,11 @@ async fn test_errors_in_regular_sync11() { run_flavour(TestFlavour::normal_with_errors11(), 100).await; } +#[tokio::test] +async fn test_errors_in_regular_sync12() { + run_flavour(TestFlavour::normal_with_errors12(), 100).await; +} + #[cfg(feature = "integration_tests")] use my_tasks::{traits::CalDavSource, Provider,