aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-01-13 12:59:10 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-01-13 12:59:10 +0100
commita43422b4d4ed4d89e1ca8fc316dd372e5dd9cb34 (patch)
treee1eabfc74bb54b1c03d454411d8b16821df35db8 /src
parent316c62b8ddce3315cca0a9ecf35c551e8013160e (diff)
downloadrust-zotapi-a43422b4d4ed4d89e1ca8fc316dd372e5dd9cb34.tar.gz
rust-zotapi-a43422b4d4ed4d89e1ca8fc316dd372e5dd9cb34.tar.bz2
rust-zotapi-a43422b4d4ed4d89e1ca8fc316dd372e5dd9cb34.zip
Move streamitem tests to streamitem module.
Diffstat (limited to 'src')
-rw-r--r--src/stream.rs88
-rw-r--r--src/stream/streamitem.rs97
2 files changed, 97 insertions, 88 deletions
diff --git a/src/stream.rs b/src/stream.rs
index 8f543cc..438ef0f 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -54,92 +54,4 @@ mod test {
assert!(s.is_ok());
}
- #[test]
- fn construct_stream_from_json_with_one_activity() {
- let json = r#"[
- {
- "type": "activity",
- "encoding": "zot",
- "uuid": "2c102ec3-676b-4d84-b2b4-9141467a254f",
- "message_id": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
- "message_top": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
- "message_parent": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
- "created": "2023-12-12 17:00:42",
- "edited": "2023-12-12 17:00:42",
- "expires": "0000-00-00 00:00:00",
- "commented": "2023-12-19 09:01:15",
- "mimetype": "text/bbcode",
- "title": "The item title",
- "summary": "The summary of the post",
- "body": "The body of the post",
- "app": "",
- "verb": "http://activitystrea.ms/schema/1.0/post",
- "object_type": "http://activitystrea.ms/schema/1.0/note",
- "target_type": "",
- "permalink": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
- "location": "",
- "longlat": "",
- "signature": "sha256.ADzsjr5uFUpcwVkUT9liHimr1n2TJmGpTtm0SGSody_6vTbfYhHK3OJJhGknImHYwMradSwVcA9dNAAXzhSoAY5hCmSbnThLun30HVIA3E0ZSDBbt1RyKNomqBCvCBmyyFKhxYoPk34UQisCH6gIQ3eZL-m5PxE9t2oMO_CnpPvLWESoezY3CAZaEIIRj3KKozwC8DxibQmsnCeA32C-2Ejzv8PdZCX1skbIdc5d8Jj_ykyUTqc2DZKMSl9osua3esEMwYZLbxlRQruDfgyjJExdvz57zpeqf1WKzqdIZ5kmguZxch6NLVMiRitooT-sIZOvo9JzgP1ogBQW34W-kG1hHzuGJQkDZKOAA1rLD8qrfwugbbg9wDpjtZY-WHv265KMMsFhctIIupNPVVkuSgs0jMKQmjJTeDE0IxBKx2dCsxiqMWlJll_LSu7b6BtTa7jcuhfMPaKqdMOCRRnGNwehj6qeOXPV7zEZsc4Mzym6N_jRTV556OmUwaCHouEFqTG1ARE5EquYTMk2wXIteC5lT2d0WpEGTnlL1WpqWLx9DCp76Z2JsxMBxjZicKvJSm1gX3ng2ENG2cvECww0IF_zPy2DmHcWOqm795-11uLBNt_60bpP9-sgjrNSj0q6MHgAsFGnpW42M4sFe-6gb-W-HjyHwY2B2yjErYC9KDo",
- "route": "",
- "owner": {
- "name": "Benjamin Franklin",
- "address": "ben@example.com",
- "url": "https://example.com/channel/ben",
- "network": "zot6",
- "photo": {
- "mimetype": "image/jpeg",
- "src": "https://example.com/photo/profile/m/2"
- },
- "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
- "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
- "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
- },
- "author": {
- "name": "Benjamin Franklin",
- "address": "ben@example.com",
- "url": "https://example.com/channel/ben",
- "network": "zot6",
- "photo": {
- "mimetype": "image/jpeg",
- "src": "https://example.com/photo/profile/m/2"
- },
- "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
- "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
- "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
- },
- "flags": [
- "thread_parent"
- ],
- "public_scope": "",
- "comment_scope": "authenticated",
- "tags": [
- {
- "tag": "a-tag",
- "url": "https://example.com/search?tag=a-tag",
- "type": "hashtag"
- },
- {
- "tag": "fediverse",
- "url": "https://example.com/search?tag=fediverse",
- "type": "hashtag"
- },
- {
- "tag": "hubzilla",
- "url": "https://example.com/search?tag=hubzilla",
- "type": "hashtag"
- }
- ]
- }]"#;
- let s = Stream::from_json(&json).unwrap();
- assert_eq!(1, s.items.len());
-
- let item = &s.items[0];
-
- assert_eq!(StreamItemType::Activity, item.item_type);
- assert_eq!(StreamItemEncoding::Zot, item.encoding);
- assert_eq!(Verb::Post, item.verb);
- assert_eq!("The item title", &item.title);
- assert_eq!("The summary of the post", &item.summary);
- assert_eq!("The body of the post", &item.body);
- }
}
diff --git a/src/stream/streamitem.rs b/src/stream/streamitem.rs
index 343ed28..1934dfe 100644
--- a/src/stream/streamitem.rs
+++ b/src/stream/streamitem.rs
@@ -44,3 +44,100 @@ impl StreamItem {
self.verb == Verb::Post
}
}
+
+#[cfg(test)]
+mod test {
+
+ use super::*;
+
+ #[test]
+ fn parse_stream_item_from_json() {
+ let json = r#"
+ {
+ "type": "activity",
+ "encoding": "zot",
+ "uuid": "2c102ec3-676b-4d84-b2b4-9141467a254f",
+ "message_id": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
+ "message_top": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
+ "message_parent": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
+ "created": "2023-12-12 17:00:42",
+ "edited": "2023-12-12 17:00:42",
+ "expires": "0000-00-00 00:00:00",
+ "commented": "2023-12-19 09:01:15",
+ "mimetype": "text/bbcode",
+ "title": "The item title",
+ "summary": "The summary of the post",
+ "body": "The body of the post",
+ "app": "",
+ "verb": "http://activitystrea.ms/schema/1.0/post",
+ "object_type": "http://activitystrea.ms/schema/1.0/note",
+ "target_type": "",
+ "permalink": "https://example.com/item/2c102ec3-676b-4d84-b2b4-9141467a254f",
+ "location": "",
+ "longlat": "",
+ "signature": "sha256.ADzsjr5uFUpcwVkUT9liHimr1n2TJmGpTtm0SGSody_6vTbfYhHK3OJJhGknImHYwMradSwVcA9dNAAXzhSoAY5hCmSbnThLun30HVIA3E0ZSDBbt1RyKNomqBCvCBmyyFKhxYoPk34UQisCH6gIQ3eZL-m5PxE9t2oMO_CnpPvLWESoezY3CAZaEIIRj3KKozwC8DxibQmsnCeA32C-2Ejzv8PdZCX1skbIdc5d8Jj_ykyUTqc2DZKMSl9osua3esEMwYZLbxlRQruDfgyjJExdvz57zpeqf1WKzqdIZ5kmguZxch6NLVMiRitooT-sIZOvo9JzgP1ogBQW34W-kG1hHzuGJQkDZKOAA1rLD8qrfwugbbg9wDpjtZY-WHv265KMMsFhctIIupNPVVkuSgs0jMKQmjJTeDE0IxBKx2dCsxiqMWlJll_LSu7b6BtTa7jcuhfMPaKqdMOCRRnGNwehj6qeOXPV7zEZsc4Mzym6N_jRTV556OmUwaCHouEFqTG1ARE5EquYTMk2wXIteC5lT2d0WpEGTnlL1WpqWLx9DCp76Z2JsxMBxjZicKvJSm1gX3ng2ENG2cvECww0IF_zPy2DmHcWOqm795-11uLBNt_60bpP9-sgjrNSj0q6MHgAsFGnpW42M4sFe-6gb-W-HjyHwY2B2yjErYC9KDo",
+ "route": "",
+ "owner": {
+ "name": "Benjamin Franklin",
+ "address": "ben@example.com",
+ "url": "https://example.com/channel/ben",
+ "network": "zot6",
+ "photo": {
+ "mimetype": "image/jpeg",
+ "src": "https://example.com/photo/profile/m/2"
+ },
+ "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
+ "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
+ "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
+ },
+ "author": {
+ "name": "Benjamin Franklin",
+ "address": "ben@example.com",
+ "url": "https://example.com/channel/ben",
+ "network": "zot6",
+ "photo": {
+ "mimetype": "image/jpeg",
+ "src": "https://example.com/photo/profile/m/2"
+ },
+ "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
+ "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
+ "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
+ },
+ "flags": [
+ "thread_parent"
+ ],
+ "public_scope": "",
+ "comment_scope": "authenticated",
+ "tags": [
+ {
+ "tag": "a-tag",
+ "url": "https://example.com/search?tag=a-tag",
+ "type": "hashtag"
+ },
+ {
+ "tag": "fediverse",
+ "url": "https://example.com/search?tag=fediverse",
+ "type": "hashtag"
+ },
+ {
+ "tag": "hubzilla",
+ "url": "https://example.com/search?tag=hubzilla",
+ "type": "hashtag"
+ }
+ ]
+ }"#;
+
+ let item: StreamItem = serde_json::from_str(&json).unwrap();
+
+ assert_eq!(StreamItemType::Activity, item.item_type);
+ assert_eq!(StreamItemEncoding::Zot, item.encoding);
+ assert_eq!(Verb::Post, item.verb);
+ assert_eq!("The item title", &item.title);
+ assert_eq!("The summary of the post", &item.summary);
+ assert_eq!("The body of the post", &item.body);
+ assert_eq!("2023-12-12 17:00:42", &item.created.to_string());
+ assert_eq!("2023-12-12 17:00:42", &item.edited.to_string());
+ assert_eq!("0000-00-00 00:00:00", &item.expires.to_string());
+ assert_eq!("2023-12-19 09:01:15", &item.commented.to_string());
+ }
+}