about summary refs log tree commit diff
path: root/src/micropub
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-06 17:13:38 +0300
committerVika <vika@fireburn.ru>2021-05-06 17:13:38 +0300
commit0f767c40a0517e4c635e462c6084e4cb16e57478 (patch)
tree059a5ac92b65fa44151b9675cf3b4fb079e50a09 /src/micropub
parentaecb72d104dae2bcdeafdb01f0e33ad92ecf27d4 (diff)
Turns out assert!() can have a second argument with a panic reason. Cool!
Diffstat (limited to 'src/micropub')
-rw-r--r--src/micropub/post.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/micropub/post.rs b/src/micropub/post.rs
index 39a06ce..5b85ad4 100644
--- a/src/micropub/post.rs
+++ b/src/micropub/post.rs
@@ -509,15 +509,15 @@ mod tests {
         });
 
         let (uid, post) = normalize_mf2(mf2, &User::new("https://fireburn.ru/", "https://quill.p3k.io/", "create update media"));
-        assert!(post["properties"]["published"].as_array().unwrap().len() > 0);
-        DateTime::parse_from_rfc3339(post["properties"]["published"][0].as_str().unwrap()).unwrap();
-        assert!(post["properties"]["url"].as_array().unwrap().len() > 0);
-        assert!(post["properties"]["uid"].as_array().unwrap().len() > 0);
-        assert_eq!(post["properties"]["uid"][0].as_str().unwrap(), &uid);
-        assert!(uid.starts_with("https://fireburn.ru/posts/"));
-        assert_eq!(post["properties"]["content"][0]["html"].as_str().unwrap().trim(), "<p>This is content!</p>");
-        assert_eq!(post["properties"]["channel"][0], "https://fireburn.ru/feeds/main");
-        assert_eq!(post["properties"]["author"][0], "https://fireburn.ru/");
+        assert_eq!(post["properties"]["published"].as_array().expect("post['published'] is undefined").len(), 1, "Post doesn't have a published time");
+        DateTime::parse_from_rfc3339(post["properties"]["published"][0].as_str().unwrap()).expect("Couldn't parse date from rfc3339");
+        assert!(post["properties"]["url"].as_array().expect("post['url'] is undefined").len() > 0, "Post doesn't have any URLs");
+        assert_eq!(post["properties"]["uid"].as_array().expect("post['uid'] is undefined").len(), 1, "Post doesn't have a single UID");
+        assert_eq!(post["properties"]["uid"][0], uid, "UID of a post and its supposed location don't match");
+        assert!(uid.starts_with("https://fireburn.ru/posts/"), "The post namespace is incorrect");
+        assert_eq!(post["properties"]["content"][0]["html"].as_str().expect("Post doesn't have a rich content object").trim(), "<p>This is content!</p>", "Parsed Markdown content doesn't match expected HTML");
+        assert_eq!(post["properties"]["channel"][0], "https://fireburn.ru/feeds/main", "Post isn't posted to the main channel");
+        assert_eq!(post["properties"]["author"][0], "https://fireburn.ru/", "Post author is unknown");
     }
 
     #[test]
@@ -536,11 +536,9 @@ mod tests {
             .unwrap()
             .iter()
             .map(|i| i.as_str().unwrap())
-            .any(|i| i == "https://fireburn.ru/posts/hello-post")
-        );
-        if let Some(_) = post["properties"]["mp-slug"].as_array() {
-            panic!("mp-slug wasn't deleted from the array!")
-        }
+            .any(|i| i == "https://fireburn.ru/posts/hello-post"),
+            "Didn't found an URL pointing to the location expected by the mp-slug semantics");
+        assert!(post["properties"]["mp-slug"].as_array().is_none(), "mp-slug wasn't deleted from the array!")
     }
 
     #[test]
@@ -554,16 +552,15 @@ mod tests {
         });
 
         let (uid, post) = normalize_mf2(mf2, &User::new("https://fireburn.ru/", "https://quill.p3k.io/", "create update media"));
-        assert_eq!(post["properties"]["uid"][0].as_str().unwrap(), &uid);
+        assert_eq!(post["properties"]["uid"][0], uid, "UID of a post and its supposed location don't match");
         assert_eq!(post["properties"]["author"][0], "https://fireburn.ru/");
         assert!(post["properties"]["url"]
             .as_array()
             .unwrap()
             .iter()
             .map(|i| i.as_str().unwrap())
-            .any(|i| i == "https://fireburn.ru/feeds/main"));
-        if let Some(_) = post["properties"]["mp-slug"].as_array() {
-            panic!("mp-slug wasn't deleted from the array!")
-        }
+            .any(|i| i == "https://fireburn.ru/feeds/main"),
+        "Didn't found an URL pointing to the location expected by the mp-slug semantics");
+        assert!(post["properties"]["mp-slug"].as_array().is_none(), "mp-slug wasn't deleted from the array!")
     }
 }
\ No newline at end of file