about summary refs log tree commit diff
path: root/src/database/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/mod.rs')
-rw-r--r--src/database/mod.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/database/mod.rs b/src/database/mod.rs
index 58f0a35..e6873b0 100644
--- a/src/database/mod.rs
+++ b/src/database/mod.rs
@@ -252,6 +252,58 @@ mod tests {
         }
     }
 
+    /// Note: this is merely a smoke check and is in no way comprehensive.
+    async fn test_backend_update<Backend: Storage>(backend: Backend) {
+        let post: serde_json::Value = json!({
+            "type": ["h-entry"],
+            "properties": {
+                "content": ["Test content"],
+                "author": ["https://fireburn.ru/"],
+                "uid": ["https://fireburn.ru/posts/hello"],
+                "url": ["https://fireburn.ru/posts/hello", "https://fireburn.ru/posts/test"]
+            }
+        });
+        let key = post["properties"]["uid"][0].as_str().unwrap().to_string();
+
+        // Reading and writing
+        backend
+            .put_post(&post, "https://fireburn.ru/")
+            .await
+            .unwrap();
+
+        backend.update_post(&key, json!({
+            "url": &key,
+            "add": {
+                "category": ["testing"],
+            },
+            "replace": {
+                "content": ["Different test content"]
+            }
+        })).await.unwrap();
+
+        if let Some(returned_post) = backend.get_post(&key).await.unwrap() {
+            assert!(returned_post.is_object());
+            assert_eq!(
+                returned_post["type"].as_array().unwrap().len(),
+                post["type"].as_array().unwrap().len()
+            );
+            assert_eq!(
+                returned_post["type"].as_array().unwrap(),
+                post["type"].as_array().unwrap()
+            );
+            assert_eq!(
+                returned_post["properties"]["content"][0].as_str().unwrap(),
+                "Different test content"
+            );
+            assert_eq!(
+                returned_post["properties"]["category"].as_array().unwrap(),
+                &vec![json!("testing")]
+            );
+        } else {
+            panic!("For some reason the backend did not return the post.")
+        }
+    }
+
     async fn test_backend_get_channel_list<Backend: Storage>(backend: Backend) {
         let feed = json!({
             "type": ["h-feed"],
@@ -330,7 +382,9 @@ mod tests {
     redis_test!(test_backend_basic_operations);
     redis_test!(test_backend_get_channel_list);
     redis_test!(test_backend_settings);
+    redis_test!(test_backend_update);
     file_test!(test_backend_basic_operations);
     file_test!(test_backend_get_channel_list);
     file_test!(test_backend_settings);
+    file_test!(test_backend_update);
 }