From 04f6b1d421b29c6849d6094532d161f0e35f7d7e Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sun, 29 Dec 2019 13:37:50 -0500 Subject: [PATCH] add test for syncing deletes and creates --- TODO.txt | 2 +- tests/sync.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index cdbf54749..056c26e24 100644 --- a/TODO.txt +++ b/TODO.txt @@ -12,4 +12,4 @@ - need to be sure that create / delete operations don't get reversed * cli tools * prop testing for DB modifications - - 'strict' mode to fail on application of any nonsense operations + - generate a non-failing sequence of operations with syncs interspersed diff --git a/tests/sync.rs b/tests/sync.rs index 9f062b244..733fc71ce 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -61,3 +61,56 @@ fn test_sync() { db1.sync("me", &mut server); assert_eq!(db1.tasks(), db2.tasks()); } + +#[test] +fn test_sync_create_delete() { + let mut server = Server::new(); + + let mut db1 = DB::new(); + db1.sync("me", &mut server); + + let mut db2 = DB::new(); + db2.sync("me", &mut server); + + // create and update a task.. + let uuid = Uuid::new_v4(); + db1.apply(Operation::Create { uuid }).unwrap(); + db1.apply(Operation::Update { + uuid: uuid, + property: "title".into(), + value: Some("my first task".into()), + timestamp: Utc::now(), + }) + .unwrap(); + + // and synchronize those around + db1.sync("me", &mut server); + db2.sync("me", &mut server); + db1.sync("me", &mut server); + assert_eq!(db1.tasks(), db2.tasks()); + + // delete and re-create the task on db1 + db1.apply(Operation::Delete { uuid }).unwrap(); + db1.apply(Operation::Create { uuid }).unwrap(); + db1.apply(Operation::Update { + uuid: uuid, + property: "title".into(), + value: Some("my second task".into()), + timestamp: Utc::now(), + }) + .unwrap(); + + // and on db2, update a property of the task + db2.apply(Operation::Update { + uuid: uuid, + property: "project".into(), + value: Some("personal".into()), + timestamp: Utc::now(), + }) + .unwrap(); + + db1.sync("me", &mut server); + db2.sync("me", &mut server); + db1.sync("me", &mut server); + assert_eq!(db1.tasks(), db2.tasks()); +}